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

Function TestDSDefault

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

Source from the content-addressed store, hash-verified

75}
76
77func TestDSDefault(t *testing.T) {
78 var ds []time.Duration
79 f := setUpDSFlagSetWithDefault(&ds)
80
81 vals := []string{"0s", "1ns"}
82
83 err := f.Parse([]string{})
84 if err != nil {
85 t.Fatal("expected no error; got", err)
86 }
87 for i, v := range ds {
88 d, err := time.ParseDuration(vals[i])
89 if err != nil {
90 t.Fatalf("got error: %v", err)
91 }
92 if d != v {
93 t.Fatalf("expected ds[%d] to be %d but got: %d", i, d, v)
94 }
95 }
96
97 getDS, err := f.GetDurationSlice("ds")
98 if err != nil {
99 t.Fatal("got an error from GetDurationSlice():", err)
100 }
101 for i, v := range getDS {
102 d, err := time.ParseDuration(vals[i])
103 if err != nil {
104 t.Fatal("got an error from GetDurationSlice():", err)
105 }
106 if d != v {
107 t.Fatalf("expected ds[%d] to be %d from GetDurationSlice but got: %d", i, d, v)
108 }
109 }
110}
111
112func TestDSWithDefault(t *testing.T) {
113 var ds []time.Duration

Callers

nothing calls this directly

Calls 3

GetDurationSliceMethod · 0.80
ParseMethod · 0.65

Tested by

no test coverage detected