@@ -266,7 +266,7 @@ func TestLeaseConversion(t *testing.T) {
266266 }
267267}
268268
269- func TestUpdateWithNilLabels (t * testing.T ) {
269+ func TestUpdateWithNilLabelsOnLease (t * testing.T ) {
270270 setup ()
271271
272272 // Create initial lease
@@ -278,23 +278,30 @@ func TestUpdateWithNilLabels(t *testing.T) {
278278 t .Fatalf ("Failed to get lease: %v" , err )
279279 }
280280
281- leaseLock .lease . Labels = map [string ]string {"custom-key" : "custom-val" }
281+ leaseLock .Labels = map [string ]string {"custom-key" : "custom-val" }
282282
283- // Update labels
284- lease , err := leaseLock .Client .Leases (testNamespace ).Update (context .Background (), leaseLock .lease , metav1.UpdateOptions {})
285- if err != nil {
286- t .Fatalf ("Failed to update lease labels: %v" , err )
283+ // Update should succeed even with nil Labels on the lease itself
284+ if err := leaseLock .Update (context .Background (), testRecord ); err != nil {
285+ t .Errorf ("Update failed with nil Labels: %v" , err )
287286 }
287+ }
288288
289- val , exists := lease .Labels ["custom-key" ]
290- if ! exists {
291- t .Error ("Label was overidden on the lease" )
289+
290+ func TestUpdateWithNilLabelsOnLeaseLock (t * testing.T ) {
291+ setup ()
292+
293+ // Create initial lease
294+ if err := leaseLock .Create (context .Background (), testRecord ); err != nil {
295+ t .Fatalf ("Failed to create lease: %v" , err )
292296 }
293- if val != "custom-val" {
294- t .Errorf ("Label value mismatch, got %q want %q" , val , "custom-val" )
297+ // Get the lease to initialize leaseLock.lease
298+ if _ , _ , err := leaseLock .Get (context .Background ()); err != nil {
299+ t .Fatalf ("Failed to get lease: %v" , err )
295300 }
296301
297- // Update should succeed even with nil Labels
302+ leaseLock .lease .Labels = map [string ]string {"custom-key" : "custom-val" }
303+
304+ // Update should succeed even with nil Labels on the leaselock
298305 if err := leaseLock .Update (context .Background (), testRecord ); err != nil {
299306 t .Errorf ("Update failed with nil Labels: %v" , err )
300307 }
@@ -364,4 +371,4 @@ func TestLabelUpdate(t *testing.T) {
364371 if val != "custom-val-2" {
365372 t .Errorf ("Label value mismatch, got %q want %q" , val , "custom-val-2" )
366373 }
367- }
374+ }
0 commit comments