@@ -5,8 +5,10 @@ import (
5
5
"testing"
6
6
"time"
7
7
8
+ kapierrors "k8s.io/apimachinery/pkg/api/errors"
8
9
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9
10
"k8s.io/apimachinery/pkg/labels"
11
+ "k8s.io/apimachinery/pkg/runtime"
10
12
"k8s.io/apimachinery/pkg/runtime/schema"
11
13
"k8s.io/apimachinery/pkg/util/diff"
12
14
clientgotesting "k8s.io/client-go/testing"
@@ -40,10 +42,7 @@ func TestStop(t *testing.T) {
40
42
replicationControllerKind = schema.GroupVersionKind {Kind : "ReplicationController" }
41
43
)
42
44
43
- pause := func (d * deployapi.DeploymentConfig ) * deployapi.DeploymentConfig {
44
- d .Spec .Paused = true
45
- return d
46
- }
45
+ pauseBytes := []byte (`{"spec":{"paused":true,"replicas":0,"revisionHistoryLimit":0}}` )
47
46
48
47
fakeDC := map [string ]* deployapi.DeploymentConfig {
49
48
"simple-stop" : deploytest .OkDeploymentConfig (1 ),
@@ -54,6 +53,14 @@ func TestStop(t *testing.T) {
54
53
"legacy-no-deployments" : deploytest .OkDeploymentConfig (5 ),
55
54
}
56
55
56
+ emptyClientset := func () * appsfake.Clientset {
57
+ result := & appsfake.Clientset {}
58
+ result .AddReactor ("patch" , "deploymentconfigs" , func (action clientgotesting.Action ) (handled bool , ret runtime.Object , err error ) {
59
+ return true , nil , kapierrors .NewNotFound (schema.GroupResource {Group : "apps.openshift.io" , Resource : "deploymentconfig" }, "config" )
60
+ })
61
+ return result
62
+ }
63
+
57
64
tests := []struct {
58
65
testName string
59
66
namespace string
@@ -71,8 +78,7 @@ func TestStop(t *testing.T) {
71
78
oc : appsfake .NewSimpleClientset (fakeDC ["simple-stop" ]),
72
79
kc : fake .NewSimpleClientset (mkdeploymentlist (1 )),
73
80
expected : []clientgotesting.Action {
74
- clientgotesting .NewGetAction (deploymentConfigsResource , "default" , "config" ),
75
- clientgotesting .NewUpdateAction (deploymentConfigsResource , "default" , pause (fakeDC ["simple-stop" ])),
81
+ clientgotesting .NewPatchAction (deploymentConfigsResource , "default" , "config" , pauseBytes ),
76
82
clientgotesting .NewGetAction (deploymentConfigsResource , "default" , "config" ),
77
83
clientgotesting .NewDeleteAction (deploymentConfigsResource , "default" , "config" ),
78
84
},
@@ -94,8 +100,7 @@ func TestStop(t *testing.T) {
94
100
oc : appsfake .NewSimpleClientset (fakeDC ["legacy-simple-stop" ]),
95
101
kc : fake .NewSimpleClientset (mkdeploymentlist (1 )),
96
102
expected : []clientgotesting.Action {
97
- clientgotesting .NewGetAction (deploymentConfigsResource , "default" , "config" ),
98
- clientgotesting .NewUpdateAction (deploymentConfigsResource , "default" , nil ),
103
+ clientgotesting .NewPatchAction (deploymentConfigsResource , "default" , "config" , pauseBytes ),
99
104
clientgotesting .NewGetAction (deploymentConfigsResource , "default" , "config" ),
100
105
clientgotesting .NewDeleteAction (deploymentConfigsResource , "default" , "config" ),
101
106
},
@@ -117,8 +122,7 @@ func TestStop(t *testing.T) {
117
122
oc : appsfake .NewSimpleClientset (fakeDC ["multi-stop" ]),
118
123
kc : fake .NewSimpleClientset (mkdeploymentlist (1 , 2 , 3 , 4 , 5 )),
119
124
expected : []clientgotesting.Action {
120
- clientgotesting .NewGetAction (deploymentConfigsResource , "default" , "config" ),
121
- clientgotesting .NewUpdateAction (deploymentConfigsResource , "default" , pause (fakeDC ["multi-stop" ])),
125
+ clientgotesting .NewPatchAction (deploymentConfigsResource , "default" , "config" , pauseBytes ),
122
126
clientgotesting .NewGetAction (deploymentConfigsResource , "default" , "config" ),
123
127
clientgotesting .NewDeleteAction (deploymentConfigsResource , "default" , "config" ),
124
128
},
@@ -164,8 +168,7 @@ func TestStop(t *testing.T) {
164
168
oc : appsfake .NewSimpleClientset (fakeDC ["legacy-multi-stop" ]),
165
169
kc : fake .NewSimpleClientset (mkdeploymentlist (1 , 2 , 3 , 4 , 5 )),
166
170
expected : []clientgotesting.Action {
167
- clientgotesting .NewGetAction (deploymentConfigsResource , "default" , "config" ),
168
- clientgotesting .NewUpdateAction (deploymentConfigsResource , "default" , nil ),
171
+ clientgotesting .NewPatchAction (deploymentConfigsResource , "default" , "config" , pauseBytes ),
169
172
clientgotesting .NewGetAction (deploymentConfigsResource , "default" , "config" ),
170
173
clientgotesting .NewDeleteAction (deploymentConfigsResource , "default" , "config" ),
171
174
},
@@ -208,10 +211,10 @@ func TestStop(t *testing.T) {
208
211
testName : "no config, some deployments" ,
209
212
namespace : "default" ,
210
213
name : "config" ,
211
- oc : appsfake . NewSimpleClientset (),
214
+ oc : emptyClientset (),
212
215
kc : fake .NewSimpleClientset (mkdeploymentlist (1 )),
213
216
expected : []clientgotesting.Action {
214
- clientgotesting .NewGetAction (deploymentConfigsResource , "default" , "config" ),
217
+ clientgotesting .NewPatchAction (deploymentConfigsResource , "default" , "config" , pauseBytes ),
215
218
},
216
219
kexpected : []clientgotesting.Action {
217
220
clientgotesting .NewListAction (replicationControllersResource , replicationControllerKind , "default" , metav1.ListOptions {LabelSelector : labels .SelectorFromSet (map [string ]string {"openshift.io/deployment-config.name" : "config" }).String ()}),
@@ -228,10 +231,10 @@ func TestStop(t *testing.T) {
228
231
testName : "no config, no deployments" ,
229
232
namespace : "default" ,
230
233
name : "config" ,
231
- oc : appsfake . NewSimpleClientset (),
234
+ oc : emptyClientset (),
232
235
kc : fake .NewSimpleClientset (& kapi.ReplicationControllerList {}),
233
236
expected : []clientgotesting.Action {
234
- clientgotesting .NewGetAction (deploymentConfigsResource , "default" , "config" ),
237
+ clientgotesting .NewPatchAction (deploymentConfigsResource , "default" , "config" , pauseBytes ),
235
238
},
236
239
kexpected : []clientgotesting.Action {
237
240
clientgotesting .NewListAction (replicationControllersResource , replicationControllerKind , "default" , metav1.ListOptions {}),
@@ -245,8 +248,7 @@ func TestStop(t *testing.T) {
245
248
oc : appsfake .NewSimpleClientset (fakeDC ["no-deployments" ]),
246
249
kc : fake .NewSimpleClientset (& kapi.ReplicationControllerList {}),
247
250
expected : []clientgotesting.Action {
248
- clientgotesting .NewGetAction (deploymentConfigsResource , "default" , "config" ),
249
- clientgotesting .NewUpdateAction (deploymentConfigsResource , "default" , pause (fakeDC ["no-deployments" ])),
251
+ clientgotesting .NewPatchAction (deploymentConfigsResource , "default" , "config" , pauseBytes ),
250
252
clientgotesting .NewGetAction (deploymentConfigsResource , "default" , "config" ),
251
253
clientgotesting .NewDeleteAction (deploymentConfigsResource , "default" , "config" ),
252
254
},
@@ -262,8 +264,7 @@ func TestStop(t *testing.T) {
262
264
oc : appsfake .NewSimpleClientset (fakeDC ["legacy-no-deployments" ]),
263
265
kc : fake .NewSimpleClientset (& kapi.ReplicationControllerList {}),
264
266
expected : []clientgotesting.Action {
265
- clientgotesting .NewGetAction (deploymentConfigsResource , "default" , "config" ),
266
- clientgotesting .NewUpdateAction (deploymentConfigsResource , "default" , nil ),
267
+ clientgotesting .NewPatchAction (deploymentConfigsResource , "default" , "config" , pauseBytes ),
267
268
clientgotesting .NewGetAction (deploymentConfigsResource , "default" , "config" ),
268
269
clientgotesting .NewDeleteAction (deploymentConfigsResource , "default" , "config" ),
269
270
},
0 commit comments