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

Function TestStringToIPNetHookFunc

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

Source from the content-addressed store, hash-verified

329}
330
331func TestStringToIPNetHookFunc(t *testing.T) {
332 strValue := reflect.ValueOf("5")
333 ipNetValue := reflect.ValueOf(net.IPNet{})
334 var nilNet *net.IPNet = nil
335
336 cases := []struct {
337 f, t reflect.Value
338 result interface{}
339 err bool
340 }{
341 {reflect.ValueOf("1.2.3.4/24"), ipNetValue,
342 &net.IPNet{
343 IP: net.IP{0x01, 0x02, 0x03, 0x00},
344 Mask: net.IPv4Mask(0xff, 0xff, 0xff, 0x00),
345 }, false},
346 {strValue, ipNetValue, nilNet, true},
347 {strValue, strValue, "5", false},
348 }
349
350 for i, tc := range cases {
351 f := StringToIPNetHookFunc()
352 actual, err := DecodeHookExec(f, tc.f, tc.t)
353 if tc.err != (err != nil) {
354 t.Fatalf("case %d: expected err %#v", i, tc.err)
355 }
356 if !reflect.DeepEqual(actual, tc.result) {
357 t.Fatalf(
358 "case %d: expected %#v, got %#v",
359 i, tc.result, actual)
360 }
361 }
362}
363
364func TestWeaklyTypedHook(t *testing.T) {
365 var f DecodeHookFunc = WeaklyTypedHook

Callers

nothing calls this directly

Calls 2

StringToIPNetHookFuncFunction · 0.85
DecodeHookExecFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…