MCPcopy Create free account
hub / github.com/araddon/qlbridge / TestStructWrapper

Function TestStructWrapper

datasource/context_wrapper_test.go:38–82  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

36}
37
38func TestStructWrapper(t *testing.T) {
39
40 t1, _ := dateparse.ParseAny("12/18/2015")
41 tr := true
42 user := &User{
43 Name: "Yoda",
44 Created: t1,
45 Updated: &t1,
46 Authenticated: true,
47 HasSession: &tr,
48 Roles: []string{"admin", "api"},
49 BankAmount: 55.5,
50 }
51 user.Address.City = "Phoenix"
52 user.Address.Zip = 97811
53
54 readers := []expr.ContextReader{
55 datasource.NewContextWrapper(user),
56 datasource.NewContextSimpleNative(map[string]interface{}{
57 "str1": "str1",
58 "int1": 1,
59 "t1": t1,
60 "Name": "notyoda",
61 }),
62 }
63
64 nc := datasource.NewNestedContextReader(readers, time.Now())
65 expected := value.NewMapValue(map[string]interface{}{
66 "str1": "str1",
67 "int1": 1,
68 "Name": "Yoda",
69 "Authenticated": true,
70 "bankamount": 55.5,
71 "FullName": "Yoda, Jedi",
72 "Address.City": "Phoenix",
73 "Roles": []string{"admin", "api"},
74 "roles_list": []string{"admin", "api"},
75 "Nope": nil,
76 })
77
78 for k, v := range expected.Val() {
79 //u.Infof("k:%v v:%#v", k, v)
80 checkval(t, nc, k, v)
81 }
82}

Callers

nothing calls this directly

Calls 6

ValMethod · 0.95
NewContextWrapperFunction · 0.92
NewContextSimpleNativeFunction · 0.92
NewNestedContextReaderFunction · 0.92
NewMapValueFunction · 0.92
checkvalFunction · 0.85

Tested by

no test coverage detected