@@ -295,6 +295,58 @@ func TestResourceAndNonResourceRuleSplit(t *testing.T) {
295
295
}
296
296
}
297
297
298
+ func TestAnnotationsConversion (t * testing.T ) {
299
+ for _ , boolval := range []string {"true" , "false" } {
300
+ ocr := & authorizationapi.ClusterRole {
301
+ Rules : []authorizationapi.PolicyRule {},
302
+ }
303
+ ocr .Annotations = map [string ]string {"openshift.io/reconcile-protect" : boolval }
304
+ ocr2 := & authorizationapi.ClusterRole {}
305
+ crcr := & rbac.ClusterRole {}
306
+ if err := authorizationapi .Convert_authorization_ClusterRole_To_rbac_ClusterRole (ocr , crcr , nil ); err != nil {
307
+ t .Fatal (err )
308
+ }
309
+ value , ok := crcr .Annotations [rbac .AutoUpdateAnnotationKey ]
310
+ if ok {
311
+ if (boolval == "true" && value != "false" ) || (boolval == "false" && value != "true" ) {
312
+ t .Fatal (fmt .Errorf ("Wrong conversion value, 'true' instead of 'false'" ))
313
+ }
314
+ } else {
315
+ t .Fatal (fmt .Errorf ("Missing converted Annotation" ))
316
+ }
317
+ if err := authorizationapi .Convert_rbac_ClusterRole_To_authorization_ClusterRole (crcr , ocr2 , nil ); err != nil {
318
+ t .Fatal (err )
319
+ }
320
+ if ! reflect .DeepEqual (ocr , ocr2 ) {
321
+ t .Errorf ("origin cluster data not preserved; the diff is %s" , diff .ObjectDiff (ocr , ocr2 ))
322
+ }
323
+
324
+ rcr := & rbac.ClusterRole {
325
+ Rules : []rbac.PolicyRule {},
326
+ }
327
+ rcr .Annotations = map [string ]string {rbac .AutoUpdateAnnotationKey : boolval }
328
+ rcr2 := & rbac.ClusterRole {}
329
+ cocr := & authorizationapi.ClusterRole {}
330
+ if err := authorizationapi .Convert_rbac_ClusterRole_To_authorization_ClusterRole (rcr , cocr , nil ); err != nil {
331
+ t .Fatal (err )
332
+ }
333
+ value , ok = cocr .Annotations ["openshift.io/reconcile-protect" ]
334
+ if ok {
335
+ if (boolval == "true" && value != "false" ) || (boolval == "false" && value != "true" ) {
336
+ t .Fatal (fmt .Errorf ("Wrong conversion value, 'true' instead of 'false'" ))
337
+ }
338
+ } else {
339
+ t .Fatal (fmt .Errorf ("Missing converted Annotation" ))
340
+ }
341
+ if err := authorizationapi .Convert_authorization_ClusterRole_To_rbac_ClusterRole (cocr , rcr2 , nil ); err != nil {
342
+ t .Fatal (err )
343
+ }
344
+ if ! reflect .DeepEqual (rcr , rcr2 ) {
345
+ t .Errorf ("rbac cluster data not preserved; the diff is %s" , diff .ObjectDiff (rcr , rcr2 ))
346
+ }
347
+ }
348
+ }
349
+
298
350
var fuzzer = fuzz .New ().NilChance (0 ).Funcs (
299
351
func (* metav1.TypeMeta , fuzz.Continue ) {}, // Ignore TypeMeta
300
352
func (* runtime.Object , fuzz.Continue ) {}, // Ignore AttributeRestrictions since they are deprecated
0 commit comments