diff options
author | Matthew Lemon <matt@matthewlemon.com> | 2020-07-29 15:42:25 +0100 |
---|---|---|
committer | Matthew Lemon <matt@matthewlemon.com> | 2020-07-29 15:42:25 +0100 |
commit | 6bdf08d2524da6f87bbc2f5128d308d058474d36 (patch) | |
tree | 3d91c1b020558f8cec06e19192c85b479f7f4f7d | |
parent | 7a47e9fec3ad12ce95f17f275531cbdf69f2ebab (diff) |
test for ImportToDB
-rw-r--r-- | pkg/datamaps/db_test.go | 57 |
1 files changed, 54 insertions, 3 deletions
diff --git a/pkg/datamaps/db_test.go b/pkg/datamaps/db_test.go index ecf0f6c..528ae28 100644 --- a/pkg/datamaps/db_test.go +++ b/pkg/datamaps/db_test.go @@ -12,9 +12,10 @@ import ( var singleTarget string = "./testdata/test_template.xlsm" var opts = Options{ - DBPath: "./testdata/test.db", - DMName: "First Datamap", - DMPath: "./testdata/datamap_matches_test_template.csv", + DBPath: "./testdata/test.db", + DMName: "First Datamap", + DMPath: "./testdata/datamap_matches_test_template.csv", + XLSXPath: "./testdata/", } func dbSetup() (*sql.DB, error) { @@ -124,6 +125,56 @@ func TestImportSimpleTemplate(t *testing.T) { } } +func TestImportToDB(t *testing.T) { + var tests = []struct { + sheet string + cellref string + value string + }{ + {"Introduction", "A1", "10"}, + {"Introduction", "C9", "Test Department"}, + {"Introduction", "C22", "VUNT"}, + {"Introduction", "J9", "Greedy Parrots"}, + {"Summary", "B3", "This is a string"}, + {"Summary", "B4", "2.2"}, + {"Another Sheet", "N34", "23"}, + {"Another Sheet", "DI15", "Rabbit Helga"}, + } + + db, err := dbSetup() + if err != nil { + t.Fatal(err) + } + + // We need a datamap in there. + if err := DatamapToDB(&opts); err != nil { + t.Fatalf("cannot open %s", opts.DMPath) + } + defer dbTeardown(db) + + if err := ImportToDB(&opts); err != nil { + t.Fatal(err) + } + + for _, test := range tests { + sql := fmt.Sprintf(`SELECT return_data.value FROM return_data, datamap_line + WHERE + (return_data.filename='test_template.xlsm' + AND datamap_line.cellref=%q + AND datamap_line.sheet=%q + AND return_data.dml_id=datamap_line.id);`, test.cellref, test.sheet) + + got, err := exec.Command("sqlite3", opts.DBPath, sql).Output() + if err != nil { + t.Fatalf("something wrong %v", err) + } + got_s := strings.TrimSuffix(string(got), "\n") + if strings.Compare(got_s, test.value) != 0 { + t.Errorf("we wanted %s but got %s", test.value, got_s) + } + } +} + // TODO: // USING THE INDEX TO tests STRUCT WE COULD DO ALL THESE IN TEST ABOVE |