-
Notifications
You must be signed in to change notification settings - Fork 180
/
manager_test.go
653 lines (547 loc) · 20.9 KB
/
manager_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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
package bosh_test
import (
"errors"
"io/ioutil"
"os"
"github.com/cloudfoundry/bosh-bootloader/bosh"
"github.com/cloudfoundry/bosh-bootloader/fakes"
"github.com/cloudfoundry/bosh-bootloader/storage"
"github.com/cloudfoundry/bosh-bootloader/terraform"
"github.com/pivotal-cf-experimental/gomegamatchers"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Manager", func() {
var (
boshExecutor *fakes.BOSHExecutor
logger *fakes.Logger
stateStore *fakes.StateStore
sshKeyGetter *fakes.SSHKeyGetter
fs *fakes.FileIO
boshCLIProvider *fakes.BOSHCLIProvider
boshCLI *fakes.BOSHCLI
boshManager *bosh.Manager
terraformOutputs terraform.Outputs
boshVars string
osUnsetenvKey string
osSetenvKey string
osSetenvValue string
)
BeforeEach(func() {
boshExecutor = &fakes.BOSHExecutor{}
logger = &fakes.Logger{}
sshKeyGetter = &fakes.SSHKeyGetter{}
sshKeyGetter.GetCall.Returns.PrivateKey = "some-jumpbox-private-key"
fs = &fakes.FileIO{}
boshCLIProvider = &fakes.BOSHCLIProvider{}
stateStore = &fakes.StateStore{}
stateStore.GetVarsDirCall.Returns.Directory = "some-bbl-vars-dir"
stateStore.GetStateDirCall.Returns.Directory = "some-state-dir"
stateStore.GetDirectorDeploymentDirCall.Returns.Directory = "some-director-deployment-dir"
stateStore.GetJumpboxDeploymentDirCall.Returns.Directory = "some-jumpbox-deployment-dir"
boshManager = bosh.NewManager(boshExecutor, logger, stateStore, sshKeyGetter, fs, boshCLIProvider)
boshVars = `admin_password: some-admin-password
director_ssl:
ca: some-ca
certificate: some-certificate
private_key: some-private-key
`
bosh.SetOSSetenv(func(key, value string) error {
osSetenvKey = key
osSetenvValue = value
return nil
})
bosh.SetOSUnsetenv(func(key string) error {
osUnsetenvKey = key
return nil
})
})
AfterEach(func() {
bosh.ResetOSSetenv()
})
Describe("Director set-up", func() {
var state storage.State
BeforeEach(func() {
state = storage.State{
IAAS: "gcp",
EnvID: "some-env-id",
GCP: storage.GCP{
Zone: "some-zone",
ProjectID: "some-project-id",
ServiceAccountKey: "some-credential-json",
},
BOSH: storage.BOSH{
State: map[string]interface{}{
"some-key": "some-value",
},
},
}
boshExecutor.CreateEnvCall.Returns.Variables = boshVars
})
Describe("InitializeDirector", func() {
It("Calls PlanDirector", func() {
err := boshManager.InitializeDirector(state)
Expect(err).NotTo(HaveOccurred())
Expect(boshExecutor.PlanDirectorCall.Receives.DirInput.VarsDir).To(Equal("some-bbl-vars-dir"))
Expect(boshExecutor.PlanDirectorCall.Receives.DirInput.StateDir).To(Equal("some-state-dir"))
Expect(boshExecutor.PlanDirectorCall.Receives.DeploymentDir).To(Equal("some-director-deployment-dir"))
Expect(boshExecutor.PlanJumpboxCall.CallCount).To(Equal(0))
Expect(boshExecutor.CreateEnvCall.CallCount).To(Equal(0))
})
Context("when create env args fails", func() {
BeforeEach(func() {
boshExecutor.PlanDirectorCall.Returns.Error = errors.New("failed to interpolate")
})
It("returns an error", func() {
err := boshManager.InitializeDirector(storage.State{})
Expect(err).To(MatchError("failed to interpolate"))
})
})
Context("when get vars dir fails", func() {
It("returns an error", func() {
stateStore.GetVarsDirCall.Returns.Error = errors.New("pineapple")
err := boshManager.InitializeDirector(storage.State{})
Expect(err).To(MatchError("pineapple"))
})
})
Context("when get deployment dir fails", func() {
It("returns an error", func() {
stateStore.GetDirectorDeploymentDirCall.Returns.Error = errors.New("pineapple")
err := boshManager.InitializeDirector(storage.State{})
Expect(err).To(MatchError("pineapple"))
})
})
})
Describe("CreateDirector", func() {
BeforeEach(func() {
terraformOutputs = terraform.Outputs{Map: map[string]interface{}{
"internal_cidr": "10.2.0.0/24",
"some-key": "some-value",
"tags": []interface{}{"some-tag", "some-other-tag"},
}}
})
It("calls create env on the bosh executor with the expected arguments", func() {
stateWithDirector, err := boshManager.CreateDirector(state, terraformOutputs)
Expect(err).NotTo(HaveOccurred())
Expect(logger.StepCall.Messages).To(gomegamatchers.ContainSequence([]string{"creating bosh director", "created bosh director"}))
Expect(boshExecutor.CreateEnvCall.CallCount).To(Equal(1))
Expect(boshExecutor.CreateEnvCall.Receives.DirInput.Deployment).To(Equal("director"))
Expect(boshExecutor.CreateEnvCall.Receives.DirInput.VarsDir).To(Equal("some-bbl-vars-dir"))
Expect(boshExecutor.CreateEnvCall.Receives.DirInput.StateDir).To(Equal("some-state-dir"))
Expect(stateWithDirector.BOSH).To(Equal(storage.BOSH{
DirectorName: "bosh-some-env-id",
DirectorAddress: "https://10.2.0.6:25555",
DirectorUsername: "admin",
DirectorPassword: "some-admin-password",
DirectorSSLCA: "some-ca",
DirectorSSLCertificate: "some-certificate",
DirectorSSLPrivateKey: "some-private-key",
State: nil,
}))
})
Context("when an error occurs", func() {
Context("when get vars dir fails", func() {
It("returns an error", func() {
stateStore.GetVarsDirCall.Returns.Error = errors.New("pineapple")
_, err := boshManager.CreateDirector(storage.State{}, terraformOutputs)
Expect(err).To(MatchError("pineapple"))
})
})
Context("when the executor's create env call fails", func() {
BeforeEach(func() {
boshExecutor.CreateEnvCall.Returns.Error = errors.New("lychee")
})
It("returns an error", func() {
_, err := boshManager.CreateDirector(storage.State{}, terraformOutputs)
Expect(err).To(BeAssignableToTypeOf(bosh.ManagerCreateError{}))
Expect(err).To(MatchError("lychee"))
})
})
})
})
})
Describe("Jumpbox set-up", func() {
var (
state storage.State
)
BeforeEach(func() {
terraformOutputs = terraform.Outputs{Map: map[string]interface{}{
"internal_cidr": "10.0.0.0/24",
"some-key": "some-value",
"jumpbox_url": "some-jumpbox-url:22",
}}
state = storage.State{
IAAS: "gcp",
EnvID: "some-env-id",
GCP: storage.GCP{
Zone: "some-zone",
ProjectID: "some-project-id",
ServiceAccountKey: "some-credential-json",
},
Jumpbox: storage.Jumpbox{
Manifest: "name: jumpbox",
State: map[string]interface{}{
"some-key": "some-value",
},
},
}
boshExecutor.CreateEnvCall.Returns.Variables = "jumpbox_ssh:\n private_key: some-jumpbox-private-key"
fs.TempDirCall.Returns.Name = "/fake/file/bosh-jumpbox"
})
AfterEach(func() {
bosh.ResetOSSetenv()
})
Describe("InitializeJumpbox", func() {
It("calls PlanJumpboxCall appropriately", func() {
err := boshManager.InitializeJumpbox(state)
Expect(err).NotTo(HaveOccurred())
Expect(boshExecutor.PlanJumpboxCall.Receives.DeploymentDir).To(Equal("some-jumpbox-deployment-dir"))
Expect(boshExecutor.PlanJumpboxCall.Receives.DirInput.VarsDir).To(Equal("some-bbl-vars-dir"))
Expect(boshExecutor.PlanJumpboxCall.Receives.DirInput.StateDir).To(Equal("some-state-dir"))
})
Context("when an error occurs", func() {
Context("when get vars dir fails", func() {
It("returns an error", func() {
stateStore.GetVarsDirCall.Returns.Error = errors.New("kiwi")
err := boshManager.InitializeJumpbox(state)
Expect(err).To(MatchError("kiwi"))
})
})
Context("when get deployment dir fails", func() {
It("returns an error", func() {
stateStore.GetJumpboxDeploymentDirCall.Returns.Error = errors.New("kiwi")
err := boshManager.InitializeJumpbox(state)
Expect(err).To(MatchError("kiwi"))
})
})
})
})
Describe("CreateJumpbox", func() {
It("sets BOSH_ALL_PROXY to start an ssh tunnel and socks5 proxy to create the director", func() {
_, err := boshManager.CreateJumpbox(state, terraformOutputs)
Expect(err).NotTo(HaveOccurred())
Expect(osUnsetenvKey).To(Equal("BOSH_ALL_PROXY"))
Expect(osSetenvKey).To(Equal("BOSH_ALL_PROXY"))
Expect(osSetenvValue).To(Equal("ssh+socks5://jumpbox@some-jumpbox-url:22?private-key=/fake/file/bosh-jumpbox/bosh_jumpbox_private.key"))
Expect(logger.StepCall.Messages).To(gomegamatchers.ContainSequence([]string{
"creating jumpbox",
"created jumpbox",
}))
})
It("returns a bbl state with bosh and jumpbox deployment values", func() {
state, err := boshManager.CreateJumpbox(state, terraformOutputs)
Expect(err).NotTo(HaveOccurred())
Expect(boshExecutor.CreateEnvCall.Receives.DirInput.VarsDir).To(Equal("some-bbl-vars-dir"))
Expect(boshExecutor.CreateEnvCall.Receives.DirInput.StateDir).To(Equal("some-state-dir"))
Expect(boshExecutor.CreateEnvCall.Receives.DirInput.Deployment).To(Equal("jumpbox"))
Expect(state).To(Equal(storage.State{
IAAS: "gcp",
EnvID: "some-env-id",
GCP: storage.GCP{
Zone: "some-zone",
ProjectID: "some-project-id",
ServiceAccountKey: "some-credential-json",
},
Jumpbox: storage.Jumpbox{
URL: "some-jumpbox-url:22",
State: nil,
},
}))
})
Context("when an error occurs", func() {
Context("when geting the jumpbox key fails", func() {
BeforeEach(func() {
sshKeyGetter.GetCall.Returns.Error = errors.New("soursop")
})
It("returns an error", func() {
_, err := boshManager.CreateJumpbox(state, terraformOutputs)
Expect(err).To(MatchError("Get jumpbox private key: soursop"))
})
})
Context("when get vars dir fails", func() {
It("returns an error", func() {
stateStore.GetVarsDirCall.Returns.Error = errors.New("kiwi")
_, err := boshManager.CreateJumpbox(state, terraformOutputs)
Expect(err).To(MatchError("kiwi"))
})
})
Context("when create env returns an error", func() {
It("returns a ManagerCreateError", func() {
boshExecutor.CreateEnvCall.Returns.Error = errors.New("banana")
_, err := boshManager.CreateJumpbox(state, terraformOutputs)
Expect(err).To(BeAssignableToTypeOf(bosh.ManagerCreateError{}))
Expect(err).To(MatchError("banana"))
})
})
Context("when creating a temp directory fails", func() {
BeforeEach(func() {
fs.TempDirCall.Returns.Error = errors.New("fig")
})
It("returns a helpful error", func() {
_, err := boshManager.CreateJumpbox(state, terraformOutputs)
Expect(err).To(MatchError("Create temp dir for jumpbox private key: fig"))
})
})
Context("when writing the jumpbox private key fails", func() {
BeforeEach(func() {
fs.WriteFileCall.Returns = []fakes.WriteFileReturn{{errors.New("starfruit")}}
})
It("returns a helpful error", func() {
_, err := boshManager.CreateJumpbox(state, terraformOutputs)
Expect(err).To(MatchError("Write jumpbox private key: starfruit"))
})
})
})
})
})
Describe("CleanUpDirector", func() {
BeforeEach(func() {
boshCLI = &fakes.BOSHCLI{}
boshCLIProvider.AuthenticatedCLICall.Returns.AuthenticatedCLI = boshCLI
boshCLIProvider.AuthenticatedCLICall.Returns.Error = nil
})
It("authenticates the CLI", func() {
state := storage.State{
Jumpbox: storage.Jumpbox{
URL: "some-jumpbox-url:22",
},
BOSH: storage.BOSH{
DirectorAddress: "director-address",
DirectorUsername: "director-username",
DirectorPassword: "director-password",
DirectorSSLCA: "ca-cert",
},
}
err := boshManager.CleanUpDirector(state)
Expect(err).NotTo(HaveOccurred())
Expect(boshCLIProvider.AuthenticatedCLICall.CallCount).To(Equal(1))
Expect(boshCLIProvider.AuthenticatedCLICall.Receives.Jumpbox).To(Equal(state.Jumpbox))
Expect(boshCLIProvider.AuthenticatedCLICall.Receives.Stderr).To(Equal(os.Stderr))
Expect(boshCLIProvider.AuthenticatedCLICall.Receives.DirectorAddress).To(Equal(state.BOSH.DirectorAddress))
Expect(boshCLIProvider.AuthenticatedCLICall.Receives.DirectorUsername).To(Equal(state.BOSH.DirectorUsername))
Expect(boshCLIProvider.AuthenticatedCLICall.Receives.DirectorPassword).To(Equal(state.BOSH.DirectorPassword))
Expect(boshCLIProvider.AuthenticatedCLICall.Receives.DirectorCACert).To(Equal(state.BOSH.DirectorSSLCA))
})
It("runs bosh clean-up --all", func() {
err := boshManager.CleanUpDirector(storage.State{})
Expect(err).NotTo(HaveOccurred())
Expect(boshCLI.RunCall.CallCount).To(Equal(1))
Expect(boshCLI.RunCall.Receives.Args).To(Equal([]string{"clean-up", "--all"}))
})
Context("when an error occurs", func() {
Context("authenticating the cli", func() {
It("returns an error", func() {
boshCLIProvider.AuthenticatedCLICall.Returns.Error = errors.New("failed to authenticate cli")
err := boshManager.CleanUpDirector(storage.State{})
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError("failed to authenticate cli"))
Expect(boshCLIProvider.AuthenticatedCLICall.CallCount).To(Equal(1))
})
})
Context("running bosh clean-up --all", func() {
It("returns an error", func() {
boshCLI.RunCall.Returns.Error = errors.New("failed to run bosh clean-up")
err := boshManager.CleanUpDirector(storage.State{})
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError("failed to run bosh clean-up"))
Expect(boshCLI.RunCall.CallCount).To(Equal(1))
})
})
})
})
Describe("DeleteJumpbox", func() {
var (
incomingState storage.State
jumpboxState map[string]interface{}
)
BeforeEach(func() {
jumpboxState = map[string]interface{}{
"key": "value",
}
incomingState = storage.State{
IAAS: "some-iaas",
BOSH: storage.BOSH{
Variables: "some-bosh-vars",
},
Jumpbox: storage.Jumpbox{
Manifest: "some-manifest",
State: jumpboxState,
},
}
})
It("calls delete env", func() {
err := boshManager.DeleteJumpbox(incomingState, terraform.Outputs{Map: map[string]interface{}{
"some-key": "some-value",
}})
Expect(err).NotTo(HaveOccurred())
Expect(boshExecutor.WriteDeploymentVarsCall.Receives.DirInput.Deployment).To(Equal("jumpbox"))
Expect(boshExecutor.WriteDeploymentVarsCall.Receives.DirInput.StateDir).To(Equal("some-state-dir"))
Expect(boshExecutor.WriteDeploymentVarsCall.Receives.DirInput.VarsDir).To(Equal("some-bbl-vars-dir"))
Expect(boshExecutor.WriteDeploymentVarsCall.Receives.DeploymentVars).To(MatchYAML("some-key: some-value"))
Expect(boshExecutor.DeleteEnvCall.Receives.DirInput.Deployment).To(Equal("jumpbox"))
Expect(boshExecutor.DeleteEnvCall.Receives.DirInput.VarsDir).To(Equal("some-bbl-vars-dir"))
Expect(boshExecutor.DeleteEnvCall.Receives.DirInput.StateDir).To(Equal("some-state-dir"))
})
Context("when the executor's delete env call fails with delete env error", func() {
var expectedError bosh.ManagerDeleteError
BeforeEach(func() {
deleteEnvError := errors.New("failed to delete env")
boshExecutor.DeleteEnvCall.Returns.Error = deleteEnvError
expectedError = bosh.NewManagerDeleteError(incomingState, deleteEnvError)
})
It("returns a bosh manager delete error with a valid state", func() {
err := boshManager.DeleteJumpbox(incomingState, terraform.Outputs{})
Expect(err).To(MatchError(expectedError))
})
})
})
Describe("DeleteDirector", func() {
var varsDir string
BeforeEach(func() {
var err error
varsDir, err = ioutil.TempDir("", "")
Expect(err).NotTo(HaveOccurred())
stateStore.GetVarsDirCall.Returns.Directory = varsDir
fs.TempDirCall.Returns.Name = "/fake/file/bosh-jumpbox"
})
It("calls delete env", func() {
err := boshManager.DeleteDirector(storage.State{
Jumpbox: storage.Jumpbox{
URL: "some-jumpbox-url:22",
},
BOSH: storage.BOSH{
Manifest: "some-manifest",
State: map[string]interface{}{
"key": "value",
},
Variables: boshVars,
},
}, terraform.Outputs{Map: map[string]interface{}{"some-key": "some-value"}})
Expect(err).NotTo(HaveOccurred())
Expect(boshExecutor.WriteDeploymentVarsCall.Receives.DirInput.Deployment).To(Equal("director"))
Expect(boshExecutor.WriteDeploymentVarsCall.Receives.DirInput.StateDir).To(Equal("some-state-dir"))
Expect(boshExecutor.WriteDeploymentVarsCall.Receives.DirInput.VarsDir).To(Equal(varsDir))
Expect(boshExecutor.WriteDeploymentVarsCall.Receives.DeploymentVars).To(MatchYAML("some-key: some-value"))
Expect(osSetenvKey).To(Equal("BOSH_ALL_PROXY"))
Expect(osSetenvValue).To(Equal("ssh+socks5://jumpbox@some-jumpbox-url:22?private-key=/fake/file/bosh-jumpbox/bosh_jumpbox_private.key"))
Expect(boshExecutor.DeleteEnvCall.Receives.DirInput).To(Equal(bosh.DirInput{
Deployment: "director",
StateDir: "some-state-dir",
VarsDir: varsDir,
}))
})
Context("when an error occurs", func() {
var state storage.State
BeforeEach(func() {
state = storage.State{
BOSH: storage.BOSH{
Manifest: "some-manifest",
State: map[string]interface{}{
"key": "value",
},
},
Jumpbox: storage.Jumpbox{},
}
})
Context("when getting the jumpbox key fails", func() {
BeforeEach(func() {
sshKeyGetter.GetCall.Returns.Error = errors.New("rambutan")
})
It("returns an error", func() {
err := boshManager.DeleteDirector(state, terraform.Outputs{})
Expect(err).To(MatchError("Get jumpbox private key: rambutan"))
})
})
Context("when creating a temp directory fails", func() {
BeforeEach(func() {
fs.TempDirCall.Returns.Error = errors.New("fig")
})
It("returns a helpful error", func() {
err := boshManager.DeleteDirector(state, terraformOutputs)
Expect(err).To(MatchError("Create temp dir for jumpbox private key: fig"))
})
})
Context("when writing the jumpbox private key fails", func() {
BeforeEach(func() {
fs.WriteFileCall.Returns = []fakes.WriteFileReturn{{errors.New("starfruit")}}
})
It("returns a helpful error", func() {
err := boshManager.DeleteDirector(state, terraformOutputs)
Expect(err).To(MatchError("Write jumpbox private key: starfruit"))
})
})
Context("when the executor's delete env call fails with delete env error", func() {
It("returns a bosh manager delete error", func() {
deleteEnvError := errors.New("Run bosh delete-env director: some error")
boshExecutor.DeleteEnvCall.Returns.Error = deleteEnvError
expectedError := bosh.NewManagerDeleteError(state, deleteEnvError)
err := boshManager.DeleteDirector(state, terraform.Outputs{})
Expect(err).To(MatchError(expectedError))
})
})
})
})
Describe("GetJumpboxDeploymentVars", func() {
It("removes the jumpbox__ prefix from variable names", func() {
vars := boshManager.GetJumpboxDeploymentVars(storage.State{}, terraform.Outputs{Map: map[string]interface{}{
"some-key": "some-value",
"director__key": "some-director-value",
"jumpbox__key": "some-jumpbox-value",
"key": "some-ignored-value",
}})
Expect(vars).To(MatchYAML(`---
some-key: some-value
key: some-jumpbox-value
`))
})
})
Describe("GetDirectorDeploymentVars", func() {
It("removes the director__ prefix from variable names", func() {
vars := boshManager.GetDirectorDeploymentVars(storage.State{}, terraform.Outputs{Map: map[string]interface{}{
"some-key": "some-value",
"director__key": "some-director-value",
"jumpbox__key": "some-jumpbox-value",
"key": "some-ignored-value",
}})
Expect(vars).To(MatchYAML(`---
some-key: some-value
key: some-director-value
`))
})
})
Describe("Version", func() {
BeforeEach(func() {
boshExecutor.VersionCall.Returns.Version = "1.1.1"
})
It("calls out to bosh executor version", func() {
version, err := boshManager.Version()
Expect(err).NotTo(HaveOccurred())
Expect(boshExecutor.VersionCall.CallCount).To(Equal(1))
Expect(version).To(Equal("1.1.1"))
})
Context("when executor returns a bosh version error", func() {
var expectedError bosh.BOSHVersionError
BeforeEach(func() {
boshExecutor.VersionCall.Returns.Version = ""
expectedError = bosh.NewBOSHVersionError(errors.New("BOSH version could not be parsed"))
boshExecutor.VersionCall.Returns.Error = expectedError
})
It("logs a warning and returns the error", func() {
version, err := boshManager.Version()
Expect(boshExecutor.VersionCall.CallCount).To(Equal(1))
Expect(logger.PrintlnCall.CallCount).To(Equal(1))
Expect(err).To(Equal(expectedError))
Expect(version).To(Equal(""))
})
})
Context("when executor fails", func() {
BeforeEach(func() {
boshExecutor.VersionCall.Returns.Error = errors.New("failed to execute")
})
It("returns an error", func() {
_, err := boshManager.Version()
Expect(err).To(MatchError("failed to execute"))
})
})
})
})