@@ -12,12 +12,7 @@ import (
1212)
1313
1414var (
15- reg = regexp .MustCompile ("Digest is (.*)." )
16- expected = `APP IMAGE APP NAME
17- %s push-pull
18- a-simple-app:latest simple
19- b-simple-app:latest simple
20- `
15+ reg = regexp .MustCompile ("Digest is (.*)." )
2116)
2217
2318func insertBundles (t * testing.T , cmd icmd.Cmd , dir * fs.Dir , info dindSwarmAndRegistryInfo ) string {
@@ -42,6 +37,12 @@ func insertBundles(t *testing.T, cmd icmd.Cmd, dir *fs.Dir, info dindSwarmAndReg
4237 return digest
4338}
4439
40+ func expectImageListOutput (t * testing.T , cmd icmd.Cmd , output string ) {
41+ cmd .Command = dockerCli .Command ("app" , "image" , "ls" )
42+ result := icmd .RunCmd (cmd ).Assert (t , icmd .Success )
43+ assert .Equal (t , result .Stdout (), output )
44+ }
45+
4546func TestImageList (t * testing.T ) {
4647 runWithDindSwarmAndRegistry (t , func (info dindSwarmAndRegistryInfo ) {
4748 cmd := info .configuredCmd
@@ -50,10 +51,13 @@ func TestImageList(t *testing.T) {
5051
5152 digest := insertBundles (t , cmd , dir , info )
5253
54+ expected := `APP IMAGE APP NAME
55+ %s push-pull
56+ a-simple-app:latest simple
57+ b-simple-app:latest simple
58+ `
5359 expectedOutput := fmt .Sprintf (expected , info .registryAddress + "/c-myapp@" + digest )
54- cmd .Command = dockerCli .Command ("app" , "image" , "ls" )
55- result := icmd .RunCmd (cmd ).Assert (t , icmd .Success )
56- assert .Equal (t , result .Stdout (), expectedOutput )
60+ expectImageListOutput (t , cmd , expectedOutput )
5761 })
5862}
5963
@@ -85,8 +89,101 @@ Deleted: b-simple-app:latest`,
8589 })
8690
8791 expectedOutput := "APP IMAGE APP NAME\n "
88- cmd .Command = dockerCli .Command ("app" , "image" , "ls" )
89- result := icmd .RunCmd (cmd ).Assert (t , icmd .Success )
90- assert .Equal (t , result .Stdout (), expectedOutput )
92+ expectImageListOutput (t , cmd , expectedOutput )
93+ })
94+ }
95+
96+ func TestImageTag (t * testing.T ) {
97+ runWithDindSwarmAndRegistry (t , func (info dindSwarmAndRegistryInfo ) {
98+ cmd := info .configuredCmd
99+ dir := fs .NewDir (t , "" )
100+ defer dir .Remove ()
101+
102+ // given a first available image
103+ cmd .Command = dockerCli .Command ("app" , "bundle" , filepath .Join ("testdata" , "simple" , "simple.dockerapp" ), "--tag" , "a-simple-app" , "--output" , dir .Join ("simple-bundle.json" ))
104+ icmd .RunCmd (cmd ).Assert (t , icmd .Success )
105+
106+ singleImageExpectation := `APP IMAGE APP NAME
107+ a-simple-app:latest simple
108+ `
109+ expectImageListOutput (t , cmd , singleImageExpectation )
110+
111+ // with no argument
112+ cmd .Command = dockerCli .Command ("app" , "bundle" , "tag" )
113+ icmd .RunCmd (cmd ).Assert (t , icmd.Expected {ExitCode : 1 })
114+
115+ // with one argument
116+ cmd .Command = dockerCli .Command ("app" , "bundle" , "tag" , "a-simple-app" )
117+ icmd .RunCmd (cmd ).Assert (t , icmd.Expected {ExitCode : 1 })
118+
119+ // with invalid src reference
120+ cmd .Command = dockerCli .Command ("app" , "bundle" , "tag" , "a-simple-app$2" , "b-simple-app" )
121+ icmd .RunCmd (cmd ).Assert (t , icmd.Expected {ExitCode : 1 })
122+
123+ // with invalid target reference
124+ cmd .Command = dockerCli .Command ("app" , "bundle" , "tag" , "a-simple-app" , "b@simple-app" )
125+ icmd .RunCmd (cmd ).Assert (t , icmd.Expected {ExitCode : 1 })
126+
127+ // tag image with only names
128+ cmd .Command = dockerCli .Command ("app" , "image" , "tag" , "a-simple-app" , "b-simple-app" )
129+ icmd .RunCmd (cmd ).Assert (t , icmd .Success )
130+ expectImageListOutput (t , cmd , `APP IMAGE APP NAME
131+ a-simple-app:latest simple
132+ b-simple-app:latest simple
133+ ` )
134+
135+ // target tag
136+ cmd .Command = dockerCli .Command ("app" , "image" , "tag" , "a-simple-app" , "a-simple-app:0.1" )
137+ icmd .RunCmd (cmd ).Assert (t , icmd .Success )
138+ expectImageListOutput (t , cmd , `APP IMAGE APP NAME
139+ a-simple-app:0.1 simple
140+ a-simple-app:latest simple
141+ b-simple-app:latest simple
142+ ` )
143+
144+ // source tag
145+ cmd .Command = dockerCli .Command ("app" , "image" , "tag" , "a-simple-app:0.1" , "c-simple-app" )
146+ icmd .RunCmd (cmd ).Assert (t , icmd .Success )
147+ expectImageListOutput (t , cmd , `APP IMAGE APP NAME
148+ a-simple-app:0.1 simple
149+ a-simple-app:latest simple
150+ b-simple-app:latest simple
151+ c-simple-app:latest simple
152+ ` )
153+
154+ // source and target tags
155+ cmd .Command = dockerCli .Command ("app" , "image" , "tag" , "a-simple-app:0.1" , "b-simple-app:0.2" )
156+ icmd .RunCmd (cmd ).Assert (t , icmd .Success )
157+ expectImageListOutput (t , cmd , `APP IMAGE APP NAME
158+ a-simple-app:0.1 simple
159+ a-simple-app:latest simple
160+ b-simple-app:0.2 simple
161+ b-simple-app:latest simple
162+ c-simple-app:latest simple
163+ ` )
164+
165+ // given a new application
166+ cmd .Command = dockerCli .Command ("app" , "bundle" , filepath .Join ("testdata" , "push-pull" , "push-pull.dockerapp" ), "--tag" , "push-pull" , "--output" , dir .Join ("push-pull-bundle.json" ))
167+ icmd .RunCmd (cmd ).Assert (t , icmd .Success )
168+ expectImageListOutput (t , cmd , `APP IMAGE APP NAME
169+ a-simple-app:0.1 simple
170+ a-simple-app:latest simple
171+ b-simple-app:0.2 simple
172+ b-simple-app:latest simple
173+ c-simple-app:latest simple
174+ push-pull:latest push-pull
175+ ` )
176+
177+ // can be tagged to an existing tag
178+ cmd .Command = dockerCli .Command ("app" , "image" , "tag" , "push-pull" , "b-simple-app:0.2" )
179+ icmd .RunCmd (cmd ).Assert (t , icmd .Success )
180+ expectImageListOutput (t , cmd , `APP IMAGE APP NAME
181+ a-simple-app:0.1 simple
182+ a-simple-app:latest simple
183+ b-simple-app:0.2 push-pull
184+ b-simple-app:latest simple
185+ c-simple-app:latest simple
186+ push-pull:latest push-pull
187+ ` )
91188 })
92189}
0 commit comments