(t *testing.T)
| 1138 | } |
| 1139 | |
| 1140 | func TestDecode_FuncHook(t *testing.T) { |
| 1141 | t.Parallel() |
| 1142 | |
| 1143 | input := map[string]interface{}{ |
| 1144 | "foo": "baz", |
| 1145 | } |
| 1146 | |
| 1147 | decodeHook := func(f, t reflect.Type, v interface{}) (interface{}, error) { |
| 1148 | if t.Kind() != reflect.Func { |
| 1149 | return v, nil |
| 1150 | } |
| 1151 | val := v.(string) |
| 1152 | return func() string { return val }, nil |
| 1153 | } |
| 1154 | |
| 1155 | var result Func |
| 1156 | config := &DecoderConfig{ |
| 1157 | DecodeHook: decodeHook, |
| 1158 | Result: &result, |
| 1159 | } |
| 1160 | |
| 1161 | decoder, err := NewDecoder(config) |
| 1162 | if err != nil { |
| 1163 | t.Fatalf("err: %s", err) |
| 1164 | } |
| 1165 | |
| 1166 | err = decoder.Decode(input) |
| 1167 | if err != nil { |
| 1168 | t.Fatalf("got an err: %s", err) |
| 1169 | } |
| 1170 | |
| 1171 | if result.Foo() != "baz" { |
| 1172 | t.Errorf("Foo call result should be 'baz': %s", result.Foo()) |
| 1173 | } |
| 1174 | } |
| 1175 | |
| 1176 | func TestDecode_NonStruct(t *testing.T) { |
| 1177 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…