diff options
author | Matthew Lemon <matt@matthewlemon.com> | 2020-07-29 07:11:32 +0100 |
---|---|---|
committer | Matthew Lemon <matt@matthewlemon.com> | 2020-07-29 07:11:32 +0100 |
commit | 5a3668580f69c00e64bfd0f84e502a9102e44d15 (patch) | |
tree | aca17d5950b8dc53b48a1dee4442fcaebdb54a04 /pkg | |
parent | c13d416d9891803401b02ccead5c824dc82cb1d7 (diff) |
added setup and teardown funcs
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/datamaps/db_test.go | 50 |
1 files changed, 35 insertions, 15 deletions
diff --git a/pkg/datamaps/db_test.go b/pkg/datamaps/db_test.go index 93f3a39..ca4354a 100644 --- a/pkg/datamaps/db_test.go +++ b/pkg/datamaps/db_test.go @@ -1,20 +1,37 @@ package datamaps import ( + "database/sql" "os" "testing" ) -func TestOpenSQLiteFile(t *testing.T) { +var opts = Options{ + DBPath: "./testdata/test.db", + DMName: "First Datamap", + DMPath: "./testdata/short/datamap_matches_test_template.csv", +} + +func dbSetup() (*sql.DB, error) { db, err := setupDB("./testdata/test.db") - defer func() { - db.Close() - os.Remove("./testdata/test.db") - }() + if err != nil { + return nil, err + } + return db, nil +} + +func dbTeardown(db *sql.DB) { + db.Close() + os.Remove("./testdata/test.db") +} + +func TestOpenSQLiteFile(t *testing.T) { + db, err := dbSetup() if err != nil { - t.Fatalf("%v\ndatamaps-log: Expected to be able to set up the database.", err) + t.Fatal(err) } + defer dbTeardown(db) stmt := `insert into datamap(id, name) values(1,'cock')` _, err = db.Exec(stmt) @@ -41,6 +58,18 @@ func TestOpenSQLiteFile(t *testing.T) { } func TestDatamapGoesIntoDB(t *testing.T) { + db, err := dbSetup() + if err != nil { + t.Fatal(err) + } + defer dbTeardown(db) + + if err := DatamapToDB(&opts); err != nil { + t.Errorf("Unable to write datamap to database file because %v.", err) + } +} + +func TestImportSimpleTemplate(t *testing.T) { db, err := setupDB("./testdata/test.db") defer func() { db.Close() @@ -51,13 +80,4 @@ func TestDatamapGoesIntoDB(t *testing.T) { t.Fatal("Expected to be able to set up the database.") } - opts := Options{ - DBPath: "./testdata/test.db", - DMName: "First Datamap", - DMPath: "./testdata/datamap.csv", - } - - if err := DatamapToDB(&opts); err != nil { - t.Errorf("Unable to write datamap to database file because %v.", err) - } } |