enbas/internal/flag/timedurationvalue_test.go

62 lines
1 KiB
Go
Raw Normal View History

package flag_test
import (
"slices"
"testing"
internalFlag "codeflow.dananglin.me.uk/apollo/enbas/internal/flag"
)
func TestTimeDurationValue(t *testing.T) {
parsingTests := []struct {
input string
want string
}{
{
input: "1 day",
want: "24h0m0s",
},
{
input: "3 days, 5 hours, 39 minutes and 6 seconds",
want: "77h39m6s",
},
{
input: "1 minute and 30 seconds",
want: "1m30s",
},
{
input: "(7 seconds) (21 hours) (41 days)",
want: "1005h0m7s",
},
}
value := internalFlag.NewTimeDurationValue()
for _, test := range slices.All(parsingTests) {
if err := value.Set(test.input); err != nil {
t.Fatalf(
"Unable to parse %s into a TimeDurationValue: %v",
test.input,
err,
)
}
got := value.String()
if got != test.want {
t.Errorf(
"Unexpected duration parsed from %s: want %s, got %s",
test.input,
test.want,
got,
)
} else {
t.Logf(
"Expected duration parsed from %s: got %s",
test.input,
got,
)
}
}
}