-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathintegration_test.go
407 lines (335 loc) · 12.4 KB
/
integration_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
package out_test
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gbytes"
"github.com/onsi/gomega/gexec"
"github.com/concourse/cf-resource"
"github.com/concourse/cf-resource/out"
)
var _ = Describe("Out", func() {
var (
tmpDir string
cmd *exec.Cmd
request out.Request
)
BeforeEach(func() {
var err error
tmpDir, err = ioutil.TempDir("", "cf_resource_out")
Expect(err).NotTo(HaveOccurred())
err = os.Mkdir(filepath.Join(tmpDir, "project"), 0755)
Expect(err).NotTo(HaveOccurred())
err = ioutil.WriteFile(filepath.Join(tmpDir, "project", "manifest.yml"), []byte{}, 0555)
Expect(err).NotTo(HaveOccurred())
err = os.Mkdir(filepath.Join(tmpDir, "another-project"), 0555)
Expect(err).NotTo(HaveOccurred())
request = out.Request{
Source: resource.Source{
API: "https://api.run.pivotal.io",
Username: "[email protected]",
Password: "hunter2",
Organization: "org",
Space: "space",
SkipCertCheck: true,
Verbose: true,
},
Params: out.Params{
ManifestPath: "project/manifest.yml",
Path: "another-project",
CurrentAppName: "awesome-app",
},
}
})
JustBeforeEach(func() {
assetsPath, err := filepath.Abs("assets")
Expect(err).NotTo(HaveOccurred())
stdin := &bytes.Buffer{}
err = json.NewEncoder(stdin).Encode(request)
Expect(err).NotTo(HaveOccurred())
cmd = exec.Command(binPath, tmpDir)
cmd.Stdin = stdin
cmd.Dir = tmpDir
newEnv := []string{}
for _, envVar := range os.Environ() {
if strings.HasPrefix(envVar, "PATH=") {
newEnv = append(newEnv, fmt.Sprintf("PATH=%s:%s", assetsPath, os.Getenv("PATH")))
} else {
newEnv = append(newEnv, envVar)
}
}
cmd.Env = newEnv
})
AfterEach(func() {
err := os.RemoveAll(tmpDir)
Expect(err).NotTo(HaveOccurred())
})
Context("when my manifest and paths do not contain a glob", func() {
It("pushes an application to cloud foundry", func() {
session, err := gexec.Start(
cmd,
GinkgoWriter,
GinkgoWriter,
)
Expect(err).NotTo(HaveOccurred())
Eventually(session).Should(gexec.Exit(0))
var response out.Response
err = json.Unmarshal(session.Out.Contents(), &response)
Expect(err).NotTo(HaveOccurred())
Expect(response.Version.Timestamp).To(BeTemporally("~", time.Now(), time.Second))
// shim outputs arguments
Expect(session.Err).To(gbytes.Say("cf api https://api.run.pivotal.io --skip-ssl-validation"))
Expect(session.Err).To(gbytes.Say("cf auth [email protected] hunter2"))
Expect(session.Err).To(gbytes.Say("cf target -o org -s space"))
Expect(session.Err).To(gbytes.Say("cf rename awesome-app awesome-app-venerable"))
Expect(session.Err).To(gbytes.Say("cf push awesome-app -f %s",
filepath.Join(tmpDir, "project/manifest.yml"),
))
Expect(session.Err).To(gbytes.Say(filepath.Join(tmpDir, "another-project")))
Expect(session.Err).To(gbytes.Say("cf delete -f awesome-app-venerable"))
// color should be always
output := string(session.Err.Contents())
Expect(strings.Count(output, "CF_COLOR=true")).To(Equal(7))
Expect(strings.Count(output, "CF_TRACE=true")).To(Equal(7))
})
})
Context("when specifying vars", func() {
BeforeEach(func() {
request.Params.Vars = map[string]interface{}{"foo": "bar"}
request.Params.VarsFiles = []string{"vars.yml"}
})
It("pushes an application to cloud foundry", func() {
session, err := gexec.Start(
cmd,
GinkgoWriter,
GinkgoWriter,
)
Expect(err).NotTo(HaveOccurred())
Eventually(session).Should(gexec.Exit(0))
var response out.Response
err = json.Unmarshal(session.Out.Contents(), &response)
Expect(err).NotTo(HaveOccurred())
Expect(response.Version.Timestamp).To(BeTemporally("~", time.Now(), time.Second))
// shim outputs arguments
Expect(session.Err).To(gbytes.Say("cf api https://api.run.pivotal.io --skip-ssl-validation"))
Expect(session.Err).To(gbytes.Say("cf auth [email protected] hunter2"))
Expect(session.Err).To(gbytes.Say("cf target -o org -s space"))
Expect(session.Err).To(gbytes.Say("cf rename awesome-app awesome-app-venerable"))
Expect(session.Err).To(gbytes.Say("cf push awesome-app -f %s --var foo=bar --vars-file vars.yml",
filepath.Join(tmpDir, "project/manifest.yml"),
))
Expect(session.Err).To(gbytes.Say(filepath.Join(tmpDir, "another-project")))
Expect(session.Err).To(gbytes.Say("cf delete -f awesome-app-venerable"))
// color should be always
output := string(session.Err.Contents())
Expect(strings.Count(output, "CF_COLOR=true")).To(Equal(7))
Expect(strings.Count(output, "CF_TRACE=true")).To(Equal(7))
})
})
Context("when my manifest and file paths contain a glob", func() {
var tmpFileManifest *os.File
var tmpFileSearch *os.File
BeforeEach(func() {
var err error
tmpFileManifest, err = ioutil.TempFile(tmpDir, "manifest-some-glob.yml_")
Expect(err).NotTo(HaveOccurred())
tmpFileSearch, err = ioutil.TempFile(tmpDir, "another-path.jar_")
Expect(err).NotTo(HaveOccurred())
request.Params.ManifestPath = "manifest-*.yml_*"
request.Params.Path = "another-path.jar*"
})
Context("when one file matches", func() {
It("pushes an application to cloud foundry", func() {
session, err := gexec.Start(
cmd,
GinkgoWriter,
GinkgoWriter,
)
Expect(err).NotTo(HaveOccurred())
Eventually(session).Should(gexec.Exit(0))
var response out.Response
err = json.Unmarshal(session.Out.Contents(), &response)
Expect(err).NotTo(HaveOccurred())
Expect(response.Version.Timestamp).To(BeTemporally("~", time.Now(), time.Second))
// shim outputs arguments
Expect(session.Err).To(gbytes.Say("cf api https://api.run.pivotal.io --skip-ssl-validation"))
Expect(session.Err).To(gbytes.Say("cf auth [email protected] hunter2"))
Expect(session.Err).To(gbytes.Say("cf target -o org -s space"))
Expect(session.Err).To(gbytes.Say("cf rename awesome-app awesome-app-venerable"))
Expect(session.Err).To(gbytes.Say("cf push awesome-app -f %s -p %s",
tmpFileManifest.Name(),
tmpFileSearch.Name(),
))
Expect(session.Err).To(gbytes.Say("cf delete -f awesome-app-venerable"))
// color should be always
Eventually(session.Err).Should(gbytes.Say("CF_COLOR=true"))
})
})
Context("when no files match the manifest path", func() {
BeforeEach(func() {
request.Params.ManifestPath = "nope-*"
})
It("returns an error", func() {
session, err := gexec.Start(
cmd,
GinkgoWriter,
GinkgoWriter,
)
Expect(err).NotTo(HaveOccurred())
Eventually(session).Should(gexec.Exit(1))
errMsg := fmt.Sprintf("error invalid manifest path: found 0 files instead of 1 at path: %s", filepath.Join(tmpDir, `nope-\*`))
Expect(session.Err).To(gbytes.Say(errMsg))
})
})
Context("when more then one file matches the manifest path", func() {
BeforeEach(func() {
_, err := ioutil.TempFile(tmpDir, "manifest-some-glob.yml_")
Expect(err).NotTo(HaveOccurred())
})
It("returns an error", func() {
session, err := gexec.Start(
cmd,
GinkgoWriter,
GinkgoWriter,
)
Expect(err).NotTo(HaveOccurred())
Eventually(session).Should(gexec.Exit(1))
errMsg := fmt.Sprintf("error invalid manifest path: found 2 files instead of 1 at path: %s", filepath.Join(tmpDir, `manifest-\*.yml_\*`))
Expect(session.Err).To(gbytes.Say(errMsg))
})
})
Context("when no files match the path", func() {
BeforeEach(func() {
request.Params.Path = "nope-*"
})
It("returns an error", func() {
session, err := gexec.Start(
cmd,
GinkgoWriter,
GinkgoWriter,
)
Expect(err).NotTo(HaveOccurred())
Eventually(session).Should(gexec.Exit(1))
errMsg := fmt.Sprintf("error invalid path: found 0 files instead of 1 at path: %s", filepath.Join(tmpDir, `nope-\*`))
Expect(session.Err).To(gbytes.Say(errMsg))
})
})
Context("when more then one file matches the manifest path", func() {
BeforeEach(func() {
_, err := ioutil.TempFile(tmpDir, "another-path.jar_")
Expect(err).NotTo(HaveOccurred())
})
It("returns an error", func() {
session, err := gexec.Start(
cmd,
GinkgoWriter,
GinkgoWriter,
)
Expect(err).NotTo(HaveOccurred())
Eventually(session).Should(gexec.Exit(1))
errMsg := fmt.Sprintf("error invalid path: found 2 files instead of 1 at path: %s", filepath.Join(tmpDir, `another-path.jar\*`))
Expect(session.Err).To(gbytes.Say(errMsg))
})
})
})
Context("when accessing a protected docker registry", func() {
BeforeEach(func() {
request.Params.DockerUsername = "DOCKER_USERNAME"
request.Params.DockerPassword = "DOCKER_PASSWORD"
})
It("pushes an application to cloud foundry", func() {
session, err := gexec.Start(
cmd,
GinkgoWriter,
GinkgoWriter,
)
Expect(err).NotTo(HaveOccurred())
Eventually(session).Should(gexec.Exit(0))
var response out.Response
err = json.Unmarshal(session.Out.Contents(), &response)
Expect(err).NotTo(HaveOccurred())
Expect(response.Version.Timestamp).To(BeTemporally("~", time.Now(), time.Second))
// shim outputs arguments
Expect(session.Err).To(gbytes.Say("cf api https://api.run.pivotal.io --skip-ssl-validation"))
Expect(session.Err).To(gbytes.Say("cf auth [email protected] hunter2"))
Expect(session.Err).To(gbytes.Say("cf target -o org -s space"))
Expect(session.Err).To(gbytes.Say("cf rename awesome-app awesome-app-venerable"))
Expect(session.Err).To(gbytes.Say("cf push awesome-app -f %s --docker-username %s",
filepath.Join(tmpDir, "project/manifest.yml"),
request.Params.DockerUsername,
))
Expect(session.Err).To(gbytes.Say("cf delete -f awesome-app-venerable"))
Expect(session.Err).To(gbytes.Say("CF_DOCKER_PASSWORD=DOCKER_PASSWORD"))
})
})
Context("when doing an ordinary cf push", func() {
BeforeEach(func() {
request.Params.CurrentAppName = ""
})
Context("when no_start is not specified", func() {
It("pushes an application to cloud foundry", func() {
session, err := gexec.Start(
cmd,
GinkgoWriter,
GinkgoWriter,
)
Expect(err).NotTo(HaveOccurred())
Eventually(session).Should(gexec.Exit(0))
var response out.Response
err = json.Unmarshal(session.Out.Contents(), &response)
Expect(err).NotTo(HaveOccurred())
Expect(response.Version.Timestamp).To(BeTemporally("~", time.Now(), time.Second))
// shim outputs arguments
Expect(session.Err).To(gbytes.Say("cf api https://api.run.pivotal.io --skip-ssl-validation"))
Expect(session.Err).To(gbytes.Say("cf auth [email protected] hunter2"))
Expect(session.Err).To(gbytes.Say("cf target -o org -s space"))
Expect(session.Err).To(gbytes.Say("cf push -f %s -p .",
filepath.Join(tmpDir, "project/manifest.yml"),
))
Expect(session.Err).To(gbytes.Say(filepath.Join(tmpDir, "another-project")))
// color should be always
output := string(session.Err.Contents())
Expect(strings.Count(output, "CF_COLOR=true")).To(Equal(4))
Expect(strings.Count(output, "CF_TRACE=true")).To(Equal(4))
})
})
Context("when no_start is specified", func() {
BeforeEach(func() {
request.Params.NoStart = true
})
It("pushes an application to cloud foundry with --no-start", func() {
session, err := gexec.Start(
cmd,
GinkgoWriter,
GinkgoWriter,
)
Expect(err).NotTo(HaveOccurred())
Eventually(session).Should(gexec.Exit(0))
var response out.Response
err = json.Unmarshal(session.Out.Contents(), &response)
Expect(err).NotTo(HaveOccurred())
Expect(response.Version.Timestamp).To(BeTemporally("~", time.Now(), time.Second))
// shim outputs arguments
Expect(session.Err).To(gbytes.Say("cf api https://api.run.pivotal.io --skip-ssl-validation"))
Expect(session.Err).To(gbytes.Say("cf auth [email protected] hunter2"))
Expect(session.Err).To(gbytes.Say("cf target -o org -s space"))
Expect(session.Err).To(gbytes.Say("cf push -f %s --no-start",
filepath.Join(tmpDir, "project/manifest.yml"),
))
Expect(session.Err).To(gbytes.Say(filepath.Join(tmpDir, "another-project")))
// color should be always
output := string(session.Err.Contents())
Expect(strings.Count(output, "CF_COLOR=true")).To(Equal(4))
Expect(strings.Count(output, "CF_TRACE=true")).To(Equal(4))
})
})
})
})