-
Notifications
You must be signed in to change notification settings - Fork 0
/
scale_instances_test.go
125 lines (118 loc) · 4.29 KB
/
scale_instances_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
package boom
import (
"github.com/geofffranks/simpleyaml"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Boom", func() {
var (
boom *Boom
)
Context("ScaleInstances", func() {
BeforeEach(func() {
boom = New(completeManifestPath, false)
})
Context("when the job is found", func() {
Context("when the value is not round", func() {
It("don't update the value", func() {
err := boom.ScaleInstances("cell", 1)
Expect(err).NotTo(HaveOccurred())
result, err := simpleyaml.NewYaml([]byte(boom.String()))
Expect(err).NotTo(HaveOccurred())
Expect(result.Get("jobs").GetIndex(0).Get("instances").Int()).To(Equal(20))
})
})
It("decreases the value", func() {
err := boom.ScaleInstances("cell", 0.5)
Expect(err).NotTo(HaveOccurred())
result, err := simpleyaml.NewYaml([]byte(boom.String()))
Expect(err).NotTo(HaveOccurred())
Expect(result.Get("jobs").GetIndex(0).Get("instances").Int()).To(Equal(10))
})
It("increases the value", func() {
err := boom.ScaleInstances("cell", 2)
Expect(err).NotTo(HaveOccurred())
result, err := simpleyaml.NewYaml([]byte(boom.String()))
Expect(err).NotTo(HaveOccurred())
Expect(result.Get("jobs").GetIndex(0).Get("instances").Int()).To(Equal(40))
})
Context("when the value is not round", func() {
It("updates the value", func() {
err := boom.ScaleInstances("cell", 1.5)
Expect(err).NotTo(HaveOccurred())
result, err := simpleyaml.NewYaml([]byte(boom.String()))
Expect(err).NotTo(HaveOccurred())
Expect(result.Get("jobs").GetIndex(0).Get("instances").Int()).To(Equal(30))
})
})
Context("when the factor is 0", func() {
It("returns an error", func() {
err := boom.ScaleInstances("cell", 0)
Expect(err).To(MatchError("factor 0 is not permitted"))
})
})
Context("when the factor is too low to modify a unit", func() {
Context("when force mode", func() {
It("decreases the value", func() {
err := boom.ScaleInstances("brain", 0.8)
Expect(err).NotTo(HaveOccurred())
result, err := simpleyaml.NewYaml([]byte(boom.String()))
Expect(err).NotTo(HaveOccurred())
Expect(result.Get("jobs").GetIndex(1).Get("instances").Int()).To(Equal(1))
})
It("increases the value", func() {
boom.Force = true
err := boom.ScaleInstances("brain", 1.2)
Expect(err).NotTo(HaveOccurred())
result, err := simpleyaml.NewYaml([]byte(boom.String()))
Expect(err).NotTo(HaveOccurred())
Expect(result.Get("jobs").GetIndex(1).Get("instances").Int()).To(Equal(3))
})
})
Context("when force mode isn't used", func() {
It("don't increase the value", func() {
err := boom.ScaleInstances("brain", 1.2)
Expect(err).NotTo(HaveOccurred())
result, err := simpleyaml.NewYaml([]byte(boom.String()))
Expect(err).NotTo(HaveOccurred())
Expect(result.Get("resource_pools").GetIndex(1).Get("size").Int()).To(Equal(5))
})
})
})
Context("when the resource_pool is found", func() {
Context("when a dedicated resource pool is used", func() {
It("modifies the resource pool size", func() {
err := boom.ScaleInstances("cell", 0.5)
Expect(err).NotTo(HaveOccurred())
result, err := simpleyaml.NewYaml([]byte(boom.String()))
Expect(err).NotTo(HaveOccurred())
Expect(result.Get("resource_pools").GetIndex(0).Get("size").Int()).To(Equal(10))
})
})
Context("when a shared resource pool is used", func() {
It("modifies the resource pool size", func() {
err := boom.ScaleInstances("brain", 2)
Expect(err).NotTo(HaveOccurred())
result, err := simpleyaml.NewYaml([]byte(boom.String()))
Expect(err).NotTo(HaveOccurred())
Expect(result.Get("resource_pools").GetIndex(1).Get("size").Int()).To(Equal(7))
})
})
})
})
Context("when the `jobs` is not in the manifest", func() {
It("does not return an error", func() {
delete(boom.Manifest, "jobs")
err := boom.SetInstances("cell", 2)
Expect(err).NotTo(HaveOccurred())
})
})
Context("when the job is not found", func() {
It("returns an error", func() {
err := boom.SetInstances("not-existing", 2)
Expect(err).To(HaveOccurred())
Expect(err).To(MatchError("element `not-existing` not found"))
})
})
})
})