@@ -15,8 +15,7 @@ import (
15
15
16
16
func TestDeploymentController_Sync (t * testing.T ) {
17
17
mocks := newDeploymentFixture ()
18
- err := mocks .controller .Initialize (mocks .canary , true )
19
- require .NoError (t , err )
18
+ mocks .initializeCanary (t )
20
19
21
20
depPrimary , err := mocks .kubeClient .AppsV1 ().Deployments ("default" ).Get ("podinfo-primary" , metav1.GetOptions {})
22
21
require .NoError (t , err )
@@ -33,11 +32,10 @@ func TestDeploymentController_Sync(t *testing.T) {
33
32
34
33
func TestDeploymentController_Promote (t * testing.T ) {
35
34
mocks := newDeploymentFixture ()
36
- err := mocks .controller .Initialize (mocks .canary , true )
37
- require .NoError (t , err )
35
+ mocks .initializeCanary (t )
38
36
39
37
dep2 := newDeploymentControllerTestV2 ()
40
- _ , err = mocks .kubeClient .AppsV1 ().Deployments ("default" ).Update (dep2 )
38
+ _ , err : = mocks .kubeClient .AppsV1 ().Deployments ("default" ).Update (dep2 )
41
39
require .NoError (t , err )
42
40
43
41
config2 := newDeploymentControllerTestConfigMapV2 ()
@@ -74,10 +72,9 @@ func TestDeploymentController_Promote(t *testing.T) {
74
72
75
73
func TestDeploymentController_ScaleToZero (t * testing.T ) {
76
74
mocks := newDeploymentFixture ()
77
- err := mocks .controller .Initialize (mocks .canary , true )
78
- require .NoError (t , err )
75
+ mocks .initializeCanary (t )
79
76
80
- err = mocks .controller .ScaleToZero (mocks .canary )
77
+ err : = mocks .controller .ScaleToZero (mocks .canary )
81
78
require .NoError (t , err )
82
79
83
80
c , err := mocks .kubeClient .AppsV1 ().Deployments ("default" ).Get ("podinfo" , metav1.GetOptions {})
@@ -88,9 +85,7 @@ func TestDeploymentController_ScaleToZero(t *testing.T) {
88
85
func TestDeploymentController_NoConfigTracking (t * testing.T ) {
89
86
mocks := newDeploymentFixture ()
90
87
mocks .controller .configTracker = & NopTracker {}
91
-
92
- err := mocks .controller .Initialize (mocks .canary , true )
93
- require .NoError (t , err )
88
+ mocks .initializeCanary (t )
94
89
95
90
depPrimary , err := mocks .kubeClient .AppsV1 ().Deployments ("default" ).Get ("podinfo-primary" , metav1.GetOptions {})
96
91
require .NoError (t , err )
@@ -104,8 +99,7 @@ func TestDeploymentController_NoConfigTracking(t *testing.T) {
104
99
105
100
func TestDeploymentController_HasTargetChanged (t * testing.T ) {
106
101
mocks := newDeploymentFixture ()
107
- err := mocks .controller .Initialize (mocks .canary , true )
108
- require .NoError (t , err )
102
+ mocks .initializeCanary (t )
109
103
110
104
// save last applied hash
111
105
canary , err := mocks .flaggerClient .FlaggerV1beta1 ().Canaries ("default" ).Get ("podinfo" , metav1.GetOptions {})
@@ -190,46 +184,35 @@ func TestDeploymentController_HasTargetChanged(t *testing.T) {
190
184
}
191
185
192
186
func TestDeploymentController_Finalize (t * testing.T ) {
193
-
194
187
mocks := newDeploymentFixture ()
195
188
196
- tables := []struct {
189
+ for _ , tc := range []struct {
197
190
mocks deploymentControllerFixture
198
191
callInitialize bool
199
192
shouldError bool
200
193
expectedReplicas int32
201
194
canary * flaggerv1.Canary
202
195
}{
203
- //Primary not found returns error
196
+ // primary not found returns error
204
197
{mocks , false , false , 1 , mocks .canary },
205
- //Happy path
198
+ // happy path
206
199
{mocks , true , false , 1 , mocks .canary },
207
- }
208
-
209
- for _ , table := range tables {
210
- if table .callInitialize {
211
- err := mocks .controller .Initialize (table .canary , true )
212
- if err != nil {
213
- t .Fatal (err .Error ())
214
- }
200
+ } {
201
+ if tc .callInitialize {
202
+ mocks .initializeCanary (t )
215
203
}
216
204
217
- err := mocks .controller .Finalize (table .canary )
218
-
219
- if table .shouldError && err == nil {
220
- t .Error ("Expected error while calling Finalize, but none was returned" )
221
- } else if ! table .shouldError && err != nil {
222
- t .Errorf ("Expected no error would be returned while calling Finalize, but returned %s" , err )
205
+ err := mocks .controller .Finalize (tc .canary )
206
+ if tc .shouldError {
207
+ require .Error (t , err )
208
+ } else {
209
+ require .NoError (t , err )
223
210
}
224
211
225
- if table .expectedReplicas > 0 {
212
+ if tc .expectedReplicas > 0 {
226
213
c , err := mocks .kubeClient .AppsV1 ().Deployments (mocks .canary .Namespace ).Get (mocks .canary .Name , metav1.GetOptions {})
227
- if err != nil {
228
- t .Fatal (err .Error ())
229
- }
230
- if int32Default (c .Spec .Replicas ) != table .expectedReplicas {
231
- t .Errorf ("Expected replicas %d recieved replicas %d" , table .expectedReplicas , c .Spec .Replicas )
232
- }
214
+ require .NoError (t , err )
215
+ require .Equal (t , tc .expectedReplicas , * c .Spec .Replicas )
233
216
}
234
217
}
235
218
}
0 commit comments