@@ -35,6 +35,20 @@ func TestStop(t *testing.T) {
35
35
return & (kerrors .NewNotFound (kapi .Resource ("DeploymentConfig" ), "config" ).ErrStatus )
36
36
}
37
37
38
+ pause := func (d * deployapi.DeploymentConfig ) * deployapi.DeploymentConfig {
39
+ d .Spec .Paused = true
40
+ return d
41
+ }
42
+
43
+ fakeDC := map [string ]* deployapi.DeploymentConfig {
44
+ "simple-stop" : deploytest .OkDeploymentConfig (1 ),
45
+ "legacy-simple-stop" : deploytest .OkDeploymentConfig (1 ),
46
+ "multi-stop" : deploytest .OkDeploymentConfig (5 ),
47
+ "legacy-multi-stop" : deploytest .OkDeploymentConfig (5 ),
48
+ "no-deployments" : deploytest .OkDeploymentConfig (5 ),
49
+ "legacy-no-deployments" : deploytest .OkDeploymentConfig (5 ),
50
+ }
51
+
38
52
tests := []struct {
39
53
testName string
40
54
namespace string
@@ -49,9 +63,36 @@ func TestStop(t *testing.T) {
49
63
testName : "simple stop" ,
50
64
namespace : "default" ,
51
65
name : "config" ,
52
- oc : testclient .NewSimpleFake (deploytest .OkDeploymentConfig (1 )),
66
+ oc : testclient .NewSimpleFake (fakeDC ["simple-stop" ]),
67
+ kc : ktestclient .NewSimpleFake (mkdeploymentlist (1 )),
68
+ expected : []ktestclient.Action {
69
+ ktestclient .NewGetAction ("deploymentconfigs" , "default" , "config" ),
70
+ ktestclient .NewUpdateAction ("deploymentconfigs" , "default" , pause (fakeDC ["simple-stop" ])),
71
+ ktestclient .NewGetAction ("deploymentconfigs" , "default" , "config" ),
72
+ ktestclient .NewDeleteAction ("deploymentconfigs" , "default" , "config" ),
73
+ },
74
+ kexpected : []ktestclient.Action {
75
+ ktestclient .NewListAction ("replicationcontrollers" , "default" , kapi.ListOptions {}),
76
+ ktestclient .NewGetAction ("replicationcontrollers" , "" , "config-1" ),
77
+ ktestclient .NewListAction ("replicationcontrollers" , "" , kapi.ListOptions {}),
78
+ ktestclient .NewGetAction ("replicationcontrollers" , "" , "config-1" ),
79
+ ktestclient .NewUpdateAction ("replicationcontrollers" , "" , nil ),
80
+ ktestclient .NewGetAction ("replicationcontrollers" , "" , "config-1" ),
81
+ ktestclient .NewGetAction ("replicationcontrollers" , "" , "config-1" ),
82
+ ktestclient .NewDeleteAction ("replicationcontrollers" , "" , "config-1" ),
83
+ },
84
+ err : false ,
85
+ },
86
+ {
87
+ testName : "legacy simple stop" ,
88
+ namespace : "default" ,
89
+ name : "config" ,
90
+ oc : testclient .NewSimpleFake (fakeDC ["legacy-simple-stop" ]),
53
91
kc : ktestclient .NewSimpleFake (mkdeploymentlist (1 )),
54
92
expected : []ktestclient.Action {
93
+ ktestclient .NewGetAction ("deploymentconfigs" , "default" , "config" ),
94
+ ktestclient .NewUpdateAction ("deploymentconfigs" , "default" , nil ),
95
+ ktestclient .NewGetAction ("deploymentconfigs" , "default" , "config" ),
55
96
ktestclient .NewDeleteAction ("deploymentconfigs" , "default" , "config" ),
56
97
},
57
98
kexpected : []ktestclient.Action {
@@ -70,9 +111,64 @@ func TestStop(t *testing.T) {
70
111
testName : "stop multiple controllers" ,
71
112
namespace : "default" ,
72
113
name : "config" ,
73
- oc : testclient .NewSimpleFake (deploytest .OkDeploymentConfig (5 )),
114
+ oc : testclient .NewSimpleFake (fakeDC ["multi-stop" ]),
115
+ kc : ktestclient .NewSimpleFake (mkdeploymentlist (1 , 2 , 3 , 4 , 5 )),
116
+ expected : []ktestclient.Action {
117
+ ktestclient .NewGetAction ("deploymentconfigs" , "default" , "config" ),
118
+ ktestclient .NewUpdateAction ("deploymentconfigs" , "default" , pause (fakeDC ["multi-stop" ])),
119
+ ktestclient .NewGetAction ("deploymentconfigs" , "default" , "config" ),
120
+ ktestclient .NewDeleteAction ("deploymentconfigs" , "default" , "config" ),
121
+ },
122
+ kexpected : []ktestclient.Action {
123
+ ktestclient .NewListAction ("replicationcontrollers" , "default" , kapi.ListOptions {}),
124
+ ktestclient .NewGetAction ("replicationcontrollers" , "" , "config-1" ),
125
+ ktestclient .NewListAction ("replicationcontrollers" , "" , kapi.ListOptions {}),
126
+ ktestclient .NewGetAction ("replicationcontrollers" , "" , "config-1" ),
127
+ ktestclient .NewUpdateAction ("replicationcontrollers" , "" , nil ),
128
+ ktestclient .NewGetAction ("replicationcontrollers" , "" , "config-1" ),
129
+ ktestclient .NewGetAction ("replicationcontrollers" , "" , "config-4" ),
130
+ ktestclient .NewDeleteAction ("replicationcontrollers" , "" , "config-1" ),
131
+ ktestclient .NewGetAction ("replicationcontrollers" , "" , "config-2" ),
132
+ ktestclient .NewListAction ("replicationcontrollers" , "" , kapi.ListOptions {}),
133
+ ktestclient .NewGetAction ("replicationcontrollers" , "" , "config-2" ),
134
+ ktestclient .NewUpdateAction ("replicationcontrollers" , "" , nil ),
135
+ ktestclient .NewGetAction ("replicationcontrollers" , "" , "config-2" ),
136
+ ktestclient .NewGetAction ("replicationcontrollers" , "" , "config-5" ),
137
+ ktestclient .NewDeleteAction ("replicationcontrollers" , "" , "config-2" ),
138
+ ktestclient .NewGetAction ("replicationcontrollers" , "" , "config-3" ),
139
+ ktestclient .NewListAction ("replicationcontrollers" , "" , kapi.ListOptions {}),
140
+ ktestclient .NewGetAction ("replicationcontrollers" , "" , "config-3" ),
141
+ ktestclient .NewUpdateAction ("replicationcontrollers" , "" , nil ),
142
+ ktestclient .NewGetAction ("replicationcontrollers" , "" , "config-3" ),
143
+ ktestclient .NewGetAction ("replicationcontrollers" , "" , "config-5" ),
144
+ ktestclient .NewDeleteAction ("replicationcontrollers" , "" , "config-3" ),
145
+ ktestclient .NewGetAction ("replicationcontrollers" , "" , "config-4" ),
146
+ ktestclient .NewListAction ("replicationcontrollers" , "" , kapi.ListOptions {}),
147
+ ktestclient .NewGetAction ("replicationcontrollers" , "" , "config-4" ),
148
+ ktestclient .NewUpdateAction ("replicationcontrollers" , "" , nil ),
149
+ ktestclient .NewGetAction ("replicationcontrollers" , "" , "config-4" ),
150
+ ktestclient .NewGetAction ("replicationcontrollers" , "" , "config-5" ),
151
+ ktestclient .NewDeleteAction ("replicationcontrollers" , "" , "config-4" ),
152
+ ktestclient .NewGetAction ("replicationcontrollers" , "" , "config-5" ),
153
+ ktestclient .NewListAction ("replicationcontrollers" , "" , kapi.ListOptions {}),
154
+ ktestclient .NewGetAction ("replicationcontrollers" , "" , "config-5" ),
155
+ ktestclient .NewUpdateAction ("replicationcontrollers" , "" , nil ),
156
+ ktestclient .NewGetAction ("replicationcontrollers" , "" , "config-5" ),
157
+ ktestclient .NewGetAction ("replicationcontrollers" , "" , "config-5" ),
158
+ ktestclient .NewDeleteAction ("replicationcontrollers" , "" , "config-5" ),
159
+ },
160
+ err : false ,
161
+ },
162
+ {
163
+ testName : "legacy stop multiple controllers" ,
164
+ namespace : "default" ,
165
+ name : "config" ,
166
+ oc : testclient .NewSimpleFake (fakeDC ["legacy-multi-stop" ]),
74
167
kc : ktestclient .NewSimpleFake (mkdeploymentlist (1 , 2 , 3 , 4 , 5 )),
75
168
expected : []ktestclient.Action {
169
+ ktestclient .NewGetAction ("deploymentconfigs" , "default" , "config" ),
170
+ ktestclient .NewUpdateAction ("deploymentconfigs" , "default" , nil ),
171
+ ktestclient .NewGetAction ("deploymentconfigs" , "default" , "config" ),
76
172
ktestclient .NewDeleteAction ("deploymentconfigs" , "default" , "config" ),
77
173
},
78
174
kexpected : []ktestclient.Action {
@@ -122,7 +218,7 @@ func TestStop(t *testing.T) {
122
218
oc : testclient .NewSimpleFake (notfound ()),
123
219
kc : ktestclient .NewSimpleFake (mkdeploymentlist (1 )),
124
220
expected : []ktestclient.Action {
125
- ktestclient .NewDeleteAction ("deploymentconfigs" , "default" , "config" ),
221
+ ktestclient .NewGetAction ("deploymentconfigs" , "default" , "config" ),
126
222
},
127
223
kexpected : []ktestclient.Action {
128
224
ktestclient .NewListAction ("replicationcontrollers" , "default" , kapi.ListOptions {}),
@@ -143,7 +239,7 @@ func TestStop(t *testing.T) {
143
239
oc : testclient .NewSimpleFake (notfound ()),
144
240
kc : ktestclient .NewSimpleFake (& kapi.ReplicationControllerList {}),
145
241
expected : []ktestclient.Action {
146
- ktestclient .NewDeleteAction ("deploymentconfigs" , "default" , "config" ),
242
+ ktestclient .NewGetAction ("deploymentconfigs" , "default" , "config" ),
147
243
},
148
244
kexpected : []ktestclient.Action {
149
245
ktestclient .NewListAction ("replicationcontrollers" , "default" , kapi.ListOptions {}),
@@ -154,9 +250,29 @@ func TestStop(t *testing.T) {
154
250
testName : "config, no deployments" ,
155
251
namespace : "default" ,
156
252
name : "config" ,
157
- oc : testclient .NewSimpleFake (deploytest .OkDeploymentConfig (5 )),
253
+ oc : testclient .NewSimpleFake (fakeDC ["no-deployments" ]),
254
+ kc : ktestclient .NewSimpleFake (& kapi.ReplicationControllerList {}),
255
+ expected : []ktestclient.Action {
256
+ ktestclient .NewGetAction ("deploymentconfigs" , "default" , "config" ),
257
+ ktestclient .NewUpdateAction ("deploymentconfigs" , "default" , pause (fakeDC ["no-deployments" ])),
258
+ ktestclient .NewGetAction ("deploymentconfigs" , "default" , "config" ),
259
+ ktestclient .NewDeleteAction ("deploymentconfigs" , "default" , "config" ),
260
+ },
261
+ kexpected : []ktestclient.Action {
262
+ ktestclient .NewListAction ("replicationcontrollers" , "default" , kapi.ListOptions {}),
263
+ },
264
+ err : false ,
265
+ },
266
+ {
267
+ testName : "legacy config, no deployments" ,
268
+ namespace : "default" ,
269
+ name : "config" ,
270
+ oc : testclient .NewSimpleFake (fakeDC ["legacy-no-deployments" ]),
158
271
kc : ktestclient .NewSimpleFake (& kapi.ReplicationControllerList {}),
159
272
expected : []ktestclient.Action {
273
+ ktestclient .NewGetAction ("deploymentconfigs" , "default" , "config" ),
274
+ ktestclient .NewUpdateAction ("deploymentconfigs" , "default" , nil ),
275
+ ktestclient .NewGetAction ("deploymentconfigs" , "default" , "config" ),
160
276
ktestclient .NewDeleteAction ("deploymentconfigs" , "default" , "config" ),
161
277
},
162
278
kexpected : []ktestclient.Action {
@@ -180,8 +296,19 @@ func TestStop(t *testing.T) {
180
296
t .Fatalf ("%s: unexpected actions: %v, expected %v" , test .testName , test .oc .Actions (), test .expected )
181
297
}
182
298
for j , actualAction := range test .oc .Actions () {
183
- if ! reflect .DeepEqual (actualAction , test .expected [j ]) {
184
- t .Errorf ("%s: unexpected action: %s, expected %s" , test .testName , actualAction , test .expected [j ])
299
+ e , a := test .expected [j ], actualAction
300
+ switch a .(type ) {
301
+ case ktestclient.UpdateAction :
302
+ if e .GetVerb () != a .GetVerb () ||
303
+ e .GetNamespace () != a .GetNamespace () ||
304
+ e .GetResource () != a .GetResource () ||
305
+ e .GetSubresource () != a .GetSubresource () {
306
+ t .Errorf ("%s: unexpected action[%d]: %s, expected %s" , test .testName , j , a , e )
307
+ }
308
+ default :
309
+ if ! reflect .DeepEqual (actualAction , test .expected [j ]) {
310
+ t .Errorf ("%s: unexpected action: got:\n %#+v\n expected:\n %#+v" , test .testName , actualAction , test .expected [j ])
311
+ }
185
312
}
186
313
}
187
314
if len (test .kc .Actions ()) != len (test .kexpected ) {
0 commit comments