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: move data conversion code to internal/converters #473

Merged
merged 1 commit into from
Dec 7, 2023

Conversation

t0mk
Copy link
Contributor

@t0mk t0mk commented Dec 4, 2023

This PR is part of a refactoring effort (#106). It moves some helper code to another internal subpackage.

@codecov-commenter
Copy link

codecov-commenter commented Dec 4, 2023

Codecov Report

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

Comparison is base (26b2f3d) 60.11% compared to head (9a838bb) 59.64%.
Report is 83 commits behind head on main.

Files Patch % Lines
equinix/fabric_mapping_helper.go 0.00% 54 Missing ⚠️
equinix/resource_fabric_cloud_router.go 0.00% 32 Missing ⚠️
equinix/resource_fabric_connection.go 0.00% 28 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_vlan.go 43.75% 8 Missing and 1 partial ⚠️
... and 40 more

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

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #473      +/-   ##
==========================================
- Coverage   60.11%   59.64%   -0.48%     
==========================================
  Files          99       95       -4     
  Lines       20045    19752     -293     
==========================================
- Hits        12051    11782     -269     
+ Misses       7691     7679      -12     
+ Partials      303      291      -12     

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

@@ -11,7 +11,7 @@ import (
// and invert it if the result is negative.
//
// Originally from https://github.com/hashicorp/terraform-plugin-sdk/blob/main/internal/helper/hashcode/hashcode.go
func hashcodeString(s string) int {
func HashcodeString(s string) int {
Copy link
Contributor

Choose a reason for hiding this comment

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

We could move this to a hash or hashcode package and rename to String


import (
"strconv"
"strings"
)

func contains(s []string, e string) bool {
func Contains(s []string, e string) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

If we build on go 1.21 instead of 1.20 we could replace this with usage of the slices standard package (even if we don't upgrade, we could use x/exp/slices.

Copy link
Contributor

Choose a reason for hiding this comment

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

Replacement of this function could be saved for a later change, but if we opt to keep this implementation of Contains, I think it would fit better in a package named slices, since it isn't converting anything.

var arr []interface{}
for _, v := range sli {
arr = append(arr, v)
}
return arr
}

func convertStringArr(ifaceArr []interface{}) []string {
func ConvertStringArr(ifaceArr []interface{}) []string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's take this opportunity to improve these function names. StringArrToIfArr is a nice, descriptive name, and if we follow that model here, this function would be called IfArrtoStringArr

@@ -33,7 +33,7 @@ func convertStringArr(ifaceArr []interface{}) []string {
return arr
}

func convertIntArr(ifaceArr []interface{}) []string {
func ConvertIntArr(ifaceArr []interface{}) []string {
Copy link
Contributor

Choose a reason for hiding this comment

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

This would be IfArrToIntStringArr (or can it be safely replaced with usage of other converters?)

@@ -44,7 +44,7 @@ func convertIntArr(ifaceArr []interface{}) []string {
return arr
}

func convertIntArr2(ifaceArr []interface{}) []int {
func ConvertIntArr2(ifaceArr []interface{}) []int {
Copy link
Contributor

Choose a reason for hiding this comment

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

This would be IfArrToIntArr

@t0mk
Copy link
Contributor Author

t0mk commented Dec 6, 2023

@ctreatma I fixed your review comments.

@t0mk
Copy link
Contributor Author

t0mk commented Dec 6, 2023

@ctreatma I remove hashcode.go from equinix/ and fixed all the places where it was used.

@ctreatma
Copy link
Contributor

ctreatma commented Dec 6, 2023

@t0mk could you push up that change? GitHub still shows the old commit with both hashcode copies.

@t0mk
Copy link
Contributor Author

t0mk commented Dec 7, 2023

@ctreatma , sorry, I pushed it now. It should be ready for review again.

@ctreatma ctreatma merged commit 8ff7a88 into main Dec 7, 2023
4 of 5 checks passed
@ctreatma ctreatma deleted the move_more_utils_to_internal branch December 7, 2023 15:18
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.

None yet

3 participants