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

Commit 6aed81e

Browse files
authored
Merge pull request #1511 from gtardif/fix_test_race
Avoid race between parallel tests, add specific build sample for scan_message_test
2 parents eb7732f + 088b13b commit 6aed81e

File tree

5 files changed

+44
-11
lines changed

5 files changed

+44
-11
lines changed

local/e2e/compose/compose_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ func TestLocalComposeUp(t *testing.T) {
6969
t.Run("top", func(t *testing.T) {
7070
res := c.RunDockerCmd("compose", "-p", projectName, "top")
7171
output := res.Stdout()
72-
assert.Assert(t, strings.Contains(output, `UID PID PPID C STIME TTY TIME CMD`))
73-
assert.Assert(t, strings.Contains(output, `java -Xmx8m -Xms8m -jar /app/words.jar`))
74-
assert.Assert(t, strings.Contains(output, `/dispatcher`))
72+
assert.Assert(t, strings.Contains(output, `UID PID PPID C STIME TTY TIME CMD`), output)
73+
assert.Assert(t, strings.Contains(output, `java -Xmx8m -Xms8m -jar /app/words.jar`), output)
74+
assert.Assert(t, strings.Contains(output, `/dispatcher`), output)
7575
})
7676

7777
t.Run("check compose labels", func(t *testing.T) {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
services:
2+
nginx:
3+
build: nginx-build
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2020 Docker Compose CLI authors
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
FROM nginx
16+
17+
ARG FOO
18+
LABEL FOO=$FOO
19+
COPY static /usr/share/nginx/html
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Docker Nginx</title>
6+
</head>
7+
<body>
8+
<h2>Hello from Nginx container</h2>
9+
</body>
10+
</html>

local/e2e/compose/scan_message_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ import (
3333
)
3434

3535
func TestDisplayScanMessageAfterBuild(t *testing.T) {
36+
3637
c := NewParallelE2eCLI(t, binDir)
3738
setupScanPlugin(t, c)
3839

3940
res := c.RunDockerCmd("info")
4041
res.Assert(t, icmd.Expected{Out: "scan: Docker Scan"})
4142

4243
t.Run("display when docker build", func(t *testing.T) {
43-
res := c.RunDockerCmd("build", "-t", "test-image-scan-msg", "./fixtures/build-test/nginx-build")
44+
res := c.RunDockerCmd("build", "-t", "test-image-scan-msg", "./fixtures/simple-build-test/nginx-build")
4445
res.Assert(t, icmd.Expected{Out: "Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them"})
4546
})
4647

@@ -52,21 +53,21 @@ func TestDisplayScanMessageAfterBuild(t *testing.T) {
5253
})
5354

5455
t.Run("display on compose build", func(t *testing.T) {
55-
res := c.RunDockerCmd("compose", "-f", "./fixtures/build-test/compose.yml", "build")
56+
res := c.RunDockerCmd("compose", "-f", "./fixtures/simple-build-test/compose.yml", "-p", "scan-msg-test", "build")
5657
res.Assert(t, icmd.Expected{Out: "Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them"})
5758
})
5859

59-
_ = c.RunDockerOrExitError("rmi", "build-test_nginx")
60+
_ = c.RunDockerOrExitError("rmi", "scan-msg-test_nginx")
6061

6162
t.Run("display on compose up if image is built", func(t *testing.T) {
62-
res := c.RunDockerCmd("compose", "-f", "./fixtures/build-test/compose.yml", "up", "-d")
63-
defer c.RunDockerCmd("compose", "-f", "./fixtures/build-test/compose.yml", "down")
63+
res := c.RunDockerCmd("compose", "-f", "./fixtures/simple-build-test/compose.yml", "-p", "scan-msg-test", "up", "-d")
64+
defer c.RunDockerCmd("compose", "-f", "./fixtures/simple-build-test/compose.yml", "-p", "scan-msg-test", "down")
6465
res.Assert(t, icmd.Expected{Out: "Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them"})
6566
})
6667

6768
t.Run("do not display on compose up if no image built", func(t *testing.T) { // re-run the same Compose aproject
68-
res := c.RunDockerCmd("compose", "-f", "./fixtures/build-test/compose.yml", "up", "-d")
69-
defer c.RunDockerCmd("compose", "-f", "./fixtures/build-test/compose.yml", "down")
69+
res := c.RunDockerCmd("compose", "-f", "./fixtures/simple-build-test/compose.yml", "-p", "scan-msg-test", "up", "-d")
70+
defer c.RunDockerCmd("compose", "-f", "./fixtures/simple-build-test/compose.yml", "-p", "scan-msg-test", "down")
7071
assert.Assert(t, !strings.Contains(res.Combined(), "docker scan"), res.Combined())
7172
})
7273

@@ -76,7 +77,7 @@ func TestDisplayScanMessageAfterBuild(t *testing.T) {
7677
err := ioutil.WriteFile(scanConfigFile, []byte(`{"optin":true}`), 0644)
7778
assert.NilError(t, err)
7879

79-
res := c.RunDockerCmd("build", "-t", "test-image-scan-msg", "./fixtures/build-test/nginx-build")
80+
res := c.RunDockerCmd("build", "-t", "test-image-scan-msg", "./fixtures/simple-build-test/nginx-build")
8081
assert.Assert(t, !strings.Contains(res.Combined(), "docker scan"), res.Combined())
8182
})
8283
}

0 commit comments

Comments
 (0)