aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <matt@matthewlemon.com>2020-07-29 09:18:16 +0100
committerMatthew Lemon <matt@matthewlemon.com>2020-07-29 09:18:16 +0100
commit0e04de97d5cdb72e16f5cc4afe49dfedf36a25bb (patch)
treefe622e712c4a3de58036dbbb926aba12e666117c
parent69a7dc8f06566d96d5241df62465a180b85f5e35 (diff)
more tests
-rw-r--r--pkg/datamaps/db_test.go71
-rw-r--r--pkg/datamaps/testdata/short/datamap_matches_test_template.csv4
-rw-r--r--pkg/datamaps/testdata/test_template.xlsmbin9193 -> 9394 bytes
3 files changed, 58 insertions, 17 deletions
diff --git a/pkg/datamaps/db_test.go b/pkg/datamaps/db_test.go
index b60cb82..88fa640 100644
--- a/pkg/datamaps/db_test.go
+++ b/pkg/datamaps/db_test.go
@@ -2,6 +2,7 @@ package datamaps
import (
"database/sql"
+ "fmt"
"os"
"os/exec"
"strings"
@@ -75,12 +76,20 @@ func TestDatamapGoesIntoDB(t *testing.T) {
func TestImportSimpleTemplate(t *testing.T) {
- 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);`
+ 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 {
@@ -92,18 +101,46 @@ func TestImportSimpleTemplate(t *testing.T) {
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.Fatalf("Something wrong: %v", 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)
+
+ 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
+
+// Returns useful error messages when querying for stuff not in datamap
+// func TestImportSimpleQueryValueNotInDatamap(t *testing.T) {
+// var tests = []struct {
+// sheet string
+// cellref string
+// value string
+// }{
+// {"Summary", "B2", "20/10/19"}, // this is not referenced in datamap
+// }
+// }
+
+// TODO:
+// When a date is returned from the spreadsheet it is an integer and needs
+// to be handled appropriately.
+// func TestValuesReturnedAsDates(t *testing.T) {
+// }
diff --git a/pkg/datamaps/testdata/short/datamap_matches_test_template.csv b/pkg/datamaps/testdata/short/datamap_matches_test_template.csv
index f9e94e9..9ff8c8c 100644
--- a/pkg/datamaps/testdata/short/datamap_matches_test_template.csv
+++ b/pkg/datamaps/testdata/short/datamap_matches_test_template.csv
@@ -4,3 +4,7 @@ A Test,Introduction,C9
A Vunt,Introduction,C22
Floaty,Another Sheet,D5
A Parrot,Introduction,J9
+A String,Summary,B3
+A Float,Summary,B4
+A Number,Another Sheet,N34
+A Rabbit,Another Sheet,DI15
diff --git a/pkg/datamaps/testdata/test_template.xlsm b/pkg/datamaps/testdata/test_template.xlsm
index 77ac56f..737eeb4 100644
--- a/pkg/datamaps/testdata/test_template.xlsm
+++ b/pkg/datamaps/testdata/test_template.xlsm
Binary files differ