fix(config): Removes config file name from abra dir

This commit is contained in:
2024-07-10 14:06:07 +02:00
committed by decentral1se
parent ce7dda1eae
commit c5724d56f8
2 changed files with 45 additions and 9 deletions

View File

@ -71,8 +71,7 @@ func TestLoadAbraConfigGetAbraDir(t *testing.T) {
}
cfg := LoadAbraConfig()
log.Println(cfg.GetAbraDir())
wantAbraDir := filepath.Join(wd, "testdata/abraconfig1/abra.yaml/foobar")
wantAbraDir := filepath.Join(wd, "testdata/abraconfig1/foobar")
if cfg.GetAbraDir() != wantAbraDir {
t.Errorf("\nwant: %s\ngot: %s", wantAbraDir, cfg.GetAbraDir())
}
@ -101,3 +100,34 @@ func TestLoadAbraConfigGetAbraDir(t *testing.T) {
}
})
}
func TestLoadAbraConfigServersDir(t *testing.T) {
wd, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
t.Setenv("ABRA_DIR", "")
t.Run("default", func(t *testing.T) {
cfg := LoadAbraConfig()
wantServersDir := os.ExpandEnv("$HOME/.abra/servers")
if cfg.GetServersDir() != wantServersDir {
t.Errorf("\nwant: %s\ngot: %s", wantServersDir, cfg.GetServersDir())
}
})
t.Run("from config file", func(t *testing.T) {
t.Cleanup(func() { os.Chdir(wd) })
err = os.Chdir(filepath.Join(wd, "testdata/abraconfig1"))
if err != nil {
log.Fatal(err)
}
cfg := LoadAbraConfig()
log.Println(cfg)
wantServersDir := filepath.Join(wd, "testdata/abraconfig1/foobar/servers")
if cfg.GetServersDir() != wantServersDir {
t.Errorf("\nwant: %s\ngot: %s", wantServersDir, cfg.GetServersDir())
}
})
}