Unit test query of SQLite master table
@@ -49,6 +49,25 @@ func Test_TableCreation(t *testing.T) {
}
}
+func Test_SQLiteMaster(t *testing.T) {
+ db, path := mustCreateDatabase()
+ defer db.Close()
+ defer os.Remove(path)
+
+ _, err := db.Execute([]string{"CREATE TABLE foo (id INTEGER NOT NULL PRIMARY KEY, name TEXT)"}, false, false)
+ if err != nil {
+ t.Fatalf("failed to create table: %s", err.Error())
+ }
+
+ r, err := db.Query([]string{"SELECT * FROM sqlite_master"}, false, false)
+ if err != nil {
+ t.Fatalf("failed to query master table: %s", err.Error())
+ }
+ if exp, got := `[{"columns":["type","name","tbl_name","rootpage","sql"],"types":["text","text","text","integer","text"],"values":[["table","foo","foo",2,"CREATE TABLE foo (id INTEGER NOT NULL PRIMARY KEY, name TEXT)"]]}]`, asJSON(r); exp != got {
+ t.Fatalf("unexpected results for query, expected %s, got %s", exp, got)
+ }
+}
+
func Test_LoadInMemory(t *testing.T) {
db, path := mustCreateDatabase()
defer db.Close()
