aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/datamaps/reader_test.go
diff options
context:
space:
mode:
authorMatthew Lemon <matt@matthewlemon.com>2020-07-26 19:46:26 +0100
committerMatthew Lemon <matt@matthewlemon.com>2020-07-26 19:46:26 +0100
commitfe186c2865c9a54cfb488f14fb6142257d712b94 (patch)
tree239f38a7edd9158e8dc87d9e64e69587d3336456 /pkg/datamaps/reader_test.go
parentc89f3b3e5680e06b93ed32c27e8b7632c66c3de9 (diff)
extraction now uses a named datamap from the database instead of the file
Diffstat (limited to 'pkg/datamaps/reader_test.go')
-rw-r--r--pkg/datamaps/reader_test.go45
1 files changed, 44 insertions, 1 deletions
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 {