Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit eeb3270

Browse files
committed
refactor: extract docker app image tag command
This allows to remove duplication and avoid to write the wrong command. Signed-off-by: Yves Brissaud <[email protected]>
1 parent 2fe538c commit eeb3270

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

e2e/images_test.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ func TestImageTag(t *testing.T) {
9999
dir := fs.NewDir(t, "")
100100
defer dir.Remove()
101101

102+
dockerAppImageTag := func(args ...string) {
103+
cmdArgs := append([]string{"app", "image", "tag"}, args...)
104+
cmd.Command = dockerCli.Command(cmdArgs...)
105+
}
106+
102107
// given a first available image
103108
cmd.Command = dockerCli.Command("app", "bundle", filepath.Join("testdata", "simple", "simple.dockerapp"), "--tag", "a-simple-app", "--output", dir.Join("simple-bundle.json"))
104109
icmd.RunCmd(cmd).Assert(t, icmd.Success)
@@ -109,43 +114,43 @@ a-simple-app:latest simple
109114
expectImageListOutput(t, cmd, singleImageExpectation)
110115

111116
// with no argument
112-
cmd.Command = dockerCli.Command("app", "bundle", "tag")
117+
dockerAppImageTag()
113118
icmd.RunCmd(cmd).Assert(t, icmd.Expected{
114119
ExitCode: 1,
115120
Err: `"docker app image tag" requires exactly 2 arguments.`,
116121
})
117122

118123
// with one argument
119-
cmd.Command = dockerCli.Command("app", "image", "tag", "a-simple-app")
124+
dockerAppImageTag("a-simple-app")
120125
icmd.RunCmd(cmd).Assert(t, icmd.Expected{
121126
ExitCode: 1,
122127
Err: `"docker app image tag" requires exactly 2 arguments.`,
123128
})
124129

125130
// with invalid src reference
126-
cmd.Command = dockerCli.Command("app", "image", "tag", "a-simple-app$2", "b-simple-app")
131+
dockerAppImageTag("a-simple-app$2", "b-simple-app")
127132
icmd.RunCmd(cmd).Assert(t, icmd.Expected{
128133
ExitCode: 1,
129134
Err: `could not parse 'a-simple-app$2' as a valid reference: invalid reference format`,
130135
})
131136

132137
// with invalid target reference
133-
cmd.Command = dockerCli.Command("app", "image", "tag", "a-simple-app", "b@simple-app")
138+
dockerAppImageTag("a-simple-app", "b@simple-app")
134139
icmd.RunCmd(cmd).Assert(t, icmd.Expected{
135140
ExitCode: 1,
136141
Err: `could not parse 'b@simple-app' as a valid reference: invalid reference format`,
137142
})
138143

139144
// tag image with only names
140-
cmd.Command = dockerCli.Command("app", "image", "tag", "a-simple-app", "b-simple-app")
145+
dockerAppImageTag("a-simple-app", "b-simple-app")
141146
icmd.RunCmd(cmd).Assert(t, icmd.Success)
142147
expectImageListOutput(t, cmd, `APP IMAGE APP NAME
143148
a-simple-app:latest simple
144149
b-simple-app:latest simple
145150
`)
146151

147152
// target tag
148-
cmd.Command = dockerCli.Command("app", "image", "tag", "a-simple-app", "a-simple-app:0.1")
153+
dockerAppImageTag("a-simple-app", "a-simple-app:0.1")
149154
icmd.RunCmd(cmd).Assert(t, icmd.Success)
150155
expectImageListOutput(t, cmd, `APP IMAGE APP NAME
151156
a-simple-app:0.1 simple
@@ -154,7 +159,7 @@ b-simple-app:latest simple
154159
`)
155160

156161
// source tag
157-
cmd.Command = dockerCli.Command("app", "image", "tag", "a-simple-app:0.1", "c-simple-app")
162+
dockerAppImageTag("a-simple-app:0.1", "c-simple-app")
158163
icmd.RunCmd(cmd).Assert(t, icmd.Success)
159164
expectImageListOutput(t, cmd, `APP IMAGE APP NAME
160165
a-simple-app:0.1 simple
@@ -164,7 +169,7 @@ c-simple-app:latest simple
164169
`)
165170

166171
// source and target tags
167-
cmd.Command = dockerCli.Command("app", "image", "tag", "a-simple-app:0.1", "b-simple-app:0.2")
172+
dockerAppImageTag("a-simple-app:0.1", "b-simple-app:0.2")
168173
icmd.RunCmd(cmd).Assert(t, icmd.Success)
169174
expectImageListOutput(t, cmd, `APP IMAGE APP NAME
170175
a-simple-app:0.1 simple
@@ -187,7 +192,7 @@ push-pull:latest push-pull
187192
`)
188193

189194
// can be tagged to an existing tag
190-
cmd.Command = dockerCli.Command("app", "image", "tag", "push-pull", "b-simple-app:0.2")
195+
dockerAppImageTag("push-pull", "b-simple-app:0.2")
191196
icmd.RunCmd(cmd).Assert(t, icmd.Success)
192197
expectImageListOutput(t, cmd, `APP IMAGE APP NAME
193198
a-simple-app:0.1 simple

0 commit comments

Comments
 (0)