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

Function TestComposeDecodeHookFunc

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

Source from the content-addressed store, hash-verified

10)
11
12func TestComposeDecodeHookFunc(t *testing.T) {
13 f1 := func(
14 f reflect.Kind,
15 t reflect.Kind,
16 data interface{}) (interface{}, error) {
17 return data.(string) + "foo", nil
18 }
19
20 f2 := func(
21 f reflect.Kind,
22 t reflect.Kind,
23 data interface{}) (interface{}, error) {
24 return data.(string) + "bar", nil
25 }
26
27 f := ComposeDecodeHookFunc(f1, f2)
28
29 result, err := DecodeHookExec(
30 f, reflect.ValueOf(""), reflect.ValueOf([]byte("")))
31 if err != nil {
32 t.Fatalf("bad: %s", err)
33 }
34 if result.(string) != "foobar" {
35 t.Fatalf("bad: %#v", result)
36 }
37}
38
39func TestComposeDecodeHookFunc_err(t *testing.T) {
40 f1 := func(reflect.Kind, reflect.Kind, interface{}) (interface{}, error) {

Callers

nothing calls this directly

Calls 2

ComposeDecodeHookFuncFunction · 0.85
DecodeHookExecFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…