MCPcopy
hub / github.com/mitchellh/mapstructure / TestStringToIPHookFunc

Function TestStringToIPHookFunc

decode_hooks_test.go:303–329  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

301}
302
303func TestStringToIPHookFunc(t *testing.T) {
304 strValue := reflect.ValueOf("5")
305 ipValue := reflect.ValueOf(net.IP{})
306 cases := []struct {
307 f, t reflect.Value
308 result interface{}
309 err bool
310 }{
311 {reflect.ValueOf("1.2.3.4"), ipValue,
312 net.IPv4(0x01, 0x02, 0x03, 0x04), false},
313 {strValue, ipValue, net.IP{}, true},
314 {strValue, strValue, "5", false},
315 }
316
317 for i, tc := range cases {
318 f := StringToIPHookFunc()
319 actual, err := DecodeHookExec(f, tc.f, tc.t)
320 if tc.err != (err != nil) {
321 t.Fatalf("case %d: expected err %#v", i, tc.err)
322 }
323 if !reflect.DeepEqual(actual, tc.result) {
324 t.Fatalf(
325 "case %d: expected %#v, got %#v",
326 i, tc.result, actual)
327 }
328 }
329}
330
331func TestStringToIPNetHookFunc(t *testing.T) {
332 strValue := reflect.ValueOf("5")

Callers

nothing calls this directly

Calls 2

StringToIPHookFuncFunction · 0.85
DecodeHookExecFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…