@@ -65,6 +65,66 @@ func TestIsKROOwned(t *testing.T) {
65
65
}
66
66
}
67
67
68
+ func TestHasMatchingKROOwner (t * testing.T ) {
69
+ cases := []struct {
70
+ name string
71
+ aOwnerName string
72
+ aOwnerID string
73
+ bOwnerName string
74
+ bOwnerID string
75
+ expected bool
76
+ }{
77
+ {
78
+ name : "matching owners" ,
79
+ aOwnerName : "test-rgd" ,
80
+ aOwnerID : "test-uid-123" ,
81
+ bOwnerName : "test-rgd" ,
82
+ bOwnerID : "test-uid-123" ,
83
+ expected : true ,
84
+ },
85
+ {
86
+ name : "different owner names" ,
87
+ aOwnerName : "test-rgd-a" ,
88
+ aOwnerID : "test-uid-123" ,
89
+ bOwnerName : "test-rgd-b" ,
90
+ bOwnerID : "test-uid-123" ,
91
+ expected : false ,
92
+ },
93
+ {
94
+ name : "different owner IDs" ,
95
+ aOwnerName : "test-rgd" ,
96
+ aOwnerID : "test-uid-123" ,
97
+ bOwnerName : "test-rgd" ,
98
+ bOwnerID : "test-uid-456" ,
99
+ expected : false ,
100
+ },
101
+ {
102
+ name : "no owner labels" ,
103
+ expected : true ,
104
+ },
105
+ }
106
+
107
+ for _ , tc := range cases {
108
+ t .Run (tc .name , func (t * testing.T ) {
109
+ labelsA := map [string ]string {}
110
+ labelsB := map [string ]string {}
111
+ if tc .aOwnerName != "" {
112
+ labelsA [ResourceGraphDefinitionNameLabel ] = tc .aOwnerName
113
+ labelsA [ResourceGraphDefinitionIDLabel ] = tc .aOwnerID
114
+ }
115
+ if tc .bOwnerName != "" {
116
+ labelsB [ResourceGraphDefinitionNameLabel ] = tc .bOwnerName
117
+ labelsB [ResourceGraphDefinitionIDLabel ] = tc .bOwnerID
118
+ }
119
+
120
+ metaA := metav1.ObjectMeta {Labels : labelsA }
121
+ metaB := metav1.ObjectMeta {Labels : labelsB }
122
+ result := HasMatchingKROOwner (metaA , metaB )
123
+ assert .Equal (t , tc .expected , result )
124
+ })
125
+ }
126
+ }
127
+
68
128
func TestSetKROOwned (t * testing.T ) {
69
129
cases := []struct {
70
130
name string
0 commit comments