Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 1926820

Browse files
committed
Add e2e tests
Signed-off-by: Ulysses Souza <[email protected]>
1 parent 2fdc3ba commit 1926820

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
services:
2+
restart:
3+
image: busybox
4+
command: ash -c "if [[ -f /tmp/restart.lock ]] ; then sleep infinity; else touch /tmp/restart.lock; fi"

local/e2e/compose/restart_test.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
Copyright 2020 Docker Compose CLI authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package e2e
18+
19+
import (
20+
"fmt"
21+
"strings"
22+
"testing"
23+
"time"
24+
25+
testify "github.com/stretchr/testify/assert"
26+
"gotest.tools/v3/assert"
27+
28+
. "github.com/docker/compose-cli/utils/e2e"
29+
)
30+
31+
func TestRestart(t *testing.T) {
32+
c := NewParallelE2eCLI(t, binDir)
33+
const projectName = "e2e-restart"
34+
35+
getServiceRegx := func(service string, status string) string {
36+
// match output with random spaces like:
37+
// e2e-start-stop_db_1 db running
38+
return fmt.Sprintf("%s_%s_1\\s+%s\\s+%s", projectName, service, service, status)
39+
}
40+
41+
t.Run("Up a project", func(t *testing.T) {
42+
// This is just to ensure the containers do NOT exist
43+
c.RunDockerOrExitError("compose", "--project-name", projectName, "down")
44+
45+
res := c.RunDockerOrExitError("compose", "-f", "./fixtures/restart-test/compose.yml", "--project-name", projectName, "up", "-d")
46+
assert.Assert(t, strings.Contains(res.Combined(), "Container e2e-restart_restart_1 Started"), res.Combined())
47+
48+
// Give the time for it to exit
49+
time.Sleep(time.Second)
50+
51+
res = c.RunDockerOrExitError("compose", "--project-name", projectName, "ps", "-a")
52+
testify.Regexp(t, getServiceRegx("restart", "exited"), res.Stdout())
53+
54+
_ = c.RunDockerOrExitError("compose", "-f", "./fixtures/restart-test/compose.yml", "--project-name", projectName, "restart")
55+
56+
// Give the same time but it must NOT exit
57+
time.Sleep(time.Second)
58+
59+
res = c.RunDockerOrExitError("compose", "--project-name", projectName, "ps")
60+
testify.Regexp(t, getServiceRegx("restart", "running"), res.Stdout())
61+
62+
// Clean up
63+
c.RunDockerOrExitError("compose", "--project-name", projectName, "down")
64+
})
65+
}

0 commit comments

Comments
 (0)