Skip to content

Commit ff2bf78

Browse files
authored
Merge pull request docker#9612 from milas/e2e-start-stop
e2e: add more start/stop test cases
2 parents 0664944 + 4aa8c4a commit ff2bf78

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

pkg/e2e/start_stop_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
testify "github.com/stretchr/testify/assert"
2525
"gotest.tools/v3/assert"
26+
"gotest.tools/v3/icmd"
2627
)
2728

2829
func TestStartStop(t *testing.T) {
@@ -182,3 +183,66 @@ func TestStartStopWithOneOffs(t *testing.T) {
182183
assert.Assert(t, !strings.Contains(res.Combined(), "e2e-start-stop-with-oneoffs-bar"), res.Combined())
183184
})
184185
}
186+
187+
func TestStartAlreadyRunning(t *testing.T) {
188+
cli := NewParallelCLI(t, WithEnv(
189+
"COMPOSE_PROJECT_NAME=e2e-start-stop-svc-already-running",
190+
"COMPOSE_FILE=./fixtures/start-stop/compose.yaml"))
191+
t.Cleanup(func() {
192+
cli.RunDockerComposeCmd(t, "down", "--remove-orphans", "-v", "-t", "0")
193+
})
194+
195+
cli.RunDockerComposeCmd(t, "up", "-d", "--wait")
196+
197+
res := cli.RunDockerComposeCmd(t, "start", "simple")
198+
assert.Equal(t, res.Stdout(), "", "No output should have been written to stdout")
199+
}
200+
201+
func TestStopAlreadyStopped(t *testing.T) {
202+
cli := NewParallelCLI(t, WithEnv(
203+
"COMPOSE_PROJECT_NAME=e2e-start-stop-svc-already-stopped",
204+
"COMPOSE_FILE=./fixtures/start-stop/compose.yaml"))
205+
t.Cleanup(func() {
206+
cli.RunDockerComposeCmd(t, "down", "--remove-orphans", "-v", "-t", "0")
207+
})
208+
209+
cli.RunDockerComposeCmd(t, "up", "-d", "--wait")
210+
211+
// stop the container
212+
cli.RunDockerComposeCmd(t, "stop", "simple")
213+
214+
// attempt to stop it again
215+
res := cli.RunDockerComposeCmdNoCheck(t, "stop", "simple")
216+
// TODO: for consistency, this should NOT write any output because the
217+
// container is already stopped
218+
res.Assert(t, icmd.Expected{
219+
ExitCode: 0,
220+
Err: "Container e2e-start-stop-svc-already-stopped-simple-1 Stopped",
221+
})
222+
}
223+
224+
func TestStartStopMultipleServices(t *testing.T) {
225+
cli := NewParallelCLI(t, WithEnv(
226+
"COMPOSE_PROJECT_NAME=e2e-start-stop-svc-multiple",
227+
"COMPOSE_FILE=./fixtures/start-stop/compose.yaml"))
228+
t.Cleanup(func() {
229+
cli.RunDockerComposeCmd(t, "down", "--remove-orphans", "-v", "-t", "0")
230+
})
231+
232+
cli.RunDockerComposeCmd(t, "up", "-d", "--wait")
233+
234+
res := cli.RunDockerComposeCmd(t, "stop", "simple", "another")
235+
services := []string{"simple", "another"}
236+
for _, svc := range services {
237+
stopMsg := fmt.Sprintf("Container e2e-start-stop-svc-multiple-%s-1 Stopped", svc)
238+
assert.Assert(t, strings.Contains(res.Stderr(), stopMsg),
239+
fmt.Sprintf("Missing stop message for %s\n%s", svc, res.Combined()))
240+
}
241+
242+
res = cli.RunDockerComposeCmd(t, "start", "simple", "another")
243+
for _, svc := range services {
244+
startMsg := fmt.Sprintf("Container e2e-start-stop-svc-multiple-%s-1 Started", svc)
245+
assert.Assert(t, strings.Contains(res.Stderr(), startMsg),
246+
fmt.Sprintf("Missing start message for %s\n%s", svc, res.Combined()))
247+
}
248+
}

pkg/e2e/start_fail_test.go renamed to pkg/e2e/up_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"gotest.tools/v3/icmd"
2323
)
2424

25-
func TestStartFail(t *testing.T) {
25+
func TestUpServiceUnhealthy(t *testing.T) {
2626
c := NewParallelCLI(t)
2727
const projectName = "e2e-start-fail"
2828

0 commit comments

Comments
 (0)