From b7f03d01b8eed1c0dab111aa83ee9bfd1dd8fbeb Mon Sep 17 00:00:00 2001 From: Torben Giesselmann Date: Tue, 14 Mar 2023 19:16:24 -0700 Subject: [PATCH] Add helper function for Duration parsing Tests in cmd_forget_test.go need the same convenience function that was implemented in snapshot_policy_test.go. Function parseDuration(...) was moved to testing.go and renamed to ParseDurationOrPanic(...). --- internal/restic/testing.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/internal/restic/testing.go b/internal/restic/testing.go index ebafdf651..9c21b81d1 100644 --- a/internal/restic/testing.go +++ b/internal/restic/testing.go @@ -212,3 +212,14 @@ func TestParseHandle(s string, t BlobType) BlobHandle { func TestSetSnapshotID(t testing.TB, sn *Snapshot, id ID) { sn.id = &id } + +// Convenience function that parses a duration from a string or panics if string is invalid. +// The format is `6y5m234d37h`. +func ParseDurationOrPanic(s string) Duration { + d, err := ParseDuration(s) + if err != nil { + panic(err) + } + + return d +}