-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathmain_test.go
708 lines (618 loc) · 22.9 KB
/
main_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
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
package main_test
import (
"errors"
"fmt"
"code.cloudfoundry.org/cli/plugin"
"code.cloudfoundry.org/cli/plugin/models"
"code.cloudfoundry.org/cli/plugin/pluginfakes"
. "github.com/bluemixgaragelondon/cf-blue-green-deploy"
"github.com/bluemixgaragelondon/cf-blue-green-deploy/manifest"
"github.com/bluemixgaragelondon/cf-blue-green-deploy/manifest/fakes"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"strings"
)
var _ = Describe("BGD Plugin", func() {
Describe("blue green flow", func() {
Context("when there is a previous live app", func() {
It("calls methods in correct order", func() {
b := &BlueGreenDeployFake{liveApp: &plugin_models.GetAppModel{Name: "app-name-live"}, appSshEnabled: false}
p := CfPlugin{
Deployer: b,
}
p.Deploy(manifest.CfDomains{DefaultDomain: "example.com"}, &fakes.FakeManifestReader{}, NewArgs([]string{"bgd", "app-name"}))
Expect(b.flow).To(Equal([]string{
"delete old apps",
"get current live app",
"push app-name-new",
"check ssh enablement for 'app-name'",
"set ssh enablement for 'app-name-new' to 'false'",
"unmap 1 routes from app-name-new",
"delete 1 routes",
"mapped 1 routes",
"rename app-name-live to app-name-old",
"rename app-name-new to app-name",
"unmap 0 routes from app-name-old",
}))
})
Context("and we want to delete the old app instances", func() {
It("calls 'delete old apps'", func() {
b := &BlueGreenDeployFake{liveApp: &plugin_models.GetAppModel{Name: "app-name-live"}, appSshEnabled: false}
p := CfPlugin{
Deployer: b,
}
p.Deploy(manifest.CfDomains{DefaultDomain: "example.com"}, &fakes.FakeManifestReader{}, NewArgs([]string{"bgd", "app-name", "--delete-old-apps"}))
Expect(b.flow).To(Equal([]string{
"delete old apps",
"get current live app",
"push app-name-new",
"check ssh enablement for 'app-name'",
"set ssh enablement for 'app-name-new' to 'false'",
"unmap 1 routes from app-name-new",
"delete 1 routes",
"mapped 1 routes",
"rename app-name-live to app-name-old",
"rename app-name-new to app-name",
"unmap 0 routes from app-name-old",
"delete old apps except failed ones",
}))
})
})
Context("with an existing live route", func() {
It("maps the live app routes to the new app", func() {
liveAppRoutes := []plugin_models.GetApp_RouteSummary{
{Host: "host1", Domain: plugin_models.GetApp_DomainFields{Name: "example.com"}},
{Host: "host2", Domain: plugin_models.GetApp_DomainFields{Name: "example.com"}},
}
b := &BlueGreenDeployFake{
liveApp: &plugin_models.GetAppModel{Name: "app-name-live",
Routes: liveAppRoutes},
}
p := CfPlugin{
Deployer: b,
}
p.Deploy(manifest.CfDomains{DefaultDomain: "example.com"}, &fakes.FakeManifestReader{}, NewArgs([]string{"bgd", "app-name"}))
deletedTempRoute := plugin_models.GetApp_RouteSummary{Host: "app-name-new", Domain: plugin_models.GetApp_DomainFields{Name: "example.com"}}
Expect(b.deletedRoutes).To(ConsistOf(deletedTempRoute))
Expect(b.mappedRoutes).To(ConsistOf(liveAppRoutes))
})
})
Context("with an existing live route and manifest", func() {
It("maps both manifest & live app routes", func() {
liveAppRoutes := []plugin_models.GetApp_RouteSummary{
{Host: "host1", Domain: plugin_models.GetApp_DomainFields{Name: "example.com"}},
{Host: "host2", Domain: plugin_models.GetApp_DomainFields{Name: "example.com"}},
}
b := &BlueGreenDeployFake{
liveApp: &plugin_models.GetAppModel{Name: "app-name-live",
Routes: liveAppRoutes},
}
p := CfPlugin{
Deployer: b,
}
repo := &fakes.FakeManifestReader{Yaml: `---
name: app-name
hosts:
- man1
domains:
- example.com
`}
p.Deploy(manifest.CfDomains{DefaultDomain: "example.com"}, repo, NewArgs([]string{"bgd", "app-name"}))
expectedAppRoutes := append(liveAppRoutes, plugin_models.GetApp_RouteSummary{Host: "man1", Domain: plugin_models.GetApp_DomainFields{Name: "example.com"}})
Expect(b.mappedRoutes).To(ConsistOf(expectedAppRoutes))
})
It("maps unique routes", func() {
liveAppRoutes := []plugin_models.GetApp_RouteSummary{
{Host: "host1", Domain: plugin_models.GetApp_DomainFields{Name: "example.com"}},
{Host: "host2", Domain: plugin_models.GetApp_DomainFields{Name: "example.com"}},
}
b := &BlueGreenDeployFake{
liveApp: &plugin_models.GetAppModel{Name: "app-name-live",
Routes: liveAppRoutes},
}
p := CfPlugin{
Deployer: b,
}
repo := &fakes.FakeManifestReader{Yaml: `---
name: app-name
hosts:
- man1
- host1
- host2
domains:
- example.com
`}
p.Deploy(manifest.CfDomains{DefaultDomain: "example.com"}, repo, NewArgs([]string{"bgd", "app-name"}))
expectedAppRoutes := append(liveAppRoutes, plugin_models.GetApp_RouteSummary{Host: "man1", Domain: plugin_models.GetApp_DomainFields{Name: "example.com"}})
Expect(b.mappedRoutes).To(ConsistOf(expectedAppRoutes))
})
})
})
Context("when there is no previous live app", func() {
It("calls methods in correct order", func() {
b := &BlueGreenDeployFake{liveApp: nil}
p := CfPlugin{
Deployer: b,
}
p.Deploy(manifest.CfDomains{DefaultDomain: "example.com"}, &fakes.FakeManifestReader{}, NewArgs([]string{"bgd", "app-name"}))
Expect(b.flow).To(Equal([]string{
"delete old apps",
"get current live app",
"push app-name-new",
"unmap 1 routes from app-name-new",
"delete 1 routes",
"mapped 1 routes",
"rename app-name-new to app-name",
}))
})
})
Context("when app has manifest", func() {
Context("when manifest uses hosts and domains", func() {
It("maps manifest routes", func() {
b := &BlueGreenDeployFake{liveApp: nil}
p := CfPlugin{
Deployer: b,
}
repo := &fakes.FakeManifestReader{Yaml: `---
name: app-name
hosts:
- host1
- host2
domains:
- specific.com
- specific.net
`}
p.Deploy(manifest.CfDomains{DefaultDomain: "example.com"}, repo, NewArgs([]string{"bgd", "app-name"}))
Expect(b.flow).To(Equal([]string{
"delete old apps",
"get current live app",
"push app-name-new",
"unmap 1 routes from app-name-new",
"delete 1 routes",
"mapped 4 routes",
"rename app-name-new to app-name",
}))
deletedTempRoute := plugin_models.GetApp_RouteSummary{Host: "app-name-new", Domain: plugin_models.GetApp_DomainFields{Name: "specific.com"}}
Expect(b.deletedRoutes).To(ConsistOf(deletedTempRoute))
expectedRoutes := []plugin_models.GetApp_RouteSummary{
plugin_models.GetApp_RouteSummary{Host: "host1", Domain: plugin_models.GetApp_DomainFields{Name: "specific.com"}},
plugin_models.GetApp_RouteSummary{Host: "host2", Domain: plugin_models.GetApp_DomainFields{Name: "specific.com"}},
plugin_models.GetApp_RouteSummary{Host: "host1", Domain: plugin_models.GetApp_DomainFields{Name: "specific.net"}},
plugin_models.GetApp_RouteSummary{Host: "host2", Domain: plugin_models.GetApp_DomainFields{Name: "specific.net"}},
}
Expect(len(b.mappedRoutes)).To(Equal(4))
Expect(b.mappedRoutes).To(ConsistOf(expectedRoutes))
})
})
Context("when manifest uses routes", func() {
It("maps manifest routes", func() {
b := &BlueGreenDeployFake{liveApp: nil}
p := CfPlugin{
Deployer: b,
}
repo := &fakes.FakeManifestReader{Yaml: `---
name: app-name
routes:
- route: host1.something.com
- route: host2.mine.com
- route: host3.common.com
`}
p.Deploy(manifest.CfDomains{DefaultDomain: "example.com", SharedDomains: []string{"common.com"}, PrivateDomains: []string{"mine.com", "something.com"}}, repo, NewArgs([]string{"bgd", "app-name"}))
Expect(b.flow).To(Equal([]string{
"delete old apps",
"get current live app",
"push app-name-new",
"unmap 1 routes from app-name-new",
"delete 1 routes",
"mapped 3 routes",
"rename app-name-new to app-name",
}))
expectedRoutes := []plugin_models.GetApp_RouteSummary{
{Host: "host1", Domain: plugin_models.GetApp_DomainFields{Name: "something.com"}},
{Host: "host2", Domain: plugin_models.GetApp_DomainFields{Name: "mine.com"}},
{Host: "host3", Domain: plugin_models.GetApp_DomainFields{Name: "common.com"}},
}
Expect(b.mappedRoutes).To(ConsistOf(expectedRoutes))
})
})
Context("when scale parameters are defined", func() {
It("Uses the scale values", func() {
b := &BlueGreenDeployFake{liveApp: nil}
p := CfPlugin{
Deployer: b,
}
repo := &fakes.FakeManifestReader{Yaml: `---
name: app-name
memory: 16M
disk_quota: 500M
instances: 3
hosts:
- host1
`}
p.Deploy(manifest.CfDomains{DefaultDomain: "example.com"}, repo, NewArgs([]string{"bgd", "app-name"}))
Expect(b.flow).To(Equal([]string{
"delete old apps",
"get current live app",
"push app-name-new",
"unmap 1 routes from app-name-new",
"delete 1 routes",
"mapped 1 routes",
"rename app-name-new to app-name",
}))
scaleParameters := ScaleParameters{
Memory: int64(16),
DiskQuota: int64(500),
InstanceCount: 3,
}
Expect(*b.usedScale).To(Equal(scaleParameters))
})
})
Context("when no routes are specified in the manifest", func() {
It("maps the app name as the only route", func() {
b := &BlueGreenDeployFake{liveApp: nil}
p := CfPlugin{
Deployer: b,
}
repo := &fakes.FakeManifestReader{Yaml: `---
name: app-name
hosts:
- host1
`}
p.Deploy(manifest.CfDomains{DefaultDomain: "example.com"}, repo, NewArgs([]string{"bgd", "app-name"}))
Expect(b.mappedRoutes).To(Equal([]plugin_models.GetApp_RouteSummary{
{Host: "app-name", Domain: plugin_models.GetApp_DomainFields{Name: "example.com"}},
}))
})
})
})
Context("when there is a smoke test defined", func() {
Context("when it succeeds", func() {
var (
b *BlueGreenDeployFake
p CfPlugin
)
BeforeEach(func() {
b = &BlueGreenDeployFake{liveApp: nil, passSmokeTest: true}
p = CfPlugin{
Deployer: b,
}
})
It("calls methods in correct order", func() {
p.Deploy(manifest.CfDomains{DefaultDomain: "example.com"}, &fakes.FakeManifestReader{}, NewArgs([]string{"bgd", "app-name", "--smoke-test", "script/smoke-test"}))
Expect(b.flow).To(Equal([]string{
"delete old apps",
"get current live app",
"push app-name-new",
"script/smoke-test app-name-new.example.com",
"unmap 1 routes from app-name-new",
"delete 1 routes",
"mapped 1 routes",
"rename app-name-new to app-name",
}))
})
It("returns true", func() {
result := p.Deploy(manifest.CfDomains{DefaultDomain: "example.com"}, &fakes.FakeManifestReader{}, NewArgs([]string{"bgd", "app-name", "--smoke-test", "script/smoke-test"}))
Expect(result).To(Equal(true))
})
})
Context("when it fails", func() {
var (
b *BlueGreenDeployFake
p CfPlugin
)
BeforeEach(func() {
b = &BlueGreenDeployFake{liveApp: nil, passSmokeTest: false}
p = CfPlugin{
Deployer: b,
}
})
It("calls methods in correct order", func() {
p.Deploy(manifest.CfDomains{DefaultDomain: "example.com"}, &fakes.FakeManifestReader{}, NewArgs([]string{"bgd", "app-name", "--smoke-test", "script/smoke-test"}))
Expect(b.flow).To(Equal([]string{
"delete old apps",
"get current live app",
"push app-name-new",
"script/smoke-test app-name-new.example.com",
"unmap 1 routes from app-name-new",
"delete 1 routes",
"rename app-name-new to app-name-failed",
}))
})
It("returns false", func() {
result := p.Deploy(manifest.CfDomains{DefaultDomain: "example.com"}, &fakes.FakeManifestReader{}, NewArgs([]string{"bgd", "app-name", "--smoke-test", "script/smoke-test"}))
Expect(result).To(Equal(false))
})
})
})
Describe("GetScaleFromManifest", func() {
p := CfPlugin{}
Context("when the manifest is valid", func() {
It("returns the scale parameters", func() {
fakeManifestReader := &fakes.FakeManifestReader{Yaml: `---
name: app-name
memory: 16M
disk_quota: 500M
hosts:
- man1
`,
}
actualScale := p.GetScaleFromManifest("app-name", manifest.CfDomains{DefaultDomain: "example.com"}, fakeManifestReader)
expectedScale := ScaleParameters{Memory: int64(16), DiskQuota: int64(500)}
Expect(actualScale).To(Equal(expectedScale))
})
})
Context("the manifest is invalid", func() {
It("returns an empty manifest", func() {
failingFakeManifestReader := &fakes.FakeManifestReader{Err: errors.New("")}
actualScale := p.GetScaleFromManifest("app-name", manifest.CfDomains{DefaultDomain: "example.com"}, failingFakeManifestReader)
expectedScale := ScaleParameters{}
Expect(actualScale).To(Equal(expectedScale))
})
})
})
})
Describe("SharedDomains", func() {
connection := &pluginfakes.FakeCliConnection{}
p := CfPlugin{Connection: connection}
Context("when CF command succeeds", func() {
It("returns all CF shared domains", func() {
connection.CliCommandWithoutTerminalOutputStub = func(args ...string) ([]string, error) {
return []string{`{
"total_results": 2,
"total_pages": 1,
"prev_url": null,
"next_url": null,
"resources": [
{
"metadata": {
"guid": "75049093-13e9-4520-80a6-2d6fea6542bc",
"url": "/v2/shared_domains/75049093-13e9-4520-80a6-2d6fea6542bc",
"created_at": "2014-10-20T09:21:39+00:00",
"updated_at": null
},
"entity": {
"name": "my.cool.com"
}},
{
"metadata": {
"guid": "75049093-13e9-4520-80a6-2d6fea6542bc",
"url": "/v2/shared_domains/75049093-13e9-4520-80a6-2d6fea6542bc",
"created_at": "2014-10-20T09:21:39+00:00",
"updated_at": null
},
"entity": {
"name": "another.com"
}
}
]
}`}, nil
}
domain, _ := p.SharedDomains()
Expect(domain).To(Equal([]string{"my.cool.com", "another.com"}))
})
})
Context("when CF command fails", func() {
It("returns error", func() {
connection.CliCommandWithoutTerminalOutputStub = func(args ...string) ([]string, error) {
return nil, errors.New("cf curl failed")
}
_, err := p.SharedDomains()
Expect(err).To(MatchError("cf curl failed"))
})
})
Context("when CF command returns invalid JSON", func() {
It("returns error", func() {
connection.CliCommandWithoutTerminalOutputStub = func(args ...string) ([]string, error) {
return []string{`{"resources": { "entity": "foo" }}`}, nil
}
_, err := p.SharedDomains()
Expect(err).To(HaveOccurred())
})
})
})
Describe("PrivateDomains", func() {
connection := &pluginfakes.FakeCliConnection{}
p := CfPlugin{Connection: connection}
Context("when CF command succeeds", func() {
It("returns all private domains", func() {
connection.CliCommandWithoutTerminalOutputStub = func(args ...string) ([]string, error) {
return []string{`{
"total_results": 2,
"total_pages": 1,
"prev_url": null,
"next_url": null,
"resources": [
{
"metadata": {
"guid": "75049093-13e9-4520-80a6-2d6fea6542bc",
"url": "/v2/private_domains/75049093-13e9-4520-80a6-2d6fea6542bc",
"created_at": "2014-10-20T09:21:39+00:00",
"updated_at": null
},
"entity": {
"name": "eu-gb.mypaas.net"
}},
{
"metadata": {
"guid": "75049093-13e9-4520-80a6-2d6fea6542bc",
"url": "/v2/private_domains/75049093-13e9-4520-80a6-2d6fea6542bc",
"created_at": "2014-10-20T09:21:39+00:00",
"updated_at": null
},
"entity": {
"name": "eu-de.mypaas.net"
}
}
]
}`}, nil
}
domain, _ := p.PrivateDomains()
Expect(domain).To(Equal([]string{"eu-gb.mypaas.net", "eu-de.mypaas.net"}))
})
})
Context("when CF command fails", func() {
It("returns error", func() {
connection.CliCommandWithoutTerminalOutputStub = func(args ...string) ([]string, error) {
return nil, errors.New("cf curl failed")
}
_, err := p.PrivateDomains()
Expect(err).To(MatchError("cf curl failed"))
})
})
Context("when CF command returns invalid JSON", func() {
It("returns error", func() {
connection.CliCommandWithoutTerminalOutputStub = func(args ...string) ([]string, error) {
return []string{`{"resources": { "entity": "foo" }}`}, nil
}
_, err := p.PrivateDomains()
Expect(err).To(HaveOccurred())
})
})
})
Describe("Unique list of routes", func() {
p := CfPlugin{}
Context("when listA and ListB are empty", func() {
It("returns an empty list", func() {
listA := []plugin_models.GetApp_RouteSummary{}
listB := []plugin_models.GetApp_RouteSummary{}
Expect(p.UnionRouteLists(listA, listB)).To(BeEmpty())
})
})
Context("when listA is Empty", func() {
It("returns listB", func() {
listA := []plugin_models.GetApp_RouteSummary{}
listB := []plugin_models.GetApp_RouteSummary{{Host: "foo"}}
Expect(p.UnionRouteLists(listA, listB)).To(Equal(listB))
})
})
Context("when listB is Empty", func() {
It("returns listA", func() {
listA := []plugin_models.GetApp_RouteSummary{{Host: "foo"}}
listB := []plugin_models.GetApp_RouteSummary{}
Expect(p.UnionRouteLists(listA, listB)).To(ConsistOf(listA))
})
})
Context("when listB and listA contain the same routes", func() {
It("returns a list equal in contents to listB", func() {
listA := []plugin_models.GetApp_RouteSummary{{Host: "foo"}}
listB := []plugin_models.GetApp_RouteSummary{{Host: "foo"}}
Expect(p.UnionRouteLists(listA, listB)).To(ConsistOf(listA))
})
})
Context("when listB and listA contain different routes", func() {
It("returns a union of both routes", func() {
listA := []plugin_models.GetApp_RouteSummary{{Host: "foo"}}
listB := []plugin_models.GetApp_RouteSummary{{Host: "bar"}}
Expect(p.UnionRouteLists(listA, listB)).To(ConsistOf(append(listA, listB...)))
})
})
Context("when listA contains some routes not in listB", func() {
It("returns a union of both routes", func() {
listA := []plugin_models.GetApp_RouteSummary{{Host: "foo"}, {Host: "bar"}}
listB := []plugin_models.GetApp_RouteSummary{{Host: "foo"}}
Expect(p.UnionRouteLists(listA, listB)).To(ConsistOf(listA))
})
})
Context("when listB contains some routes not in listA", func() {
It("returns a union of both routes", func() {
listA := []plugin_models.GetApp_RouteSummary{{Host: "foo"}}
listB := []plugin_models.GetApp_RouteSummary{{Host: "foo"}, {Host: "bar"}}
Expect(p.UnionRouteLists(listA, listB)).To(ConsistOf(listB))
})
})
Context("when list A and List B contain both shared and non-shared routes", func() {
It("returns a union of both routes", func() {
listA := []plugin_models.GetApp_RouteSummary{{Host: "shared"}, {Host: "listAOnly"}}
listB := []plugin_models.GetApp_RouteSummary{{Host: "shared"}, {Host: "listBOnly"}}
expectedRoutes := []plugin_models.GetApp_RouteSummary{{Host: "shared"}, {Host: "listAOnly"}, {Host: "listBOnly"}}
Expect(p.UnionRouteLists(listA, listB)).To(ConsistOf(expectedRoutes))
})
})
Context("when list A is nil", func() {
It("returns list B", func() {
listB := []plugin_models.GetApp_RouteSummary{{Host: "foo"}}
Expect(p.UnionRouteLists(nil, listB)).To(ConsistOf(listB))
})
})
Context("when list B is nil", func() {
It("returns list A", func() {
listA := []plugin_models.GetApp_RouteSummary{{Host: "foo"}}
Expect(p.UnionRouteLists(listA, nil)).To(ConsistOf(listA))
})
})
Context("when list A & list B are nil", func() {
It("returns an empty Array", func() {
Expect(p.UnionRouteLists(nil, nil)).To(BeEmpty())
})
})
})
Describe("FQDN", func() {
It("returns the fqdn of the route", func() {
route := plugin_models.GetApp_RouteSummary{Host: "testroute", Domain: plugin_models.GetApp_DomainFields{Name: "example.com"}}
Expect(FQDN(route)).To(Equal("testroute.example.com"))
})
})
})
type BlueGreenDeployFake struct {
flow []string
liveApp *plugin_models.GetAppModel
appSshEnabled bool
passSmokeTest bool
mappedRoutes []plugin_models.GetApp_RouteSummary
deletedRoutes []plugin_models.GetApp_RouteSummary
scale *ScaleParameters
usedScale *ScaleParameters
}
func (p *BlueGreenDeployFake) Setup(connection plugin.CliConnection) {
p.flow = append(p.flow, "setup")
}
func (p *BlueGreenDeployFake) GetScaleParameters(appName string) (ScaleParameters, error) {
return ScaleParameters{}, nil
}
func (p *BlueGreenDeployFake) PushNewApp(appName string, route plugin_models.GetApp_RouteSummary,
manifestPath string, scaleParameters ScaleParameters) {
p.usedScale = &scaleParameters
p.flow = append(p.flow, fmt.Sprintf("push %s", appName))
}
func (p *BlueGreenDeployFake) DeleteAllAppsExceptLiveApp(string) {
p.flow = append(p.flow, "delete old apps")
}
func (p *BlueGreenDeployFake) DeleteAllAppsExceptLiveAndFailedApp(string) {
p.flow = append(p.flow, "delete old apps except failed ones")
}
func (p *BlueGreenDeployFake) LiveApp(string) (string, []plugin_models.GetApp_RouteSummary) {
p.flow = append(p.flow, "get current live app")
if p.liveApp == nil {
return "", nil
} else {
return p.liveApp.Name, p.liveApp.Routes
}
}
func (p *BlueGreenDeployFake) RunSmokeTests(script string, fqdn string) bool {
p.flow = append(p.flow, fmt.Sprintf("%s %s", script, fqdn))
return p.passSmokeTest
}
func (p *BlueGreenDeployFake) RemapRoutesFromLiveAppToNewApp(liveApp plugin_models.GetAppModel, newApp plugin_models.GetAppModel) {
p.flow = append(p.flow, fmt.Sprintf("remap routes from %s to %s", liveApp.Name, newApp.Name))
}
func (p *BlueGreenDeployFake) RenameApp(app string, newName string) {
p.flow = append(p.flow, fmt.Sprintf("rename %s to %s", app, newName))
}
func (p *BlueGreenDeployFake) MapRoutesToApp(appName string, routes ...plugin_models.GetApp_RouteSummary) {
p.mappedRoutes = routes
p.flow = append(p.flow, fmt.Sprintf("mapped %d routes", len(routes)))
}
func (p *BlueGreenDeployFake) UnmapRoutesFromApp(oldAppName string, routes ...plugin_models.GetApp_RouteSummary) {
p.flow = append(p.flow, fmt.Sprintf("unmap %d routes from %s", len(routes), oldAppName))
}
func (p *BlueGreenDeployFake) DeleteRoutes(routes ...plugin_models.GetApp_RouteSummary) {
p.deletedRoutes = routes
p.flow = append(p.flow, fmt.Sprintf("delete %d routes", len(routes)))
}
func (p *BlueGreenDeployFake) CheckSshEnablement(app string) bool {
p.flow = append(p.flow, fmt.Sprintf("check ssh enablement for '%s'", app))
return strings.Contains(app, "ssh-enabled-app")
}
func (p *BlueGreenDeployFake) SetSshAccess(app string, enableSsh bool) {
p.flow = append(p.flow, fmt.Sprintf("set ssh enablement for '%s' to '%v'", app, enableSsh))
}