MCPcopy
hub / github.com/spf13/pflag / TestDS

Function TestDS

duration_slice_test.go:43–75  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

41}
42
43func TestDS(t *testing.T) {
44 var ds []time.Duration
45 f := setUpDSFlagSet(&ds)
46
47 vals := []string{"1ns", "2ms", "3m", "4h"}
48 arg := fmt.Sprintf("--ds=%s", strings.Join(vals, ","))
49 err := f.Parse([]string{arg})
50 if err != nil {
51 t.Fatal("expected no error; got", err)
52 }
53 for i, v := range ds {
54 d, err := time.ParseDuration(vals[i])
55 if err != nil {
56 t.Fatalf("got error: %v", err)
57 }
58 if d != v {
59 t.Fatalf("expected ds[%d] to be %s but got: %d", i, vals[i], v)
60 }
61 }
62 getDS, err := f.GetDurationSlice("ds")
63 if err != nil {
64 t.Fatalf("got error: %v", err)
65 }
66 for i, v := range getDS {
67 d, err := time.ParseDuration(vals[i])
68 if err != nil {
69 t.Fatalf("got error: %v", err)
70 }
71 if d != v {
72 t.Fatalf("expected ds[%d] to be %s but got: %d from GetDurationSlice", i, vals[i], v)
73 }
74 }
75}
76
77func TestDSDefault(t *testing.T) {
78 var ds []time.Duration

Callers

nothing calls this directly

Calls 3

setUpDSFlagSetFunction · 0.85
GetDurationSliceMethod · 0.80
ParseMethod · 0.65

Tested by

no test coverage detected