Skip to content

Commit

Permalink
[regression fix] Make project uniqueness constraint work again, fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
rfay committed May 25, 2018
1 parent adb0b8e commit 8140f3d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pkg/ddevapp/ddevapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (app *DdevApp) Init(basePath string) error {
if err == nil {
containerApproot := web.Labels["com.ddev.approot"]
if containerApproot != app.AppRoot {
return fmt.Errorf("a web container in %s state already exists for %s that was created at %s", web.State, app.Name, containerApproot)
return fmt.Errorf("a project (web container) in %s state already exists for %s that was created at %s", web.State, app.Name, containerApproot)
}
return nil
} else if strings.Contains(err.Error(), "could not find containers") {
Expand Down Expand Up @@ -1071,7 +1071,7 @@ func GetActiveApp(siteName string) (*DdevApp, error) {
// We already were successful with *finding* the app, and if we get an
// incomplete one we have to add to it.
err = app.Init(activeAppRoot)
if err != nil && (strings.Contains(err.Error(), "is not a valid hostname") || strings.Contains(err.Error(), "is not a valid apptype") || strings.Contains(err.Error(), "config.yaml exists but cannot be read.")) {
if err != nil && (strings.Contains(err.Error(), "is not a valid hostname") || strings.Contains(err.Error(), "is not a valid apptype") || strings.Contains(err.Error(), "config.yaml exists but cannot be read.") || strings.Contains(err.Error(), "a project (web container) in ")) {
return app, err
}

Expand Down
9 changes: 8 additions & 1 deletion pkg/ddevapp/ddevapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,15 @@ func TestDdevStart(t *testing.T) {

err = app.Init(another.Dir)
assert.Error(err)
assert.Contains(err.Error(), fmt.Sprintf("container in running state already exists for %s that was created at %s", TestSites[0].Name, TestSites[0].Dir))
assert.Contains(err.Error(), fmt.Sprintf("a project (web container) in running state already exists for %s that was created at %s", TestSites[0].Name, TestSites[0].Dir))

// Make sure that GetActiveApp() also fails when trying to start app of duplicate name in current directory.
switchDir := another.Chdir()
_, err = ddevapp.GetActiveApp("")
assert.Error(err)
assert.Contains(err.Error(), fmt.Sprintf("a project (web container) in running state already exists for %s that was created at %s", TestSites[0].Name, TestSites[0].Dir))
testcommon.CleanupDir(another.Dir)
switchDir()
}

// TestDdevStartMultipleHostnames tests start with multiple hostnames
Expand Down
2 changes: 2 additions & 0 deletions pkg/testcommon/testcommon.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,14 @@ func Chdir(path string) func() {
curDir, _ := os.Getwd()
err := os.Chdir(path)
if err != nil {
// TODO: This should never Fatalf, as it terminates the process without test running finishing cleanup.
log.Fatalf("Could not change to directory %s: %v\n", path, err)
}

return func() {
err := os.Chdir(curDir)
if err != nil {
// TODO: This should never Fatalf, as it terminates the process without test running finishing cleanup.
log.Fatalf("Failed to change directory to original dir=%s, err=%v", curDir, err)
}
}
Expand Down

0 comments on commit 8140f3d

Please sign in to comment.