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

Function TestIPSDefault

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

Source from the content-addressed store, hash-verified

61}
62
63func TestIPSDefault(t *testing.T) {
64 var ips []net.IP
65 f := setUpIPSFlagSetWithDefault(&ips)
66
67 vals := []string{"192.168.1.1", "0:0:0:0:0:0:0:1"}
68 err := f.Parse([]string{})
69 if err != nil {
70 t.Fatal("expected no error; got", err)
71 }
72 for i, v := range ips {
73 if ip := net.ParseIP(vals[i]); ip == nil {
74 t.Fatalf("invalid string being converted to IP address: %s", vals[i])
75 } else if !ip.Equal(v) {
76 t.Fatalf("expected ips[%d] to be %s but got: %s", i, vals[i], v)
77 }
78 }
79
80 getIPS, err := f.GetIPSlice("ips")
81 if err != nil {
82 t.Fatal("got an error from GetIPSlice")
83 }
84 for i, v := range getIPS {
85 if ip := net.ParseIP(vals[i]); ip == nil {
86 t.Fatalf("invalid string being converted to IP address: %s", vals[i])
87 } else if !ip.Equal(v) {
88 t.Fatalf("expected ips[%d] to be %s but got: %s", i, vals[i], v)
89 }
90 }
91}
92
93func TestIPSWithDefault(t *testing.T) {
94 var ips []net.IP

Callers

nothing calls this directly

Calls 3

GetIPSliceMethod · 0.80
ParseMethod · 0.65

Tested by

no test coverage detected