aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-08-06 17:07:29 +0100
committerMatthew Lemon <lemon@matthewlemon.com>2020-08-06 17:07:29 +0100
commitf12db19eefd04a31b9ac40fdf78146795baa4001 (patch)
treef57633d8ac83278042c4ce899376f0566c4ab7ed
parent5e4acc68892172e9cf2fb0e9f6f1caef4a6eed13 (diff)
starting to refactor the tests
-rw-r--r--pkg/datamaps/writer_test.go40
1 files changed, 24 insertions, 16 deletions
diff --git a/pkg/datamaps/writer_test.go b/pkg/datamaps/writer_test.go
index e168f8d..bb86c9b 100644
--- a/pkg/datamaps/writer_test.go
+++ b/pkg/datamaps/writer_test.go
@@ -17,17 +17,12 @@ var (
filesInMaster = make(map[string]int)
)
-func TestWriteMaster(t *testing.T) {
-
+func testSetup() (*Options, error) {
// setup - we need the datamap in the test database
- db, err := setupDB("./testdata/test.db")
- defer func() {
- db.Close()
- os.Remove("./testdata/test.db")
- }()
+ _, err := setupDB("./testdata/test.db")
if err != nil {
- t.Fatal("Expected to be able to set up the database.")
+ fmt.Errorf("Expected to be able to set up the database.")
}
opts := Options{
@@ -39,20 +34,33 @@ func TestWriteMaster(t *testing.T) {
XLSXPath: "./testdata/",
}
- defer func() {
- os.Remove(filepath.Join(opts.MasterOutPutPath, "master.xlsx"))
- }()
-
if err := DatamapToDB(&opts); err != nil {
- t.Fatalf("Unable to write datamap to database file because %v.", err)
+ fmt.Errorf("Unable to write datamap to database file because %v.", err)
}
if err := ImportToDB(&opts); err != nil {
- t.Fatalf("cannot read test XLSX files needed before exporting to master - %v", err)
+ fmt.Errorf("cannot read test XLSX files needed before exporting to master - %v", err)
}
+ return &opts, nil
+}
- if err := CreateMaster(&opts); err != nil {
- t.Error(err)
+func TestWriteMaster(t *testing.T) {
+
+ opts, err := testSetup()
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ defer func() {
+ os.Remove(filepath.Join(opts.MasterOutPutPath, "master.xlsx"))
+ }()
+
+ defer func() {
+ os.Remove("./testdata/test.db")
+ }()
+
+ if err := CreateMaster(opts); err != nil {
+ t.Fatal(err)
}
var tests = []struct {