diff options
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/datamaps/config.go | 23 | ||||
-rw-r--r-- | pkg/datamaps/config_test.go | 17 |
2 files changed, 10 insertions, 30 deletions
diff --git a/pkg/datamaps/config.go b/pkg/datamaps/config.go index 6c82a9f..8dc8896 100644 --- a/pkg/datamaps/config.go +++ b/pkg/datamaps/config.go @@ -8,7 +8,7 @@ import ( ) const ( - configDirName = "datamaps-go" + configDirName = "datamaps" dbName = "datamaps.db" ) @@ -37,26 +37,7 @@ func (db *DBPathChecker) check() bool { if err != nil { log.Fatal(err) } - configPath := filepath.Join(userConfig, "datamaps") - dbPath := filepath.Join(configPath, "datamaps.db") - fmt.Fprintf(os.Stderr, "dbPath is definitely %s\n", dbPath) - if _, err := os.Stat(dbPath); os.IsNotExist(err) { - fmt.Fprintf(os.Stderr, "db does not exist\n") - return false - } - return true -} - -// DetectConfig looks for the configuration directory and -// files, and the database file needed to run the application. -func DetectDBFile() bool { - dir, err := os.UserConfigDir() - if err != nil { - log.Fatal(err) - } - // check if config folder exists - configPath := filepath.Join(dir, configDirName) - dbPath := filepath.Join(configPath, dbName) + dbPath := filepath.Join(userConfig, "datamaps.db") if _, err := os.Stat(dbPath); os.IsNotExist(err) { fmt.Fprintf(os.Stderr, "db does not exist\n") return false diff --git a/pkg/datamaps/config_test.go b/pkg/datamaps/config_test.go index 5f7becc..ad19879 100644 --- a/pkg/datamaps/config_test.go +++ b/pkg/datamaps/config_test.go @@ -1,7 +1,6 @@ package datamaps import ( - "log" "os" "path/filepath" "testing" @@ -10,25 +9,25 @@ import ( // mocking funcs in go https://stackoverflow.com/questions/19167970/mock-functions-in-go func mockConfigDir() (string, error) { - return "/tmp/CONFIG", nil + return "/tmp/CONFIG/datamaps/", nil } func TestDBDetect(t *testing.T) { - if err := os.Mkdir(filepath.Join("/tmp", "CONFIG"), 0700); err != nil { - t.Fatal("cannot create temporary directory") + 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) } - os.Create(filepath.Join("/tmp", "CONFIG", "datamaps.db")) + os.Create(filepath.Join("/tmp", "CONFIG", "datamaps", "datamaps.db")) defer func() { os.RemoveAll(filepath.Join("/tmp", "CONFIG")) }() dbpc := NewDBPathChecker(mockConfigDir) h := dbpc.check() - log.SetOutput(os.Stderr) - t.Logf("h is %v\n", h) - if h != true { - t.Error("Not there") + if !h { + t.Error("the db file should be found but isn't") } } |