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

Function TestIPSAsSliceValue

ip_slice_test.go:144–165  ·  ip_slice_test.go::TestIPSAsSliceValue
(t *testing.T)

Source from the content-addressed store, hash-verified

142}
143
144func TestIPSAsSliceValue(t *testing.T) {
145 var ips []net.IP
146 f := setUpIPSFlagSet(&ips)
147
148 in := []string{"192.168.1.1", "0:0:0:0:0:0:0:1"}
149 argfmt := "--ips=%s"
150 arg1 := fmt.Sprintf(argfmt, in[0])
151 arg2 := fmt.Sprintf(argfmt, in[1])
152 err := f.Parse([]string{arg1, arg2})
153 if err != nil {
154 t.Fatal("expected no error; got", err)
155 }
156
157 f.VisitAll(func(f *Flag) {
158 if val, ok := f.Value.(SliceValue); ok {
159 _ = val.Replace([]string{"192.168.1.2"})
160 }
161 })
162 if len(ips) != 1 || !ips[0].Equal(net.ParseIP("192.168.1.2")) {
163 t.Fatalf("Expected ss to be overwritten with '192.168.1.2', but got: %v", ips)
164 }
165}
166
167func TestIPSBadQuoting(t *testing.T) {
168

Callers

nothing calls this directly

Calls 4

setUpIPSFlagSetFunction · 0.85
VisitAllMethod · 0.80
ParseMethod · 0.65
ReplaceMethod · 0.65

Tested by

no test coverage detected