Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions clients/go/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,17 @@ func configPath() (string, error) {
}

for _, configName := range configNames {
possiblePath := filepath.Join(workingDir, configName)
if _, err := os.Stat(possiblePath); err == nil {
return possiblePath, nil
dir := workingDir
// loop up the directory tree
for {
possiblePath := filepath.Join(dir, configName)
if _, err := os.Stat(possiblePath); err == nil {
return possiblePath, nil
}
if filepath.Dir(dir) == dir { // reached the root directory
break
}
dir = filepath.Dir(dir)
}
}

Expand Down
39 changes: 32 additions & 7 deletions clients/go/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func TestConfigPath_ConfigInCWD(t *testing.T) {
t.Fatalf("Cannot Getwd, got: %s", err)
}

cwd := pwd + "/testdata"
cwd := pwd + "/testdata/config_files"

oldDir, _ := os.Getwd()
err = os.Chdir(cwd)
Expand All @@ -232,7 +232,7 @@ func TestConfigPath_ConfigInCWD(t *testing.T) {
if err != nil {
t.Fatalf("didn't expect an error, got: %s", err)
}
expPath := cwd + "/.phraseapp.yml"
expPath := cwd + "/.phrase.yml"
if path != expPath {
t.Errorf("expected path to be %q, got %q", expPath, path)
}
Expand Down Expand Up @@ -269,7 +269,7 @@ func TestConfigPath_ConfigInHomeDir(t *testing.T) {
t.Fatalf("Cannot Getwd, got: %s", err)
}

cwd := pwd + "/testdata/empty"
cwd := pwd + "/testdata/empty2"

oldDir, _ := os.Getwd()
err = os.Chdir(cwd)
Expand All @@ -278,7 +278,7 @@ func TestConfigPath_ConfigInHomeDir(t *testing.T) {
}
defer os.Chdir(oldDir)

newHome := pwd + "/testdata"
newHome := pwd + "/testdata/config_files"
oldHome := os.Getenv("HOME")
os.Setenv("HOME", newHome)
defer os.Setenv("HOME", oldHome)
Expand All @@ -287,7 +287,32 @@ func TestConfigPath_ConfigInHomeDir(t *testing.T) {
if err != nil {
t.Fatalf("didn't expect an error, got: %s", err)
}
expPath := newHome + "/.phraseapp.yml"
expPath := newHome + "/.phrase.yml"
if path != expPath {
t.Errorf("expected path to be %q, got %q", expPath, path)
}
}

func TestConfigPath_ConfigInParentDir(t *testing.T) {
pwd, err := os.Getwd()
if err != nil {
t.Fatalf("Cannot Getwd, got: %s", err)
}

cwd := pwd + "/testdata/config_files/empty"

oldDir, _ := os.Getwd()
err = os.Chdir(cwd)
if err != nil {
t.Fatalf("didn't expect an error changing the working directory, got: %s", err)
}
defer os.Chdir(oldDir)

path, err := configPath()
if err != nil {
t.Fatalf("didn't expect an error, got: %s", err)
}
expPath := pwd + "/testdata/config_files/.phrase.yml"
if path != expPath {
t.Errorf("expected path to be %q, got %q", expPath, path)
}
Expand All @@ -302,7 +327,7 @@ func TestConfigPath_NoConfigAvailable(t *testing.T) {
t.Fatalf("Cannot Getwd, got: %s", err)
}

cwd := pwd + "/testdata/empty"
cwd := pwd + "/testdata/empty2"

oldDir, _ := os.Getwd()
err = os.Chdir(cwd)
Expand All @@ -318,7 +343,7 @@ func TestConfigPath_NoConfigAvailable(t *testing.T) {
t.Fatalf("Cannot Getwd, got: %s", err)
}

os.Setenv("HOME", pwd+"/testdata/empty2")
os.Setenv("HOME", pwd+"/testdata")
defer os.Setenv("HOME", oldHome)

path, err := configPath()
Expand Down
Empty file removed clients/go/testdata/.phraseapp.yml
Empty file.
Loading