diff options
Diffstat (limited to 'datamaps/config_test.go')
-rw-r--r-- | datamaps/config_test.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/datamaps/config_test.go b/datamaps/config_test.go new file mode 100644 index 0000000..dadaf6d --- /dev/null +++ b/datamaps/config_test.go @@ -0,0 +1,35 @@ +package datamaps + +import ( + "os" + "path/filepath" + "testing" +) + +// mocking funcs in go https://stackoverflow.com/questions/19167970/mock-functions-in-go + +func mockConfigDir() (string, error) { + return "/tmp/CONFIG/datamaps/", nil +} + +func TestDBDetect(t *testing.T) { + + cPath := filepath.Join("/tmp", "CONFIG", "datamaps") + t.Logf("%s\n", cPath) + if err := os.MkdirAll(cPath, 0700); err != nil { + t.Fatalf("cannot create temporary directory - %v", err) + } + + if _, err := os.Create(filepath.Join("/tmp", "CONFIG", "datamaps", "datamaps.db")); err != nil { + t.Fatalf("cannot open '/tmp/CONFIG/datamaps/databamps.db': %v", err) + } + defer func() { + os.RemoveAll(filepath.Join("/tmp", "CONFIG")) + }() + + dbpc := NewDBPathChecker(mockConfigDir) + h := dbpc.Check() + if !h { + t.Error("the db file should be found but isn't") + } +} |