blob: dadaf6d713b87b938a25f94aaa8097b0e7004183 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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")
}
}
|