Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Tests for cloudtrail.utils with Improved Mocking and Edge Cas… #9174

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

imSanko
Copy link

@imSanko imSanko commented Dec 27, 2024

Handling:

The current test suite for cloudtrail.utils can be improved with better mocking strategies and additional test cases for edge scenarios. This will increase the robustness and reliability of the codebase.

Issue #9173 , if available:

Description of changes:

GitHub Issue

Title: Enhance Tests for cloudtrail.utils with Improved Mocking and Edge Case Handling


Description:

The current test suite for cloudtrail.utils can be improved with better mocking strategies and additional test cases for edge scenarios. This will increase the robustness and reliability of the codebase.

Changes Implemented:

  1. Replaced manual mocking with the @mock.patch decorator for more explicit and isolated testing.
  2. Added new tests to cover edge cases:
    • Handling of empty responses from get_caller_identity.
    • Invalid ARNs passed to get_account_id_from_arn.
    • Missing trails in the response of describe_trails.
  3. Verified error handling by testing for expected exceptions (KeyError and ValueError) in scenarios with malformed inputs or empty responses.

Example of Improvements:

  • Improved mocking for get_account_id:

    @mock.patch('awscli.customizations.cloudtrail.utils.get_account_id')
    def test_gets_sts_account_id(self, mock_get_account_id):
        mock_get_account_id.return_value = '1234'
        account_id = utils.get_account_id(mock_get_account_id)
        self.assertEqual(account_id, '1234')
  • Edge case testing for invalid ARNs:

    def test_gets_account_id_from_arn_with_invalid_arn(self):
        arn = 'foo:bar:baz'
        with self.assertRaises(IndexError):
            utils.get_account_id_from_arn(arn)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

…e Handling

The current test suite for cloudtrail.utils can be improved with better mocking strategies and additional test cases for edge scenarios. This will increase the robustness and reliability of the codebase.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant