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

Function TestDataTypes

datasource/datatypes_test.go:37–84  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

35}
36
37func TestDataTypes(t *testing.T) {
38
39 // Load in a "csv file" into our mock data store
40 mockcsv.LoadTable(td.MockSchema.Name, "typestest", `user_id,categories,json_obj,json_cats,t1
419Ip1aKbeZe2njCDM,"sports,politics,worldnews","{""name"":""bob""}","[""sports"",""politics"",""worldnews""]","2014-01-01"`)
42
43 data := dtData{}
44 tu.ExecSqlSpec(t, &tu.QuerySpec{
45 Source: td.MockSchema.Name,
46 Sql: `SELECT
47 user_id, categories, categories AS cat, json_cats, t1, json_obj as j1, json_obj as j2
48 FROM typestest;`,
49 ExpectRowCt: 1,
50 ValidateRowData: func() {
51 u.Infof("%#v", data)
52 assert.Equal(t, catstr, data.Categories)
53 assert.Equal(t, cats, []string(data.Cat))
54 assert.Equal(t, cats, []string(data.JsonCat))
55 assert.Equal(t, t1, data.T1.Time())
56 assert.Equal(t, jo, json.RawMessage(*data.Json1))
57 j2, _ := json.Marshal(data.Json2)
58 assert.Equal(t, string(jo), string(j2))
59 },
60 RowData: &data,
61 })
62 by, err := json.Marshal(data)
63 assert.Equal(t, nil, err)
64 var data2 dtData
65 err = json.Unmarshal(by, &data2)
66 u.Infof("by %s", string(by))
67 assert.Equal(t, nil, err)
68 assert.Equal(t, catstr, data2.Categories)
69 assert.Equal(t, cats, []string(data2.Cat))
70 assert.Equal(t, cats, []string(data2.JsonCat))
71 assert.Equal(t, t1, data2.T1.Time())
72 assert.Equal(t, jo, json.RawMessage(*data2.Json1))
73 j2, _ := json.Marshal(data2.Json2)
74 assert.Equal(t, string(jo), string(j2))
75
76 tu.ExecSqlSpec(t, &tu.QuerySpec{
77 Source: td.MockSchema.Name,
78 Exec: "DROP TABLE typestest;",
79 ExpectRowCt: -1,
80 })
81 tu.TestSelect(t, `show tables;`,
82 [][]driver.Value{{"orders"}, {"users"}},
83 )
84}

Callers

nothing calls this directly

Calls 5

LoadTableFunction · 0.92
EqualMethod · 0.65
TimeMethod · 0.45
MarshalMethod · 0.45
UnmarshalMethod · 0.45

Tested by

no test coverage detected