Config: fix don't create empty dir when resolving path (#575)

* Config: fix don't create empty dir when resolving path

* refactor migration of default config file

* gracefully handle src == target on Move
* create target directory on Move, if necessary

* unify resolution of default config location

* refactor the use of flagSet to be explicit
* remove package variable
* use empty config file path setting if not set in flags
* resolve default file location the same way when showing the target and
when loading default config file

* don't migrate if target file is the same as source

* rename configfile to configFile

* add migrateConfig tests
This commit is contained in:
Rauno Ots
2020-10-15 04:24:43 +02:00
committed by GitHub
parent f11c904743
commit 8c86aac21d
10 changed files with 253 additions and 129 deletions

View File

@@ -51,12 +51,12 @@ func TestLoadConfigWithSettings(t *testing.T) {
tt := tt
t.Run(tt.name, func(t *testing.T) {
// prepare the 'flags'
flagSet = make(map[string]bool)
flagSet := make(map[string]bool)
for _, v := range tt.flags {
flagSet[v] = true
}
// Run the test
got, err := loadConfigWithSettings(tt.settings)
got, err := loadConfigWithSettings(tt.settings, flagSet)
if (err != nil) != tt.wantErr {
t.Errorf("loadConfigWithSettings() error = %v, wantErr %v", err, tt.wantErr)
return
@@ -77,7 +77,7 @@ func TestStartStopDoesNotCausePanic(t *testing.T) {
botOne, err := NewFromSettings(&Settings{
ConfigFile: config.TestFile,
EnableDryRun: true,
})
}, make(map[string]bool))
if err != nil {
t.Error(err)
}