diff options
author | Matthew Lemon <matt@matthewlemon.com> | 2020-07-29 08:24:13 +0100 |
---|---|---|
committer | Matthew Lemon <matt@matthewlemon.com> | 2020-07-29 08:24:13 +0100 |
commit | 69a7dc8f06566d96d5241df62465a180b85f5e35 (patch) | |
tree | e5582eea824499b837d1bba73d00db4d435704ed | |
parent | 5a3668580f69c00e64bfd0f84e502a9102e44d15 (diff) |
first new test on database import - testing one cell value
-rw-r--r-- | pkg/datamaps/db_test.go | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/pkg/datamaps/db_test.go b/pkg/datamaps/db_test.go index ca4354a..b60cb82 100644 --- a/pkg/datamaps/db_test.go +++ b/pkg/datamaps/db_test.go @@ -3,9 +3,13 @@ package datamaps import ( "database/sql" "os" + "os/exec" + "strings" "testing" ) +var singleTarget string = "./testdata/test_template.xlsm" + var opts = Options{ DBPath: "./testdata/test.db", DMName: "First Datamap", @@ -65,19 +69,41 @@ func TestDatamapGoesIntoDB(t *testing.T) { defer dbTeardown(db) if err := DatamapToDB(&opts); err != nil { - t.Errorf("Unable to write datamap to database file because %v.", err) + 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() - os.Remove("./testdata/test.db") - }() + const sql = ` + SELECT return_data.value + FROM return_data, datamap_line + WHERE (return_data.filename='test_template.xlsm' AND + datamap_line.cellref="C9" AND + return_data.dml_id=datamap_line.id);` + + db, err := dbSetup() if err != nil { - t.Fatal("Expected to be able to set up the database.") + t.Fatal(err) } + defer dbTeardown(db) + // We need a datamap in there. + if err := DatamapToDB(&opts); err != nil { + t.Fatalf("cannot open %s", opts.DMPath) + } + + if err := importXLSXtoDB(opts.DMName, "TEST RETURN", singleTarget, db); err != nil { + t.Fatal(err) + } + got, err := exec.Command("sqlite3", opts.DBPath, sql).Output() + if err != nil { + t.Fatal(err) + } + t.Logf("%q", string(got)) + got_s := string(got) + got_s = strings.TrimSuffix(got_s, "\n") + if strings.Compare(got_s, "Test Department") != 0 { + t.Errorf("we wanted 'Test Department' but got %s", got_s) + } } |