Skip to content

ConversionUtils() unit tests and hardening #472

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

Merged
merged 3 commits into from
Jul 18, 2025
Merged

Conversation

allenrobel
Copy link
Collaborator

Summary

The ConversionUtils class lacked associated unit tests. Adding them now.

Hardening

  • translate_mac_address could throw an unintended TypeError with integer input since the re.sub() was trying to alter the passed mac_addr, which could potentially be an int. Fixed by casting mac_addr to str within the re.sub().

Usability

  • translate_mac_address was returning the altered MAC address in its ValueError which could be confusing to the end user. Fixed by copying the original mac_addr and using the copy in the ValueError.

Updates to other unit tests

Two fabric unit tests started failing after the above changes now that we are using the original MAC address in the ValueError. Fixed the asserts in these to expect the original MAC address.

1. tests/unit/module_utils/common/test_conversion_utils.py

Unit tests for ConversioniUtils()

2. plugins/module_utils/common/conversion.py

2a. translate_mac_address

- Hardening
  - raise ValueError if anything but a string
1. plugins/module_utils/common/conversion.py

1a. translate_mac_address was failing for non-string values.

Fix by convering mac_addr to str before re.sub()

Also, use the original mac_addr rather than the re.sub() version in the ValueError() message.

2. Fix two fabric unit tests

Two unit tests were failing after the change in 1 above.  These were in files:

- tests/unit/modules/dcnm/dcnm_fabric/test_fabric_create.py
- tests/unit/modules/dcnm/dcnm_fabric/test_fabric_create_bulk.py

Fixed these to expect the original mac_addr rather than the re.sub() version.
Adding final unit tests for ConversionUtils().validate_fabric_name
@allenrobel allenrobel self-assigned this Jul 16, 2025
@allenrobel allenrobel added the ready for review PR is ready to be reviewed label Jul 16, 2025
@mikewiebe mikewiebe merged commit 48fbf78 into develop Jul 18, 2025
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for review PR is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants