@@ -3,7 +3,6 @@ package e2e
3
3
import (
4
4
"fmt"
5
5
"io/ioutil"
6
- "os"
7
6
"path/filepath"
8
7
"regexp"
9
8
"strings"
@@ -46,6 +45,9 @@ func TestRender(t *testing.T) {
46
45
47
46
func testRenderApp (appPath string , env ... string ) func (* testing.T ) {
48
47
return func (t * testing.T ) {
48
+ cmd , cleanup := dockerCli .createTestCmd ()
49
+ defer cleanup ()
50
+
49
51
envParameters := map [string ]string {}
50
52
data , err := ioutil .ReadFile (filepath .Join (appPath , "env.yml" ))
51
53
assert .NilError (t , err )
@@ -54,17 +56,19 @@ func testRenderApp(appPath string, env ...string) func(*testing.T) {
54
56
for k , v := range envParameters {
55
57
args = append (args , "--set" , fmt .Sprintf ("%s=%s" , k , v ))
56
58
}
57
- result := icmd .RunCmd (icmd.Cmd {
58
- Command : args ,
59
- Env : append (os .Environ (), env ... ),
60
- }).Assert (t , icmd .Success )
59
+ cmd .Command = args
60
+ cmd .Env = append (cmd .Env , env ... )
61
+ result := icmd .RunCmd (cmd ).Assert (t , icmd .Success )
61
62
assert .Assert (t , is .Equal (readFile (t , filepath .Join (appPath , "expected.txt" )), result .Stdout ()), "rendering mismatch" )
62
63
}
63
64
}
64
65
65
66
func TestRenderFormatters (t * testing.T ) {
67
+ cmd , cleanup := dockerCli .createTestCmd ()
68
+ defer cleanup ()
69
+
66
70
appPath := filepath .Join ("testdata" , "simple" , "simple.dockerapp" )
67
- cmd := icmd. Cmd { Command : dockerCli .Command ("app" , "render" , "--formatter" , "json" , appPath )}
71
+ cmd . Command = dockerCli .Command ("app" , "render" , "--formatter" , "json" , appPath )
68
72
result := icmd .RunCmd (cmd ).Assert (t , icmd .Success )
69
73
golden .Assert (t , result .Stdout (), "expected-json-render.golden" )
70
74
@@ -74,6 +78,9 @@ func TestRenderFormatters(t *testing.T) {
74
78
}
75
79
76
80
func TestInit (t * testing.T ) {
81
+ cmd , cleanup := dockerCli .createTestCmd ()
82
+ defer cleanup ()
83
+
77
84
composeData := `version: "3.2"
78
85
services:
79
86
nginx:
@@ -103,8 +110,7 @@ maintainers:
103
110
testAppName := "app-test"
104
111
dirName := internal .DirNameFromAppName (testAppName )
105
112
106
- cmd := icmd.Cmd {Dir : tmpDir .Path (), Env : os .Environ ()}
107
-
113
+ cmd .Dir = tmpDir .Path ()
108
114
cmd .Command = dockerCli .Command ("app" ,
109
115
"init" , testAppName ,
110
116
"--compose-file" , tmpDir .Join (internal .ComposeFileName ),
@@ -149,6 +155,9 @@ maintainers:
149
155
}
150
156
151
157
func TestDetectApp (t * testing.T ) {
158
+ cmd , cleanup := dockerCli .createTestCmd ()
159
+ defer cleanup ()
160
+
152
161
// cwd = e2e
153
162
dir := fs .NewDir (t , "detect-app-binary" ,
154
163
fs .WithDir ("attachments.dockerapp" , fs .FromDir ("testdata/attachments.dockerapp" )),
@@ -158,33 +167,35 @@ func TestDetectApp(t *testing.T) {
158
167
),
159
168
)
160
169
defer dir .Remove ()
161
- icmd .RunCmd (icmd.Cmd {
162
- Command : dockerCli .Command ("app" , "inspect" ),
163
- Dir : dir .Path (),
164
- }).Assert (t , icmd .Success )
165
- icmd .RunCmd (icmd.Cmd {
166
- Command : dockerCli .Command ("app" , "inspect" ),
167
- Dir : dir .Join ("attachments.dockerapp" ),
168
- }).Assert (t , icmd .Success )
169
- icmd .RunCmd (icmd.Cmd {
170
- Command : dockerCli .Command ("app" , "inspect" , "." ),
171
- Dir : dir .Join ("attachments.dockerapp" ),
172
- }).Assert (t , icmd .Success )
173
- result := icmd .RunCmd (icmd.Cmd {
174
- Command : dockerCli .Command ("app" , "inspect" ),
175
- Dir : dir .Join ("render" ),
176
- })
177
- result .Assert (t , icmd.Expected {
170
+
171
+ cmd .Command = dockerCli .Command ("app" , "inspect" )
172
+ cmd .Dir = dir .Path ()
173
+ icmd .RunCmd (cmd ).Assert (t , icmd .Success )
174
+
175
+ cmd .Command = dockerCli .Command ("app" , "inspect" )
176
+ cmd .Dir = dir .Join ("attachments.dockerapp" )
177
+ icmd .RunCmd (cmd ).Assert (t , icmd .Success )
178
+
179
+ cmd .Command = dockerCli .Command ("app" , "inspect" , "." )
180
+ cmd .Dir = dir .Join ("attachments.dockerapp" )
181
+ icmd .RunCmd (cmd ).Assert (t , icmd .Success )
182
+
183
+ cmd .Command = dockerCli .Command ("app" , "inspect" )
184
+ cmd .Dir = dir .Join ("render" )
185
+ icmd .RunCmd (cmd ).Assert (t , icmd.Expected {
178
186
ExitCode : 1 ,
179
187
Err : "Error: multiple applications found in current directory, specify the application name on the command line" ,
180
188
})
181
189
}
182
190
183
191
func TestSplitMerge (t * testing.T ) {
192
+ cmd , cleanup := dockerCli .createTestCmd ()
193
+ defer cleanup ()
194
+
184
195
tmpDir := fs .NewDir (t , "split_merge" )
185
196
defer tmpDir .Remove ()
186
197
187
- cmd := icmd. Cmd { Command : dockerCli .Command ("app" , "merge" , "testdata/render/envvariables/my.dockerapp" , "--output" , tmpDir .Join ("remerged.dockerapp" ))}
198
+ cmd . Command = dockerCli .Command ("app" , "merge" , "testdata/render/envvariables/my.dockerapp" , "--output" , tmpDir .Join ("remerged.dockerapp" ))
188
199
icmd .RunCmd (cmd ).Assert (t , icmd .Success )
189
200
190
201
cmd .Dir = tmpDir .Path ()
@@ -211,10 +222,11 @@ func TestSplitMerge(t *testing.T) {
211
222
}
212
223
213
224
func TestBundle (t * testing.T ) {
225
+ cmd , cleanup := dockerCli .createTestCmd ()
226
+ defer cleanup ()
227
+
214
228
tmpDir := fs .NewDir (t , t .Name ())
215
229
defer tmpDir .Remove ()
216
- // Using a custom DOCKER_CONFIG to store contexts in a temporary directory
217
- cmd := icmd.Cmd {Env : os .Environ ()}
218
230
219
231
// Running a docker in docker to bundle the application
220
232
dind := NewContainer ("docker:18.09-dind" , 2375 )
@@ -265,15 +277,14 @@ func TestBundle(t *testing.T) {
265
277
}
266
278
267
279
func TestDockerAppLifecycle (t * testing.T ) {
280
+ cmd , cleanup := dockerCli .createTestCmd ()
281
+ defer cleanup ()
282
+
268
283
tmpDir := fs .NewDir (t , t .Name ())
269
284
defer tmpDir .Remove ()
270
285
271
- cmd := icmd.Cmd {
272
- Env : append (os .Environ (),
273
- fmt .Sprintf ("DUFFLE_HOME=%s" , tmpDir .Path ()),
274
- "DOCKER_TARGET_CONTEXT=swarm-target-context" ,
275
- ),
276
- }
286
+ cmd .Env = append (cmd .Env , "DUFFLE_HOME=" + tmpDir .Path ())
287
+ cmd .Env = append (cmd .Env , "DOCKER_TARGET_CONTEXT=swarm-target-context" )
277
288
278
289
// Running a swarm using docker in docker to install the application
279
290
// and run the invocation image
@@ -289,10 +300,6 @@ func TestDockerAppLifecycle(t *testing.T) {
289
300
// - the target context for the invocation image to install within the swarm
290
301
cmd .Command = dockerCli .Command ("context" , "create" , "swarm-context" , "--docker" , fmt .Sprintf (`"host=tcp://%s"` , swarm .GetAddress (t )), "--default-stack-orchestrator" , "swarm" )
291
302
icmd .RunCmd (cmd ).Assert (t , icmd .Success )
292
- defer func () {
293
- cmd .Command = dockerCli .Command ("context" , "rm" , "--force" , "swarm-context" )
294
- icmd .RunCmd (cmd )
295
- }()
296
303
297
304
// When creating a context on a Windows host we cannot use
298
305
// the unix socket but it's needed inside the invocation image.
@@ -301,10 +308,6 @@ func TestDockerAppLifecycle(t *testing.T) {
301
308
// invocation image
302
309
cmd .Command = dockerCli .Command ("context" , "create" , "swarm-target-context" , "--docker" , "host=" , "--default-stack-orchestrator" , "swarm" )
303
310
icmd .RunCmd (cmd ).Assert (t , icmd .Success )
304
- defer func () {
305
- cmd .Command = dockerCli .Command ("context" , "rm" , "--force" , "swarm-target-context" )
306
- icmd .RunCmd (cmd )
307
- }()
308
311
309
312
// Initialize the swarm
310
313
cmd .Env = append (cmd .Env , "DOCKER_CONTEXT=swarm-context" )
0 commit comments