@@ -42,32 +42,56 @@ func TestDisplayScanMessageAfterBuild(t *testing.T) {
42
42
43
43
t .Run ("display when docker build" , func (t * testing.T ) {
44
44
res := c .RunDockerCmd ("build" , "-t" , "test-image-scan-msg" , "./fixtures/simple-build-test/nginx-build" )
45
- res .Assert (t , icmd.Expected {Out : "Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them" })
45
+ defer c .RunDockerCmd ("rmi" , "-f" , "test-image-scan-msg" )
46
+ res .Assert (t , icmd.Expected {Err : "Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them" })
46
47
})
47
48
48
- t .Run ("do not display if envvar DOCKER_SCAN_SUGGEST=false" , func (t * testing.T ) {
49
+ t .Run ("do not display with docker build and quiet flag" , func (t * testing.T ) {
50
+ 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" )
52
+ assert .Assert (t , ! strings .Contains (res .Combined (), "docker scan" ))
53
+
54
+ 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" )
56
+ assert .Assert (t , ! strings .Contains (res .Combined (), "docker scan" ))
57
+ })
58
+
59
+ t .Run ("do not display if envvar DOCKER_SCAN_SUGGEST=false" , func (t * testing.T ) {
49
60
cmd := c .NewDockerCmd ("build" , "-t" , "test-image-scan-msg" , "./fixtures/build-test/nginx-build" )
61
+ defer c .RunDockerCmd ("rmi" , "-f" , "test-image-scan-msg" )
50
62
cmd .Env = append (cmd .Env , "DOCKER_SCAN_SUGGEST=false" )
51
63
res := icmd .StartCmd (cmd )
52
64
assert .Assert (t , ! strings .Contains (res .Combined (), "docker scan" ), res .Combined ())
53
65
})
54
66
55
67
t .Run ("display on compose build" , func (t * testing.T ) {
56
- res := c .RunDockerCmd ("compose" , "-f" , "./fixtures/simple-build-test/compose.yml" , "-p" , "scan-msg-test" , "build" )
57
- res .Assert (t , icmd.Expected {Out : "Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them" })
68
+ 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" )
70
+ res .Assert (t , icmd.Expected {Err : "Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them" })
71
+ })
72
+
73
+ t .Run ("do not display on compose build with quiet flag" , func (t * testing.T ) {
74
+ res := c .RunDockerCmd ("compose" , "-f" , "./fixtures/simple-build-test/compose.yml" , "-p" , "scan-msg-test-quiet" , "build" , "--quiet" )
75
+ assert .Assert (t , ! strings .Contains (res .Combined (), "docker scan" ), res .Combined ())
76
+ res = c .RunDockerCmd ("rmi" , "-f" , "scan-msg-test-quiet_nginx" )
77
+ assert .Assert (t , ! strings .Contains (res .Combined (), "No such image" ))
78
+
79
+ 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" )
81
+ assert .Assert (t , ! strings .Contains (res .Combined (), "docker scan" ), res .Combined ())
58
82
})
59
83
60
84
_ = c .RunDockerOrExitError ("rmi" , "scan-msg-test_nginx" )
61
85
62
86
t .Run ("display on compose up if image is built" , func (t * testing.T ) {
63
87
res := c .RunDockerCmd ("compose" , "-f" , "./fixtures/simple-build-test/compose.yml" , "-p" , "scan-msg-test" , "up" , "-d" )
64
88
defer c .RunDockerCmd ("compose" , "-f" , "./fixtures/simple-build-test/compose.yml" , "-p" , "scan-msg-test" , "down" )
65
- res .Assert (t , icmd.Expected {Out : "Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them" })
89
+ res .Assert (t , icmd.Expected {Err : "Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them" })
66
90
})
67
91
68
92
t .Run ("do not display on compose up if no image built" , func (t * testing.T ) { // re-run the same Compose aproject
69
93
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" )
94
+ defer c .RunDockerCmd ("compose" , "-f" , "./fixtures/simple-build-test/compose.yml" , "-p" , "scan-msg-test" , "down" , "--rmi" , "all" )
71
95
assert .Assert (t , ! strings .Contains (res .Combined (), "docker scan" ), res .Combined ())
72
96
})
73
97
0 commit comments