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

Commit 02b9363

Browse files
committed
avoid assertions in defer statements.
Signed-off-by: Guillaume Tardif <[email protected]>
1 parent c804b7a commit 02b9363

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

local/e2e/compose/compose_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func TestAttachRestart(t *testing.T) {
145145
c := NewParallelE2eCLI(t, binDir)
146146

147147
res := c.RunDockerOrExitError("compose", "--ansi=never", "--project-directory", "./fixtures/attach-restart", "up")
148-
defer c.RunDockerCmd("compose", "-p", "attach-restart", "down")
148+
defer c.RunDockerOrExitError("compose", "-p", "attach-restart", "down")
149149
output := res.Stdout()
150150

151151
exitRegex := regexp.MustCompile("another_1 exited with code 1")
@@ -159,7 +159,7 @@ func TestInitContainer(t *testing.T) {
159159
c := NewParallelE2eCLI(t, binDir)
160160

161161
res := c.RunDockerOrExitError("compose", "--ansi=never", "--project-directory", "./fixtures/init-container", "up")
162-
defer c.RunDockerCmd("compose", "-p", "init-container", "down")
162+
defer c.RunDockerOrExitError("compose", "-p", "init-container", "down")
163163
output := res.Stdout()
164164

165165
assert.Assert(t, strings.Contains(output, "foo_1 | hello\nbar_1 | world"), res.Combined())

local/e2e/compose/scan_message_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,31 +42,31 @@ func TestDisplayScanMessageAfterBuild(t *testing.T) {
4242

4343
t.Run("display when docker build", func(t *testing.T) {
4444
res := c.RunDockerCmd("build", "-t", "test-image-scan-msg", "./fixtures/simple-build-test/nginx-build")
45-
defer c.RunDockerCmd("rmi", "-f", "test-image-scan-msg")
45+
defer c.RunDockerOrExitError("rmi", "-f", "test-image-scan-msg")
4646
res.Assert(t, icmd.Expected{Err: "Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them"})
4747
})
4848

4949
t.Run("do not display with docker build and quiet flag", func(t *testing.T) {
5050
res := c.RunDockerCmd("build", "-t", "test-image-scan-msg-quiet", "--quiet", "./fixtures/simple-build-test/nginx-build")
51-
defer c.RunDockerCmd("rmi", "-f", "test-image-scan-msg-quiet")
51+
defer c.RunDockerOrExitError("rmi", "-f", "test-image-scan-msg-quiet")
5252
assert.Assert(t, !strings.Contains(res.Combined(), "docker scan"))
5353

5454
res = c.RunDockerCmd("build", "-t", "test-image-scan-msg-q", "-q", "./fixtures/simple-build-test/nginx-build")
55-
defer c.RunDockerCmd("rmi", "-f", "test-image-scan-msg-q")
55+
defer c.RunDockerOrExitError("rmi", "-f", "test-image-scan-msg-q")
5656
assert.Assert(t, !strings.Contains(res.Combined(), "docker scan"))
5757
})
5858

5959
t.Run("do not display if envvar DOCKER_SCAN_SUGGEST=false", func(t *testing.T) {
6060
cmd := c.NewDockerCmd("build", "-t", "test-image-scan-msg", "./fixtures/build-test/nginx-build")
61-
defer c.RunDockerCmd("rmi", "-f", "test-image-scan-msg")
61+
defer c.RunDockerOrExitError("rmi", "-f", "test-image-scan-msg")
6262
cmd.Env = append(cmd.Env, "DOCKER_SCAN_SUGGEST=false")
6363
res := icmd.StartCmd(cmd)
6464
assert.Assert(t, !strings.Contains(res.Combined(), "docker scan"), res.Combined())
6565
})
6666

6767
t.Run("display on compose build", func(t *testing.T) {
6868
res := c.RunDockerCmd("compose", "-f", "./fixtures/simple-build-test/compose.yml", "-p", "scan-msg-test-compose-build", "build")
69-
defer c.RunDockerCmd("rmi", "-f", "scan-msg-test-compose-build_nginx")
69+
defer c.RunDockerOrExitError("rmi", "-f", "scan-msg-test-compose-build_nginx")
7070
res.Assert(t, icmd.Expected{Err: "Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them"})
7171
})
7272

@@ -77,21 +77,21 @@ func TestDisplayScanMessageAfterBuild(t *testing.T) {
7777
assert.Assert(t, !strings.Contains(res.Combined(), "No such image"))
7878

7979
res = c.RunDockerCmd("compose", "-f", "./fixtures/simple-build-test/compose.yml", "-p", "scan-msg-test-q", "build", "-q")
80-
defer c.RunDockerCmd("rmi", "-f", "scan-msg-test-q_nginx")
80+
defer c.RunDockerOrExitError("rmi", "-f", "scan-msg-test-q_nginx")
8181
assert.Assert(t, !strings.Contains(res.Combined(), "docker scan"), res.Combined())
8282
})
8383

8484
_ = c.RunDockerOrExitError("rmi", "scan-msg-test_nginx")
8585

8686
t.Run("display on compose up if image is built", func(t *testing.T) {
8787
res := c.RunDockerCmd("compose", "-f", "./fixtures/simple-build-test/compose.yml", "-p", "scan-msg-test", "up", "-d")
88-
defer c.RunDockerCmd("compose", "-f", "./fixtures/simple-build-test/compose.yml", "-p", "scan-msg-test", "down")
88+
defer c.RunDockerOrExitError("compose", "-f", "./fixtures/simple-build-test/compose.yml", "-p", "scan-msg-test", "down")
8989
res.Assert(t, icmd.Expected{Err: "Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them"})
9090
})
9191

9292
t.Run("do not display on compose up if no image built", func(t *testing.T) { // re-run the same Compose aproject
9393
res := c.RunDockerCmd("compose", "-f", "./fixtures/simple-build-test/compose.yml", "-p", "scan-msg-test", "up", "-d")
94-
defer c.RunDockerCmd("compose", "-f", "./fixtures/simple-build-test/compose.yml", "-p", "scan-msg-test", "down", "--rmi", "all")
94+
defer c.RunDockerOrExitError("compose", "-f", "./fixtures/simple-build-test/compose.yml", "-p", "scan-msg-test", "down", "--rmi", "all")
9595
assert.Assert(t, !strings.Contains(res.Combined(), "docker scan"), res.Combined())
9696
})
9797

0 commit comments

Comments
 (0)