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

Function TestDSWithDefault

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

Source from the content-addressed store, hash-verified

110}
111
112func TestDSWithDefault(t *testing.T) {
113 var ds []time.Duration
114 f := setUpDSFlagSetWithDefault(&ds)
115
116 vals := []string{"1ns", "2ns"}
117 arg := fmt.Sprintf("--ds=%s", strings.Join(vals, ","))
118 err := f.Parse([]string{arg})
119 if err != nil {
120 t.Fatal("expected no error; got", err)
121 }
122 for i, v := range ds {
123 d, err := time.ParseDuration(vals[i])
124 if err != nil {
125 t.Fatalf("got error: %v", err)
126 }
127 if d != v {
128 t.Fatalf("expected ds[%d] to be %d but got: %d", i, d, v)
129 }
130 }
131
132 getDS, err := f.GetDurationSlice("ds")
133 if err != nil {
134 t.Fatal("got an error from GetDurationSlice():", err)
135 }
136 for i, v := range getDS {
137 d, err := time.ParseDuration(vals[i])
138 if err != nil {
139 t.Fatalf("got error: %v", err)
140 }
141 if d != v {
142 t.Fatalf("expected ds[%d] to be %d from GetDurationSlice but got: %d", i, d, v)
143 }
144 }
145}
146
147func TestDSAsSliceValue(t *testing.T) {
148 var ds []time.Duration

Callers

nothing calls this directly

Calls 3

GetDurationSliceMethod · 0.80
ParseMethod · 0.65

Tested by

no test coverage detected