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

Function TestDecode_NilInterfaceHook

mapstructure_test.go:1067–1101  ·  mapstructure_test.go::TestDecode_NilInterfaceHook
(t *testing.T)

Source from the content-addressed store, hash-verified

1065}
1066
1067func TestDecode_NilInterfaceHook(t *testing.T) {
1068 t.Parallel()
1069
1070 input := map[string]interface{}{
1071 "w": "",
1072 }
1073
1074 decodeHook := func(f, t reflect.Type, v interface{}) (interface{}, error) {
1075 if t.String() == "io.Writer" {
1076 return nil, nil
1077 }
1078
1079 return v, nil
1080 }
1081
1082 var result NilInterface
1083 config := &DecoderConfig{
1084 DecodeHook: decodeHook,
1085 Result: &result,
1086 }
1087
1088 decoder, err := NewDecoder(config)
1089 if err != nil {
1090 t.Fatalf("err: %s", err)
1091 }
1092
1093 err = decoder.Decode(input)
1094 if err != nil {
1095 t.Fatalf("got an err: %s", err)
1096 }
1097
1098 if result.W != nil {
1099 t.Errorf("W should be nil: %#v", result.W)
1100 }
1101}
1102
1103func TestDecode_NilPointerHook(t *testing.T) {
1104 t.Parallel()

Callers

nothing calls this directly

Calls 2

DecodeMethod · 0.95
NewDecoderFunction · 0.85

Tested by

no test coverage detected