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

refactor: clean up config package #480

Merged
merged 2 commits into from
Dec 11, 2023
Merged

refactor: clean up config package #480

merged 2 commits into from
Dec 11, 2023

Conversation

ctreatma
Copy link
Contributor

@ctreatma ctreatma commented Dec 7, 2023

When the config struct was moved to its own package, we added a couple public variables to replace private ones. However, the original private variable definitions were left in place, and all references to the private variables were left unchanged.

On closer inspection, one of the private variables (ipAddressTypes) is only used by one resource and can remain private. The other one (uuidRE) is used for validation that duplicates a built-in terraform validator, so I've replaced it with the built-in validator.

When the config struct was moved to its own package, we added a couple
public variables to replace private ones.  However, the original private
variable definitions were left in place, and all references to the private
variables were left unchanged.

On closer inspection, one of the private variables is only used by one
resource and can remain private, and the other one is for validation, not
configuration.  This moves the validation variable to a validation package
and removes the unused variables.
@codecov-commenter
Copy link

codecov-commenter commented Dec 7, 2023

Codecov Report

Attention: 393 lines in your changes are missing coverage. Please review.

Comparison is base (26b2f3d) 60.11% compared to head (64081e9) 59.39%.
Report is 86 commits behind head on main.

Files Patch % Lines
equinix/fabric_mapping_helper.go 0.00% 68 Missing ⚠️
equinix/resource_fabric_connection.go 0.00% 40 Missing ⚠️
equinix/resource_fabric_cloud_router.go 0.00% 32 Missing ⚠️
equinix/resource_fabric_service_profile.go 0.00% 14 Missing ⚠️
equinix/resource_metal_device.go 78.46% 10 Missing and 4 partials ⚠️
equinix/resource_fabric_routing_protocol.go 0.00% 13 Missing ⚠️
equinix/resource_metal_organization_member.go 40.90% 13 Missing ⚠️
equinix/resource_network_device_link.go 0.00% 10 Missing ⚠️
equinix/resource_metal_connection.go 60.86% 8 Missing and 1 partial ⚠️
equinix/resource_metal_project.go 52.63% 8 Missing and 1 partial ⚠️
... and 41 more

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #480      +/-   ##
==========================================
- Coverage   60.11%   59.39%   -0.73%     
==========================================
  Files          99       95       -4     
  Lines       20045    19769     -276     
==========================================
- Hits        12051    11742     -309     
- Misses       7691     7738      +47     
+ Partials      303      289      -14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -28,11 +28,6 @@ import (
xoauth2 "golang.org/x/oauth2"
)

var (
UuidRE = regexp.MustCompile("^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$")
IpAddressTypes = []string{"public_ipv4", "private_ipv4", "public_ipv6"}
Copy link
Contributor Author

@ctreatma ctreatma Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can see here that the ipAddressTypes private variable is declared in the Metal device resource and only used in device_helpers.go: https://github.com/search?q=repo%3Aequinix%2Fterraform-provider-equinix%20ipAddressTypes&type=code

You can see here that the ipAddressSchema function in device_helpers.go (which is the only place ipAddressTypes is used) is only called by the Metal device resource: https://github.com/search?q=repo%3Aequinix%2Fterraform-provider-equinix%20ipAddressSchema&type=code

When we get to moving the device resource into its own package we should move the ipAddressSchema function with it; I left it as-is for now to avoid making unnecessary changes in this PR.


var (
uuidRE = regexp.MustCompile("^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$")
StringIsUuid = validation.StringMatch(uuidRE, "must be a valid UUID")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The upstream validation.IsUUID covers this need. The Parse function it relies on (from Hashicorp) works with upper, lower, and mixed case.

https://go.dev/play/p/U_z8v_5j2ip

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, I like removing things!

Copy link
Contributor

@t0mk t0mk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good. Is there some way we could detect these orphaned var? Does it show in VScode as unused?

@ctreatma ctreatma merged commit cb9278e into main Dec 11, 2023
5 of 6 checks passed
@ctreatma ctreatma deleted the uuidre_cleanup branch December 11, 2023 15:30
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.

4 participants