@@ -182,3 +182,69 @@ func TestGitHubURLTrimLabelValues(t *testing.T) {
182
182
assert .Len (t , listener .Labels [LabelKeyGitHubRepository ], 0 )
183
183
})
184
184
}
185
+
186
+ func TestOwnershipRelationships (t * testing.T ) {
187
+ // Create an AutoscalingRunnerSet
188
+ autoscalingRunnerSet := v1alpha1.AutoscalingRunnerSet {
189
+ ObjectMeta : metav1.ObjectMeta {
190
+ Name : "test-scale-set" ,
191
+ Namespace : "test-ns" ,
192
+ UID : "test-autoscaling-runner-set-uid" ,
193
+ Labels : map [string ]string {
194
+ LabelKeyKubernetesPartOf : labelValueKubernetesPartOf ,
195
+ LabelKeyKubernetesVersion : "0.2.0" ,
196
+ },
197
+ Annotations : map [string ]string {
198
+ runnerScaleSetIdAnnotationKey : "1" ,
199
+ AnnotationKeyGitHubRunnerGroupName : "test-group" ,
200
+ AnnotationKeyGitHubRunnerScaleSetName : "test-scale-set" ,
201
+ annotationKeyValuesHash : "test-hash" ,
202
+ },
203
+ },
204
+ Spec : v1alpha1.AutoscalingRunnerSetSpec {
205
+ GitHubConfigUrl : "https://github.com/org/repo" ,
206
+ },
207
+ }
208
+
209
+ // Initialize ResourceBuilder
210
+ b := ResourceBuilder {}
211
+
212
+ // Create EphemeralRunnerSet
213
+ ephemeralRunnerSet , err := b .newEphemeralRunnerSet (& autoscalingRunnerSet )
214
+ require .NoError (t , err )
215
+
216
+ // Test EphemeralRunnerSet ownership
217
+ require .Len (t , ephemeralRunnerSet .OwnerReferences , 1 , "EphemeralRunnerSet should have exactly one owner reference" )
218
+ ownerRef := ephemeralRunnerSet .OwnerReferences [0 ]
219
+ assert .Equal (t , autoscalingRunnerSet .GetName (), ownerRef .Name , "Owner reference name should match AutoscalingRunnerSet name" )
220
+ assert .Equal (t , autoscalingRunnerSet .GetUID (), ownerRef .UID , "Owner reference UID should match AutoscalingRunnerSet UID" )
221
+ assert .Equal (t , true , * ownerRef .Controller , "Controller flag should be true" )
222
+ assert .Equal (t , true , * ownerRef .BlockOwnerDeletion , "BlockOwnerDeletion flag should be true" )
223
+
224
+ // Create EphemeralRunner
225
+ ephemeralRunner := b .newEphemeralRunner (ephemeralRunnerSet )
226
+
227
+ // Test EphemeralRunner ownership
228
+ require .Len (t , ephemeralRunner .OwnerReferences , 1 , "EphemeralRunner should have exactly one owner reference" )
229
+ ownerRef = ephemeralRunner .OwnerReferences [0 ]
230
+ assert .Equal (t , ephemeralRunnerSet .GetName (), ownerRef .Name , "Owner reference name should match EphemeralRunnerSet name" )
231
+ assert .Equal (t , ephemeralRunnerSet .GetUID (), ownerRef .UID , "Owner reference UID should match EphemeralRunnerSet UID" )
232
+ assert .Equal (t , true , * ownerRef .Controller , "Controller flag should be true" )
233
+ assert .Equal (t , true , * ownerRef .BlockOwnerDeletion , "BlockOwnerDeletion flag should be true" )
234
+
235
+ // Create EphemeralRunnerPod
236
+ runnerSecret := & corev1.Secret {
237
+ ObjectMeta : metav1.ObjectMeta {
238
+ Name : "test-secret" ,
239
+ },
240
+ }
241
+ pod := b .newEphemeralRunnerPod (context .TODO (), ephemeralRunner , runnerSecret )
242
+
243
+ // Test EphemeralRunnerPod ownership
244
+ require .Len (t , pod .OwnerReferences , 1 , "EphemeralRunnerPod should have exactly one owner reference" )
245
+ ownerRef = pod .OwnerReferences [0 ]
246
+ assert .Equal (t , ephemeralRunner .GetName (), ownerRef .Name , "Owner reference name should match EphemeralRunner name" )
247
+ assert .Equal (t , ephemeralRunner .GetUID (), ownerRef .UID , "Owner reference UID should match EphemeralRunner UID" )
248
+ assert .Equal (t , true , * ownerRef .Controller , "Controller flag should be true" )
249
+ assert .Equal (t , true , * ownerRef .BlockOwnerDeletion , "BlockOwnerDeletion flag should be true" )
250
+ }
0 commit comments