aboutsummaryrefslogtreecommitdiffstats
path: root/db/setup_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'db/setup_test.go')
-rw-r--r--db/setup_test.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/db/setup_test.go b/db/setup_test.go
new file mode 100644
index 0000000..e256f9c
--- /dev/null
+++ b/db/setup_test.go
@@ -0,0 +1,29 @@
+package db
+
+import "testing"
+
+func TestOpenSQLiteFile(t *testing.T) {
+ // db, err := sql.Open("sqlite3", "testdata/test.db")
+ db, err := SetupDB("./testdata/test.db")
+ defer db.Close()
+ if err != nil {
+ t.Fatal("Expected to be able to set up the database.")
+ }
+ stmt := `insert into datamap(id, name) values(1,'cock')`
+ _, err = db.Exec(stmt)
+ if err != nil {
+ t.Errorf("Cannot add record to db")
+ }
+ rows, err := db.Query("select name from datamap")
+ if err != nil {
+ t.Errorf("Cannot run select statement")
+ }
+ defer rows.Close()
+ for rows.Next() {
+ var name string
+ err = rows.Scan(&name)
+ if err != nil {
+ t.Errorf("Cannot scan resulting row")
+ }
+ }
+}