Skip to content

Commit

Permalink
Child config should have priority over parent config
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Duchesne committed Feb 5, 2019
1 parent d983b66 commit 9c213fc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ func findConfigFiles(folder string) (result []string) {
}

if parent := filepath.Dir(folder); parent != folder {
result = append(result, findConfigFiles(parent)...)
result = append(findConfigFiles(parent), result...)
}

return
Expand Down
37 changes: 35 additions & 2 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ func TestCheckVersionRange(t *testing.T) {
}

func TestSetConfigDefaultValues(t *testing.T) {
tempDir, _ := ioutil.TempDir("", "TestGetConfig")
tempDir, _ = filepath.EvalSymlinks(tempDir)
tempDir, _ := filepath.EvalSymlinks(must(ioutil.TempDir("", "TestGetConfig")).(string))
currentDir, _ := os.Getwd()
os.Chdir(tempDir)
fmt.Println(tempDir)
Expand Down Expand Up @@ -116,6 +115,40 @@ func TestSetConfigDefaultValues(t *testing.T) {
assert.Nil(t, config.ImageVersion)
}

func TestTwoLevelsOfTgfConfig(t *testing.T) {
tempDir, _ := filepath.EvalSymlinks(must(ioutil.TempDir("", "TestGetConfig")).(string))
subFolder := path.Join(tempDir, "sub-folder")
must(os.Mkdir(subFolder, os.ModePerm))
tempDir = subFolder
currentDir, _ := os.Getwd()
os.Chdir(tempDir)
fmt.Println(tempDir)
defer func() {
os.Chdir(currentDir)
os.RemoveAll(tempDir)
}()

testParentTgfConfigFile := fmt.Sprintf("%s/../.tgf.config", tempDir)
testTgfConfigFile := fmt.Sprintf("%s/.tgf.config", tempDir)
testSSMParameterFolder := fmt.Sprintf("/test/tgf-%v", randInt())

parentTgfConfig := []byte(String(`
docker-image: coveo/stuff
docker-image-version: 2.0.1
`).UnIndent().TrimSpace())
ioutil.WriteFile(testParentTgfConfigFile, parentTgfConfig, 0644)

// Current directory config overwrites parent directory config
tgfConfig := []byte(String(`docker-image-version: 2.0.2`))
ioutil.WriteFile(testTgfConfigFile, tgfConfig, 0644)

config := InitConfig()
config.setDefaultValues(testSSMParameterFolder)

assert.Equal(t, "coveo/stuff", config.Image)
assert.Equal(t, "2.0.2", *config.ImageVersion)
}

func TestWeirdDirName(t *testing.T) {
tempDir, _ := ioutil.TempDir("", "bad@(){}-good-_.1234567890ABC")
currentDir, _ := os.Getwd()
Expand Down

0 comments on commit 9c213fc

Please sign in to comment.