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

Function TestIPNetWithDefault

ipnet_slice_test.go:105–134  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

103}
104
105func TestIPNetWithDefault(t *testing.T) {
106 var cidrs []net.IPNet
107 f := setUpIPNetFlagSetWithDefault(&cidrs)
108
109 vals := []string{"192.168.1.1/16", "fd00::/64"}
110 arg := fmt.Sprintf("--cidrs=%s", strings.Join(vals, ","))
111 err := f.Parse([]string{arg})
112 if err != nil {
113 t.Fatal("expected no error; got", err)
114 }
115 for i, v := range cidrs {
116 if _, cidr, _ := net.ParseCIDR(vals[i]); cidr == nil {
117 t.Fatalf("invalid string being converted to CIDR: %s", vals[i])
118 } else if !equalCIDR(*cidr, v) {
119 t.Fatalf("expected cidrs[%d] to be %s but got: %s", i, vals[i], v)
120 }
121 }
122
123 getIPNet, err := f.GetIPNetSlice("cidrs")
124 if err != nil {
125 t.Fatal("got an error from GetIPNetSlice")
126 }
127 for i, v := range getIPNet {
128 if _, cidr, _ := net.ParseCIDR(vals[i]); cidr == nil {
129 t.Fatalf("invalid string being converted to CIDR: %s", vals[i])
130 } else if !equalCIDR(*cidr, v) {
131 t.Fatalf("expected cidrs[%d] to be %s but got: %s", i, vals[i], v)
132 }
133 }
134}
135
136func TestIPNetCalledTwice(t *testing.T) {
137 var cidrs []net.IPNet

Callers

nothing calls this directly

Calls 4

equalCIDRFunction · 0.85
GetIPNetSliceMethod · 0.80
ParseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…