-
-
Notifications
You must be signed in to change notification settings - Fork 580
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add utils file for functions shared across command files. * Add --all flag to stop and remove commands. * Add tests for ddev stop. * Add test case to ensure a user can't combine --all and --remove-data. * Add --all to start, add test.
- Loading branch information
1 parent
fae2e47
commit 4e5d0c8
Showing
8 changed files
with
201 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package cmd | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/drud/ddev/pkg/ddevapp" | ||
"github.com/drud/ddev/pkg/exec" | ||
asrt "github.com/stretchr/testify/assert" | ||
) | ||
|
||
// TestDdevStart runs `ddev start` on the test apps | ||
func TestDdevStart(t *testing.T) { | ||
assert := asrt.New(t) | ||
|
||
// Make sure we have running sites. | ||
addSites() | ||
|
||
// Stop all sites. | ||
_, err := exec.RunCommand(DdevBin, []string{"stop", "--all"}) | ||
assert.NoError(err) | ||
|
||
// Ensure all sites are started after ddev start --all. | ||
out, err := exec.RunCommand(DdevBin, []string{"start", "--all"}) | ||
assert.NoError(err, "ddev start --all should succeed but failed, err: %v, output: %s", err, out) | ||
|
||
// Confirm all sites are running. | ||
apps := ddevapp.GetApps() | ||
for _, app := range apps { | ||
assert.True(app.SiteStatus() == ddevapp.SiteRunning, "All sites should be running, but %s status: %s", app.GetName(), app.SiteStatus()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package cmd | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/drud/ddev/pkg/ddevapp" | ||
"github.com/drud/ddev/pkg/exec" | ||
asrt "github.com/stretchr/testify/assert" | ||
) | ||
|
||
// TestDdevStop runs `ddev stop` on the test apps | ||
func TestDdevStop(t *testing.T) { | ||
assert := asrt.New(t) | ||
|
||
// Make sure we have running sites. | ||
addSites() | ||
|
||
for _, site := range DevTestSites { | ||
cleanup := site.Chdir() | ||
|
||
out, err := exec.RunCommand(DdevBin, []string{"stop"}) | ||
assert.NoError(err, "ddev stop should succeed but failed, err: %v, output: %s", err, out) | ||
assert.Contains(out, "has been stopped") | ||
|
||
apps := ddevapp.GetApps() | ||
for _, app := range apps { | ||
if app.GetName() != site.Name { | ||
continue | ||
} | ||
|
||
assert.True(app.SiteStatus() == ddevapp.SiteStopped) | ||
} | ||
|
||
cleanup() | ||
} | ||
|
||
// Re-create running sites. | ||
addSites() | ||
out, err := exec.RunCommand(DdevBin, []string{"stop", "--all"}) | ||
assert.NoError(err, "ddev stop --all should succeed but failed, err: %v, output: %s", err, out) | ||
|
||
// Confirm all sites are stopped. | ||
apps := ddevapp.GetApps() | ||
for _, app := range apps { | ||
assert.True(app.SiteStatus() == ddevapp.SiteStopped, "All sites should be stopped, but %s status: %s", app.GetName(), app.SiteStatus()) | ||
} | ||
|
||
// Now put the sites back together so other tests can use them. | ||
addSites() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/drud/ddev/pkg/ddevapp" | ||
) | ||
|
||
// getRequestedApps will collect and return the requested apps from command line arguments and flags. | ||
func getRequestedApps(args []string, all bool) ([]*ddevapp.DdevApp, error) { | ||
// If all is true, all active apps will be returned. | ||
if all { | ||
return ddevapp.GetApps(), nil | ||
} | ||
|
||
// If multiple apps are requested by their site name, collect and return them. | ||
if len(args) > 0 { | ||
var apps []*ddevapp.DdevApp | ||
|
||
for _, siteName := range args { | ||
app, err := ddevapp.GetActiveApp(siteName) | ||
if err != nil { | ||
return []*ddevapp.DdevApp{}, fmt.Errorf("failed to get %s: %v", siteName, err) | ||
} | ||
|
||
apps = append(apps, app) | ||
} | ||
|
||
return apps, nil | ||
} | ||
|
||
// If all is false and no specific apps are requested, return the current app. | ||
app, err := ddevapp.GetActiveApp("") | ||
if err != nil { | ||
return []*ddevapp.DdevApp{}, err | ||
} | ||
|
||
return []*ddevapp.DdevApp{app}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters