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

Function TestIPSWithDefault

ip_slice_test.go:93–122  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

91}
92
93func TestIPSWithDefault(t *testing.T) {
94 var ips []net.IP
95 f := setUpIPSFlagSetWithDefault(&ips)
96
97 vals := []string{"192.168.1.1", "0:0:0:0:0:0:0:1"}
98 arg := fmt.Sprintf("--ips=%s", strings.Join(vals, ","))
99 err := f.Parse([]string{arg})
100 if err != nil {
101 t.Fatal("expected no error; got", err)
102 }
103 for i, v := range ips {
104 if ip := net.ParseIP(vals[i]); ip == nil {
105 t.Fatalf("invalid string being converted to IP address: %s", vals[i])
106 } else if !ip.Equal(v) {
107 t.Fatalf("expected ips[%d] to be %s but got: %s", i, vals[i], v)
108 }
109 }
110
111 getIPS, err := f.GetIPSlice("ips")
112 if err != nil {
113 t.Fatal("got an error from GetIPSlice")
114 }
115 for i, v := range getIPS {
116 if ip := net.ParseIP(vals[i]); ip == nil {
117 t.Fatalf("invalid string being converted to IP address: %s", vals[i])
118 } else if !ip.Equal(v) {
119 t.Fatalf("expected ips[%d] to be %s but got: %s", i, vals[i], v)
120 }
121 }
122}
123
124func TestIPSCalledTwice(t *testing.T) {
125 var ips []net.IP

Callers

nothing calls this directly

Calls 3

GetIPSliceMethod · 0.80
ParseMethod · 0.65

Tested by

no test coverage detected