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

Function TestOrComposeDecodeHookFunc

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

Source from the content-addressed store, hash-verified

85}
86
87func TestOrComposeDecodeHookFunc(t *testing.T) {
88 f1 := func(
89 f reflect.Kind,
90 t reflect.Kind,
91 data interface{}) (interface{}, error) {
92 return data.(string) + "foo", nil
93 }
94
95 f2 := func(
96 f reflect.Kind,
97 t reflect.Kind,
98 data interface{}) (interface{}, error) {
99 return data.(string) + "bar", nil
100 }
101
102 f := OrComposeDecodeHookFunc(f1, f2)
103
104 result, err := DecodeHookExec(
105 f, reflect.ValueOf(""), reflect.ValueOf([]byte("")))
106 if err != nil {
107 t.Fatalf("bad: %s", err)
108 }
109 if result.(string) != "foo" {
110 t.Fatalf("bad: %#v", result)
111 }
112}
113
114func TestOrComposeDecodeHookFunc_correctValueIsLast(t *testing.T) {
115 f1 := func(

Callers

nothing calls this directly

Calls 2

OrComposeDecodeHookFuncFunction · 0.85
DecodeHookExecFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…