aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/datamaps/db_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/datamaps/db_test.go')
-rw-r--r--pkg/datamaps/db_test.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/pkg/datamaps/db_test.go b/pkg/datamaps/db_test.go
new file mode 100644
index 0000000..e9d5100
--- /dev/null
+++ b/pkg/datamaps/db_test.go
@@ -0,0 +1,46 @@
+package datamaps
+
+import (
+ "testing"
+)
+
+func TestOpenSQLiteFile(t *testing.T) {
+ 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")
+ }
+ }
+}
+
+func TestDatamapGoesIntoDB(t *testing.T) {
+ d, err := ReadDML("./testdata/datamap.csv")
+ if err != nil {
+ t.Fatal(err)
+ }
+ opts := Options{
+ DBPath: "./testdata/test.db",
+ DMName: "First Datamap",
+ DMData: d,
+ }
+ err = DatamapToDB(opts)
+ if err != nil {
+ t.Errorf("Unable to write datamap to database file because %v.", err)
+ }
+}