@@ -103,7 +103,6 @@ var _ = Describe("Controllerutil", func() {
103
103
}))
104
104
})
105
105
})
106
-
107
106
Describe ("SetControllerReference" , func () {
108
107
It ("should set the OwnerReference if it can find the group version kind" , func () {
109
108
rs := & appsv1.ReplicaSet {}
@@ -256,6 +255,46 @@ var _ = Describe("Controllerutil", func() {
256
255
}))
257
256
})
258
257
})
258
+ Describe ("RemoveControllerReference" , func () {
259
+ It ("should remove the owner reference established by the SetControllerReference function" , func () {
260
+ rs := & appsv1.ReplicaSet {}
261
+ dep := & extensionsv1beta1.Deployment {
262
+ ObjectMeta : metav1.ObjectMeta {Name : "foo" , UID : "foo-uid" },
263
+ }
264
+
265
+ Expect (controllerutil .SetControllerReference (dep , rs , scheme .Scheme )).NotTo (HaveOccurred ())
266
+ t := true
267
+ Expect (rs .OwnerReferences ).To (ConsistOf (metav1.OwnerReference {
268
+ Name : "foo" ,
269
+ Kind : "Deployment" ,
270
+ APIVersion : "extensions/v1beta1" ,
271
+ UID : "foo-uid" ,
272
+ Controller : & t ,
273
+ BlockOwnerDeletion : & t ,
274
+ }))
275
+
276
+ Expect (controllerutil .RemoveControllerReference (dep , rs )).NotTo (HaveOccurred ())
277
+ })
278
+ It ("should fail and return an error if the length is less than 1" , func () {
279
+ rs := & appsv1.ReplicaSet {}
280
+ dep := & extensionsv1beta1.Deployment {
281
+ ObjectMeta : metav1.ObjectMeta {Name : "foo" , UID : "foo-uid" },
282
+ }
283
+ Expect (controllerutil .RemoveControllerReference (dep , rs )).To (HaveOccurred ())
284
+ })
285
+ It ("should fail and return an error because the owner doesn't exist to remove" , func () {
286
+ rs := & appsv1.ReplicaSet {}
287
+ dep := & extensionsv1beta1.Deployment {
288
+ ObjectMeta : metav1.ObjectMeta {Name : "foo" , UID : "foo-uid" },
289
+ }
290
+ dep2 := & extensionsv1beta1.Deployment {
291
+ ObjectMeta : metav1.ObjectMeta {Name : "bar" , UID : "bar-uid" },
292
+ }
293
+ Expect (controllerutil .SetControllerReference (dep , rs , scheme .Scheme )).NotTo (HaveOccurred ())
294
+ Expect (controllerutil .RemoveControllerReference (dep2 , rs )).To (HaveOccurred ())
295
+ })
296
+
297
+ })
259
298
260
299
Describe ("CreateOrUpdate" , func () {
261
300
var deploy * appsv1.Deployment
0 commit comments