diff options
Diffstat (limited to 'pkg/datamaps')
-rw-r--r-- | pkg/datamaps/writer_test.go | 40 |
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 { |