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

Function TestStringToSliceHookFunc

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

Source from the content-addressed store, hash-verified

205}
206
207func TestStringToSliceHookFunc(t *testing.T) {
208 f := StringToSliceHookFunc(",")
209
210 strValue := reflect.ValueOf("42")
211 sliceValue := reflect.ValueOf([]byte("42"))
212 cases := []struct {
213 f, t reflect.Value
214 result interface{}
215 err bool
216 }{
217 {sliceValue, sliceValue, []byte("42"), false},
218 {strValue, strValue, "42", false},
219 {
220 reflect.ValueOf("foo,bar,baz"),
221 sliceValue,
222 []string{"foo", "bar", "baz"},
223 false,
224 },
225 {
226 reflect.ValueOf(""),
227 sliceValue,
228 []string{},
229 false,
230 },
231 }
232
233 for i, tc := range cases {
234 actual, err := DecodeHookExec(f, tc.f, tc.t)
235 if tc.err != (err != nil) {
236 t.Fatalf("case %d: expected err %#v", i, tc.err)
237 }
238 if !reflect.DeepEqual(actual, tc.result) {
239 t.Fatalf(
240 "case %d: expected %#v, got %#v",
241 i, tc.result, actual)
242 }
243 }
244}
245
246func TestStringToTimeDurationHookFunc(t *testing.T) {
247 f := StringToTimeDurationHookFunc()

Callers

nothing calls this directly

Calls 2

StringToSliceHookFuncFunction · 0.85
DecodeHookExecFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…