@@ -4,11 +4,11 @@ import (
44 "bufio"
55 "fmt"
66 "path/filepath"
7+ "regexp"
78 "strings"
89 "testing"
910
1011 "gotest.tools/assert"
11- "gotest.tools/fs"
1212 "gotest.tools/icmd"
1313)
1414
@@ -22,10 +22,20 @@ func insertBundles(t *testing.T, cmd icmd.Cmd, info dindSwarmAndRegistryInfo) {
2222 icmd .RunCmd (cmd ).Assert (t , icmd .Success )
2323}
2424
25+ func assertImageListOutput (t * testing.T , cmd icmd.Cmd , expected string ) {
26+ result := icmd .RunCmd (cmd ).Assert (t , icmd .Success )
27+ match , _ := regexp .MatchString (expected , result .Stdout ())
28+ assert .Assert (t , match )
29+ }
30+
2531func expectImageListOutput (t * testing.T , cmd icmd.Cmd , output string ) {
2632 cmd .Command = dockerCli .Command ("app" , "image" , "ls" )
27- result := icmd .RunCmd (cmd ).Assert (t , icmd .Success )
28- assert .Equal (t , result .Stdout (), output )
33+ assertImageListOutput (t , cmd , output )
34+ }
35+
36+ func expectImageListDigestsOutput (t * testing.T , cmd icmd.Cmd , output string ) {
37+ cmd .Command = dockerCli .Command ("app" , "image" , "ls" , "--digests" )
38+ assertImageListOutput (t , cmd , output )
2939}
3040
3141func verifyImageIDListOutput (t * testing.T , cmd icmd.Cmd , count int , distinct int ) {
@@ -48,36 +58,44 @@ func verifyImageIDListOutput(t *testing.T, cmd icmd.Cmd, count int, distinct int
4858func TestImageList (t * testing.T ) {
4959 runWithDindSwarmAndRegistry (t , func (info dindSwarmAndRegistryInfo ) {
5060 cmd := info .configuredCmd
51- dir := fs .NewDir (t , "" )
52- defer dir .Remove ()
5361
5462 insertBundles (t , cmd , info )
5563
56- expected := `APP IMAGE APP NAME
57- %s push-pull
58- a-simple-app:latest simple
59- b-simple-app:latest simple
64+ expected := `REPOSITORY TAG APP IMAGE ID APP NAME
65+ %s latest [a-f0-9]{12} push-pull
66+ a-simple-app latest [a-f0-9]{12} simple
67+ b-simple-app latest [a-f0-9]{12} simple
6068`
61- expectedOutput := fmt .Sprintf (expected , info .registryAddress + "/c-myapp:latest " )
69+ expectedOutput := fmt .Sprintf (expected , info .registryAddress + "/c-myapp" )
6270 expectImageListOutput (t , cmd , expectedOutput )
6371 })
6472}
6573
6674func TestImageListQuiet (t * testing.T ) {
6775 runWithDindSwarmAndRegistry (t , func (info dindSwarmAndRegistryInfo ) {
6876 cmd := info .configuredCmd
69- dir := fs .NewDir (t , "" )
70- defer dir .Remove ()
7177 insertBundles (t , cmd , info )
7278 verifyImageIDListOutput (t , cmd , 3 , 2 )
7379 })
7480}
7581
82+ func TestImageListDigests (t * testing.T ) {
83+ runWithDindSwarmAndRegistry (t , func (info dindSwarmAndRegistryInfo ) {
84+ cmd := info .configuredCmd
85+ insertBundles (t , cmd , info )
86+ expected := `REPOSITORY TAG DIGEST APP IMAGE ID APP NAME
87+ %s latest <none> [a-f0-9]{12} push-pull
88+ a-simple-app latest <none> [a-f0-9]{12} simple
89+ b-simple-app latest <none> [a-f0-9]{12} simple
90+ `
91+ expectedOutput := fmt .Sprintf (expected , info .registryAddress + "/c-myapp" )
92+ expectImageListDigestsOutput (t , cmd , expectedOutput )
93+ })
94+ }
95+
7696func TestImageRm (t * testing.T ) {
7797 runWithDindSwarmAndRegistry (t , func (info dindSwarmAndRegistryInfo ) {
7898 cmd := info .configuredCmd
79- dir := fs .NewDir (t , "" )
80- defer dir .Remove ()
8199
82100 insertBundles (t , cmd , info )
83101
@@ -100,7 +118,7 @@ Deleted: b-simple-app:latest`,
100118 Err : `b-simple-app:latest: reference not found` ,
101119 })
102120
103- expectedOutput := "APP IMAGE APP NAME\n "
121+ expectedOutput := "REPOSITORY TAG APP IMAGE ID APP NAME\n "
104122 expectImageListOutput (t , cmd , expectedOutput )
105123 })
106124}
@@ -118,8 +136,8 @@ func TestImageTag(t *testing.T) {
118136 cmd .Command = dockerCli .Command ("app" , "build" , "--tag" , "a-simple-app" , filepath .Join ("testdata" , "simple" ))
119137 icmd .RunCmd (cmd ).Assert (t , icmd .Success )
120138
121- singleImageExpectation := `APP IMAGE APP NAME
122- a-simple-app: latest simple
139+ singleImageExpectation := `REPOSITORY TAG APP IMAGE ID APP NAME
140+ a-simple-app latest [a-f0-9]{12} simple
123141`
124142 expectImageListOutput (t , cmd , singleImageExpectation )
125143
@@ -168,63 +186,63 @@ a-simple-app:latest simple
168186 // tag image with only names
169187 dockerAppImageTag ("a-simple-app" , "b-simple-app" )
170188 icmd .RunCmd (cmd ).Assert (t , icmd .Success )
171- expectImageListOutput (t , cmd , `APP IMAGE APP NAME
172- a-simple-app: latest simple
173- b-simple-app: latest simple
189+ expectImageListOutput (t , cmd , `REPOSITORY TAG APP IMAGE ID APP NAME
190+ a-simple-app latest [a-f0-9]{12} simple
191+ b-simple-app latest [a-f0-9]{12} simple
174192` )
175193
176194 // target tag
177195 dockerAppImageTag ("a-simple-app" , "a-simple-app:0.1" )
178196 icmd .RunCmd (cmd ).Assert (t , icmd .Success )
179- expectImageListOutput (t , cmd , `APP IMAGE APP NAME
180- a-simple-app: 0.1 simple
181- a-simple-app: latest simple
182- b-simple-app: latest simple
197+ expectImageListOutput (t , cmd , `REPOSITORY TAG APP IMAGE ID APP NAME
198+ a-simple-app 0.1 [a-f0-9]{12} simple
199+ a-simple-app latest [a-f0-9]{12} simple
200+ b-simple-app latest [a-f0-9]{12} simple
183201` )
184202
185203 // source tag
186204 dockerAppImageTag ("a-simple-app:0.1" , "c-simple-app" )
187205 icmd .RunCmd (cmd ).Assert (t , icmd .Success )
188- expectImageListOutput (t , cmd , `APP IMAGE APP NAME
189- a-simple-app: 0.1 simple
190- a-simple-app: latest simple
191- b-simple-app: latest simple
192- c-simple-app: latest simple
206+ expectImageListOutput (t , cmd , `REPOSITORY TAG APP IMAGE ID APP NAME
207+ a-simple-app 0.1 [a-f0-9]{12} simple
208+ a-simple-app latest [a-f0-9]{12} simple
209+ b-simple-app latest [a-f0-9]{12} simple
210+ c-simple-app latest [a-f0-9]{12} simple
193211` )
194212
195213 // source and target tags
196214 dockerAppImageTag ("a-simple-app:0.1" , "b-simple-app:0.2" )
197215 icmd .RunCmd (cmd ).Assert (t , icmd .Success )
198- expectImageListOutput (t , cmd , `APP IMAGE APP NAME
199- a-simple-app: 0.1 simple
200- a-simple-app: latest simple
201- b-simple-app: 0.2 simple
202- b-simple-app: latest simple
203- c-simple-app: latest simple
216+ expectImageListOutput (t , cmd , `REPOSITORY TAG APP IMAGE ID APP NAME
217+ a-simple-app 0.1 [a-f0-9]{12} simple
218+ a-simple-app latest [a-f0-9]{12} simple
219+ b-simple-app 0.2 [a-f0-9]{12} simple
220+ b-simple-app latest [a-f0-9]{12} simple
221+ c-simple-app latest [a-f0-9]{12} simple
204222` )
205223
206224 // given a new application
207225 cmd .Command = dockerCli .Command ("app" , "build" , "--tag" , "push-pull" , filepath .Join ("testdata" , "push-pull" ))
208226 icmd .RunCmd (cmd ).Assert (t , icmd .Success )
209- expectImageListOutput (t , cmd , `APP IMAGE APP NAME
210- a-simple-app: 0.1 simple
211- a-simple-app: latest simple
212- b-simple-app: 0.2 simple
213- b-simple-app: latest simple
214- c-simple-app: latest simple
215- push-pull:latest push-pull
227+ expectImageListOutput (t , cmd , `REPOSITORY TAG APP IMAGE ID APP NAME
228+ a-simple-app 0.1 [a-f0-9]{12} simple
229+ a-simple-app latest [a-f0-9]{12} simple
230+ b-simple-app 0.2 [a-f0-9]{12} simple
231+ b-simple-app latest [a-f0-9]{12} simple
232+ c-simple-app latest [a-f0-9]{12} simple
233+ push-pull latest [a-f0-9]{12} push-pull
216234` )
217235
218236 // can be tagged to an existing tag
219237 dockerAppImageTag ("push-pull" , "b-simple-app:0.2" )
220238 icmd .RunCmd (cmd ).Assert (t , icmd .Success )
221- expectImageListOutput (t , cmd , `APP IMAGE APP NAME
222- a-simple-app: 0.1 simple
223- a-simple-app: latest simple
224- b-simple-app: 0.2 push-pull
225- b-simple-app: latest simple
226- c-simple-app: latest simple
227- push-pull:latest push-pull
239+ expectImageListOutput (t , cmd , `REPOSITORY TAG APP IMAGE ID APP NAME
240+ a-simple-app 0.1 [a-f0-9]{12} simple
241+ a-simple-app latest [a-f0-9]{12} simple
242+ b-simple-app 0.2 [a-f0-9]{12} push-pull
243+ b-simple-app latest [a-f0-9]{12} simple
244+ c-simple-app latest [a-f0-9]{12} simple
245+ push-pull latest [a-f0-9]{12} push-pull
228246` )
229247 })
230248}
0 commit comments