mirror of https://github.com/docker/compose.git
e2e: add more start/stop test cases
* Starting a service that's already running * Stopping a service that's already stopped * Starting/stopping multiple services (by name) at once Also renamed a test that was about `up` behavior but was misleadingly labeled start/stop. Signed-off-by: Milas Bowman <milas.bowman@docker.com>
This commit is contained in:
parent
06649442eb
commit
4aa8c4a1e5
|
@ -23,6 +23,7 @@ import (
|
|||
|
||||
testify "github.com/stretchr/testify/assert"
|
||||
"gotest.tools/v3/assert"
|
||||
"gotest.tools/v3/icmd"
|
||||
)
|
||||
|
||||
func TestStartStop(t *testing.T) {
|
||||
|
@ -182,3 +183,66 @@ func TestStartStopWithOneOffs(t *testing.T) {
|
|||
assert.Assert(t, !strings.Contains(res.Combined(), "e2e-start-stop-with-oneoffs-bar"), res.Combined())
|
||||
})
|
||||
}
|
||||
|
||||
func TestStartAlreadyRunning(t *testing.T) {
|
||||
cli := NewParallelCLI(t, WithEnv(
|
||||
"COMPOSE_PROJECT_NAME=e2e-start-stop-svc-already-running",
|
||||
"COMPOSE_FILE=./fixtures/start-stop/compose.yaml"))
|
||||
t.Cleanup(func() {
|
||||
cli.RunDockerComposeCmd(t, "down", "--remove-orphans", "-v", "-t", "0")
|
||||
})
|
||||
|
||||
cli.RunDockerComposeCmd(t, "up", "-d", "--wait")
|
||||
|
||||
res := cli.RunDockerComposeCmd(t, "start", "simple")
|
||||
assert.Equal(t, res.Stdout(), "", "No output should have been written to stdout")
|
||||
}
|
||||
|
||||
func TestStopAlreadyStopped(t *testing.T) {
|
||||
cli := NewParallelCLI(t, WithEnv(
|
||||
"COMPOSE_PROJECT_NAME=e2e-start-stop-svc-already-stopped",
|
||||
"COMPOSE_FILE=./fixtures/start-stop/compose.yaml"))
|
||||
t.Cleanup(func() {
|
||||
cli.RunDockerComposeCmd(t, "down", "--remove-orphans", "-v", "-t", "0")
|
||||
})
|
||||
|
||||
cli.RunDockerComposeCmd(t, "up", "-d", "--wait")
|
||||
|
||||
// stop the container
|
||||
cli.RunDockerComposeCmd(t, "stop", "simple")
|
||||
|
||||
// attempt to stop it again
|
||||
res := cli.RunDockerComposeCmdNoCheck(t, "stop", "simple")
|
||||
// TODO: for consistency, this should NOT write any output because the
|
||||
// container is already stopped
|
||||
res.Assert(t, icmd.Expected{
|
||||
ExitCode: 0,
|
||||
Err: "Container e2e-start-stop-svc-already-stopped-simple-1 Stopped",
|
||||
})
|
||||
}
|
||||
|
||||
func TestStartStopMultipleServices(t *testing.T) {
|
||||
cli := NewParallelCLI(t, WithEnv(
|
||||
"COMPOSE_PROJECT_NAME=e2e-start-stop-svc-multiple",
|
||||
"COMPOSE_FILE=./fixtures/start-stop/compose.yaml"))
|
||||
t.Cleanup(func() {
|
||||
cli.RunDockerComposeCmd(t, "down", "--remove-orphans", "-v", "-t", "0")
|
||||
})
|
||||
|
||||
cli.RunDockerComposeCmd(t, "up", "-d", "--wait")
|
||||
|
||||
res := cli.RunDockerComposeCmd(t, "stop", "simple", "another")
|
||||
services := []string{"simple", "another"}
|
||||
for _, svc := range services {
|
||||
stopMsg := fmt.Sprintf("Container e2e-start-stop-svc-multiple-%s-1 Stopped", svc)
|
||||
assert.Assert(t, strings.Contains(res.Stderr(), stopMsg),
|
||||
fmt.Sprintf("Missing stop message for %s\n%s", svc, res.Combined()))
|
||||
}
|
||||
|
||||
res = cli.RunDockerComposeCmd(t, "start", "simple", "another")
|
||||
for _, svc := range services {
|
||||
startMsg := fmt.Sprintf("Container e2e-start-stop-svc-multiple-%s-1 Started", svc)
|
||||
assert.Assert(t, strings.Contains(res.Stderr(), startMsg),
|
||||
fmt.Sprintf("Missing start message for %s\n%s", svc, res.Combined()))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ import (
|
|||
"gotest.tools/v3/icmd"
|
||||
)
|
||||
|
||||
func TestStartFail(t *testing.T) {
|
||||
func TestUpServiceUnhealthy(t *testing.T) {
|
||||
c := NewParallelCLI(t)
|
||||
const projectName = "e2e-start-fail"
|
||||
|
Loading…
Reference in New Issue