From fe186c2865c9a54cfb488f14fb6142257d712b94 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Sun, 26 Jul 2020 19:46:26 +0100 Subject: extraction now uses a named datamap from the database instead of the file --- pkg/datamaps/reader_test.go | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'pkg/datamaps/reader_test.go') diff --git a/pkg/datamaps/reader_test.go b/pkg/datamaps/reader_test.go index ec158a1..de169dd 100644 --- a/pkg/datamaps/reader_test.go +++ b/pkg/datamaps/reader_test.go @@ -125,7 +125,7 @@ func TestDMLSliceFromDatabase(t *testing.T) { {7, "Parrots Name"}, } - data := DMLFromDB("First Datamap", db) + data, _ := DMLFromDB("First Datamap", db) for _, c := range cases { got := data[c.index].Key @@ -139,6 +139,49 @@ func TestDMLSliceFromDatabase(t *testing.T) { } } +func TestExtractUsingDBDM(t *testing.T) { + // setup - we need the datamap in the test database + db, err := SetupDB("./testdata/test.db") + defer db.Close() + + if err != nil { + 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) + } + + d := ExtractDBDM("First Datamap", "testdata/test_template.xlsx", db) + cases := []struct { + sheet, cellref, val string + }{ + {"Introduction", "C9", "Test Department"}, + {"Introduction", "J9", "Greedy Parrots"}, + {"Introduction", "A1", "10"}, + {"Introduction", "C22", "VUNT"}, + } + + for _, c := range cases { + got := d[c.sheet][c.cellref].Value + if got != c.val { + t.Errorf("The test expected %s in %s sheet to be %s "+ + "- instead it is %s.", c.sheet, c.cellref, c.val, + d[c.sheet][c.cellref].Value) + } + } + + if d["Another Sheet"]["E26"].Value != "Integer:" { + t.Errorf("Expected E26 in Another Sheet sheet to be Integer: - instead it is %s", d["Another Sheet"]["E26"].Value) + } +} + func TestExtract(t *testing.T) { d := Extract("testdata/datamap.csv", "testdata/test_template.xlsx") cases := []struct { -- cgit v1.2.3