-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…708) * Adding retry logic for #655 and add tests for delete_default_vpc.py * Proper logging * Adopt tenacity in favor of retrying * Max retry logic and exponential backoff intervals * Change logging msg to DEBUG and add meaningfull msg * Mock nap.time.sleep for faster tests * Update src/lambda_codebase/account_processing/tests/test_delete_default_vpc.py --------- Co-authored-by: Javy de Koning Co-authored-by: Stewart Wallace Co-authored-by: Simon Kok
- Loading branch information
1 parent
325c960
commit 32e9ecf
Showing
4 changed files
with
79 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
aws-xray-sdk==2.13.0 | ||
pyyaml~=6.0.1 | ||
tenacity==8.2.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/lambda_codebase/account_processing/tests/test_delete_default_vpc.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Copyright Amazon.com Inc. or its affiliates. | ||
# SPDX-License-Identifier: MIT-0 | ||
|
||
""" | ||
Tests the delete_default_vpc lambda | ||
""" | ||
|
||
import unittest | ||
from unittest.mock import MagicMock, patch | ||
from delete_default_vpc import find_default_vpc | ||
from botocore.exceptions import ClientError | ||
|
||
|
||
class TestFindDefaultVPC(unittest.TestCase): | ||
|
||
@patch("tenacity.nap.time.sleep", MagicMock()) | ||
@patch('delete_default_vpc.patch_all') | ||
# pylint: disable=unused-argument | ||
def test_find_default_vpc(self, mock_patch_all): | ||
# Create a mock ec2_client | ||
mock_ec2_client = MagicMock() | ||
|
||
# Define the side effects for describe_vpcs method | ||
side_effects = [ | ||
ClientError({'Error': {'Code': 'MockTestError'}}, 'describe_vpcs'), | ||
ClientError({'Error': {'Code': 'MockTestError'}}, 'describe_vpcs'), | ||
{"Vpcs": [ | ||
{"VpcId": "vpc-123", "IsDefault": False}, | ||
{"VpcId": "vpc-456", "IsDefault": True}, | ||
{"VpcId": "vpc-789", "IsDefault": False} | ||
]} | ||
] | ||
|
||
# Set side_effect for the mock ec2_client.describe_vpcs | ||
mock_ec2_client.describe_vpcs.side_effect = side_effects | ||
|
||
# Call the function with the mock ec2_client | ||
default_vpc_id = find_default_vpc(mock_ec2_client) | ||
|
||
# Check if the correct default VPC ID is returned | ||
self.assertEqual(default_vpc_id, "vpc-456") | ||
|
||
# Check if describe_vpcs method is called 3 times | ||
self.assertEqual(mock_ec2_client.describe_vpcs.call_count, 3) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |