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

Function LoadTestDataOnce

datasource/sqlite/sqlite_test.go:41–132  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

39 }
40}
41func LoadTestDataOnce(t *testing.T) {
42 loadData.Do(func() {
43 testutil.Setup()
44 // load our mock data sources "users", "orders"
45 td.LoadTestDataOnce()
46
47 os.Remove(testFile)
48
49 // It will be created if it doesn't exist.
50 db, err := sql.Open("sqlite3", testFile)
51 exitIfErr(err)
52 err = db.Ping()
53 exitIfErr(err)
54
55 reg := schema.DefaultRegistry()
56 by := []byte(`{
57 "name": "sqlite_test",
58 "type": "sqlite",
59 "settings" : {
60 "file" : "test.db"
61 }
62 }`)
63
64 conf := &schema.ConfigSource{}
65 err = json.Unmarshal(by, conf)
66 assert.Equal(t, nil, err)
67
68 // Create Sqlite db schema
69 for _, tablename := range td.MockSchema.Tables() {
70 tbl, _ := td.MockSchema.Table(tablename)
71 if tbl == nil {
72 panic("missing table " + tablename)
73 }
74 //u.Infof("found schema for %s \n%s", tablename, tbl.String())
75 // for _, col := range tbl.Fields {
76 // u.Debugf("%+v", col)
77 // }
78 u.Debugf("\n%s", sqlite.TableToString(tbl))
79 // Create table schema
80 res, err := db.Exec(sqlite.TableToString(tbl))
81 assert.Equal(t, nil, err)
82 assert.NotEqual(t, nil, res)
83 //u.Infof("err=%v res=%+v", err, res)
84 }
85 db.Close()
86
87 // From config, create schema
88 err = reg.SchemaAddFromConfig(conf)
89 assert.Equal(t, nil, err)
90
91 // Get the Schema we just created
92 s, ok := reg.Schema("sqlite_test")
93 assert.Equal(t, true, ok)
94 assert.NotEqual(t, nil, s)
95
96 // set global to schema for text context
97 sch = s
98

Callers 1

TestSuiteFunction · 0.70

Calls 15

SetupFunction · 0.92
DefaultRegistryFunction · 0.92
TableToStringFunction · 0.92
NewKeyFunction · 0.92
MakeIdFunction · 0.92
exitIfErrFunction · 0.85
SchemaAddFromConfigMethod · 0.80
OpenConnMethod · 0.80
ErrorfMethod · 0.80
DoMethod · 0.65
OpenMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected