fix(config): Removes config file name from abra dir
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
ce7dda1eae
commit
c5724d56f8
|
@ -34,7 +34,7 @@ func LoadAbraConfig() Abra {
|
|||
return Abra{}
|
||||
}
|
||||
log.Debugf("config file loaded from: %s", configFile)
|
||||
config.configPath = configFile
|
||||
config.configPath = filepath.Dir(configFile)
|
||||
return config
|
||||
}
|
||||
|
||||
|
@ -88,16 +88,22 @@ func (a Abra) GetAbraDir() string {
|
|||
return os.ExpandEnv("$HOME/.abra")
|
||||
}
|
||||
|
||||
func (a Abra) GetServersDir() string { return path.Join(a.GetAbraDir(), "servers") }
|
||||
func (a Abra) GetRecipesDir() string { return path.Join(a.GetAbraDir(), "recipes") }
|
||||
func (a Abra) GetVendorDir() string { return path.Join(a.GetAbraDir(), "vendor") }
|
||||
func (a Abra) GetBackupDir() string { return path.Join(a.GetAbraDir(), "backups") }
|
||||
func (a Abra) GetCatalogueDir() string { return path.Join(a.GetAbraDir(), "catalogue") }
|
||||
|
||||
var config = LoadAbraConfig()
|
||||
|
||||
var (
|
||||
ABRA_DIR = config.GetAbraDir()
|
||||
SERVERS_DIR = path.Join(ABRA_DIR, "servers")
|
||||
RECIPES_DIR = path.Join(ABRA_DIR, "recipes")
|
||||
VENDOR_DIR = path.Join(ABRA_DIR, "vendor")
|
||||
BACKUP_DIR = path.Join(ABRA_DIR, "backups")
|
||||
CATALOGUE_DIR = path.Join(ABRA_DIR, "catalogue")
|
||||
RECIPES_JSON = path.Join(ABRA_DIR, "catalogue", "recipes.json")
|
||||
SERVERS_DIR = config.GetServersDir()
|
||||
RECIPES_DIR = config.GetRecipesDir()
|
||||
VENDOR_DIR = config.GetVendorDir()
|
||||
BACKUP_DIR = config.GetBackupDir()
|
||||
CATALOGUE_DIR = config.GetCatalogueDir()
|
||||
RECIPES_JSON = path.Join(config.GetCatalogueDir(), "recipes.json")
|
||||
REPOS_BASE_URL = "https://git.coopcloud.tech/coop-cloud"
|
||||
CATALOGUE_JSON_REPO_NAME = "recipes-catalogue-json"
|
||||
SSH_URL_TEMPLATE = "ssh://git@git.coopcloud.tech:2222/coop-cloud/%s.git"
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue