@@ -291,14 +291,17 @@ def test_update_entries(self, prefix_list_ipv4, ec2_validator):
291291 assert entry_to_remove not in k8s_cidrs , \
292292 f"Entry { entry_to_remove } should not be in K8s: { k8s_cidrs } "
293293
294- def test_update_tags (self , prefix_list_ipv4 ):
295- """Test updating prefix list tags."""
296- (ref , _ ) = prefix_list_ipv4
294+ def test_update_tags (self , prefix_list_ipv4 , ec2_validator ):
295+ """Test adding, updating, and removing prefix list tags."""
296+ (ref , cr ) = prefix_list_ipv4
297+
298+ # Get the prefix list ID
299+ prefix_list_id = cr ['status' ]['prefixListID' ]
297300
298301 # Get the latest version of the resource to avoid conflicts
299302 cr = k8s .get_resource (ref )
300303
301- # Add a new tag
304+ # ===== TEST 1: Add a new tag =====
302305 new_tag = {
303306 'key' : 'Environment' ,
304307 'value' : 'Test'
@@ -313,14 +316,73 @@ def test_update_tags(self, prefix_list_ipv4):
313316
314317 # Wait for the resource to be synced
315318 assert k8s .wait_on_condition (ref , "ACK.ResourceSynced" , "True" , wait_periods = 5 ), \
316- "Resource did not sync after tag update"
319+ "Resource did not sync after adding tag"
320+
321+ # Get the updated resource
322+ cr = k8s .get_resource (ref )
323+
324+ # Verify tag was added in K8s
325+ tags = cr ['spec' ].get ('tags' , [])
326+ assert any (tag ['key' ] == 'Environment' and tag ['value' ] == 'Test' for tag in tags ), \
327+ "Environment tag should be added in K8s"
328+
329+ # Verify tag was added in AWS
330+ aws_prefix_list = ec2_validator .get_managed_prefix_list (prefix_list_id )
331+ aws_tags = aws_prefix_list .get ('Tags' , [])
332+ assert any (tag ['Key' ] == 'Environment' and tag ['Value' ] == 'Test' for tag in aws_tags ), \
333+ "Environment tag should be added in AWS"
334+
335+ # ===== TEST 2: Update an existing tag =====
336+ for tag in cr ['spec' ]['tags' ]:
337+ if tag ['key' ] == 'Environment' :
338+ tag ['value' ] = 'Development'
339+
340+ # Apply the update
341+ k8s .patch_custom_resource (ref , cr )
342+ time .sleep (UPDATE_WAIT_AFTER_SECONDS )
343+
344+ # Wait for the resource to be synced
345+ assert k8s .wait_on_condition (ref , "ACK.ResourceSynced" , "True" , wait_periods = 5 ), \
346+ "Resource did not sync after updating tag"
347+
348+ # Get the updated resource
349+ cr = k8s .get_resource (ref )
350+
351+ # Verify tag was updated in K8s
352+ tags = cr ['spec' ].get ('tags' , [])
353+ assert any (tag ['key' ] == 'Environment' and tag ['value' ] == 'Development' for tag in tags ), \
354+ "Environment tag should be updated to Development in K8s"
355+
356+ # Verify tag was updated in AWS
357+ aws_prefix_list = ec2_validator .get_managed_prefix_list (prefix_list_id )
358+ aws_tags = aws_prefix_list .get ('Tags' , [])
359+ assert any (tag ['Key' ] == 'Environment' and tag ['Value' ] == 'Development' for tag in aws_tags ), \
360+ "Environment tag should be updated to Development in AWS"
361+
362+ # ===== TEST 3: Remove a tag =====
363+ cr ['spec' ]['tags' ] = [tag for tag in cr ['spec' ]['tags' ] if tag ['key' ] != 'Environment' ]
364+
365+ # Apply the update
366+ k8s .patch_custom_resource (ref , cr )
367+ time .sleep (UPDATE_WAIT_AFTER_SECONDS )
368+
369+ # Wait for the resource to be synced
370+ assert k8s .wait_on_condition (ref , "ACK.ResourceSynced" , "True" , wait_periods = 5 ), \
371+ "Resource did not sync after removing tag"
317372
318373 # Get the updated resource
319374 cr = k8s .get_resource (ref )
320375
321- # Verify tag was added
376+ # Verify tag was removed in K8s
322377 tags = cr ['spec' ].get ('tags' , [])
323- assert any (tag ['key' ] == 'Environment' and tag ['value' ] == 'Test' for tag in tags )
378+ assert not any (tag ['key' ] == 'Environment' for tag in tags ), \
379+ "Environment tag should be removed from K8s"
380+
381+ # Verify tag was removed in AWS
382+ aws_prefix_list = ec2_validator .get_managed_prefix_list (prefix_list_id )
383+ aws_tags = aws_prefix_list .get ('Tags' , [])
384+ assert not any (tag ['Key' ] == 'Environment' for tag in aws_tags ), \
385+ "Environment tag should be removed from AWS"
324386
325387 def test_prefix_list_fields (self , prefix_list_ipv4 ):
326388 """Test that all expected fields are present."""
0 commit comments