Skip to content

Commit

Permalink
Attempt to remove running projects before testing (#1013)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewfrench committed Jul 25, 2018
1 parent b282a8b commit ccaa5d3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions cmd/ddev/cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ func TestMain(m *testing.M) {
log.Errorln("could not set noninteractive mode, failed to Setenv, err: ", err)
}

// Attempt to remove all running containers before starting a test.
// If no projects are running, this will exit silently and without error.
if _, err = exec.RunCommand(DdevBin, []string{"remove", "--all"}); err != nil {
log.Warnf("Failed to remove all running projects: %v", err)
}

for i := range DevTestSites {
err = DevTestSites[i].Prepare()
if err != nil {
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 @@ -109,9 +109,16 @@ func TestMain(m *testing.M) {
// This is normally done by Testsite.Prepare()
_ = os.Setenv("DRUD_NONINTERACTIVE", "true")

// Attempt to remove all running containers before starting a test.
// If no projects are running, this will exit silently and without error.
// If a system doesn't have `ddev` in its $PATH, this will emit a warning but will not fail the test.
if _, err := exec.RunCommand("ddev", []string{"remove", "--all"}); err != nil {
log.Warnf("Failed to remove all running projects: %v", err)
}

count := len(ddevapp.GetApps())
if count > 0 {
log.Fatalf("ddevapp tests require no sites running. You have %v site(s) running.", count)
log.Fatalf("ddevapp tests require no projects running. You have %v project(s) running.", count)
}

// If GOTEST_SHORT is an integer, then use it as index for a single usage
Expand Down

0 comments on commit ccaa5d3

Please sign in to comment.