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: remove unnecessary wrappers for getting a random string or int #481

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions equinix/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,14 +446,6 @@ func nprintf(format string, params map[string]interface{}) string {
return format
}

func randInt(n int) int {
return acctest.RandIntRange(0, n)
}

func randString(length int) string {
return acctest.RandString(length)
}

func getFromEnv(varName string) (string, error) {
if v := os.Getenv(varName); v != "" {
return v, nil
Expand Down
41 changes: 21 additions & 20 deletions equinix/resource_ecx_l2_connection_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/equinix/ecx-go/v2"
"github.com/equinix/rest-go"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
Expand Down Expand Up @@ -85,12 +86,12 @@ func TestAccFabricL2Connection_Port_Single_AWS(t *testing.T) {
"port-name": portName.(string),
"connection-resourceName": "test",
"connection-profile_name": spName.(string),
"connection-name": fmt.Sprintf("%s-%s", tstResourcePrefix, randString(6)),
"connection-name": fmt.Sprintf("%s-%s", tstResourcePrefix, acctest.RandString(6)),
"connection-speed": 50,
"connection-speed_unit": "MB",
"connection-notifications": []string{"[email protected]", "[email protected]"},
"connection-purchase_order_number": randString(10),
"connection-vlan_stag": randInt(2000),
"connection-purchase_order_number": acctest.RandString(10),
"connection-vlan_stag": acctest.RandIntRange(0, 2000),
"connection-seller_region": "us-west-1",
"connection-seller_metro_code": "SV",
"connection-authorization_key": authKey.(string),
Expand Down Expand Up @@ -135,21 +136,21 @@ func TestAccFabricL2Connection_Port_HA_Azure(t *testing.T) {
"port-secondary_name": secPortName.(string),
"connection-resourceName": "test",
"connection-profile_name": spName.(string),
"connection-name": fmt.Sprintf("%s-%s", tstResourcePrefix, randString(6)),
"connection-name": fmt.Sprintf("%s-%s", tstResourcePrefix, acctest.RandString(6)),
"connection-speed": 50,
"connection-speed_unit": "MB",
"connection-notifications": []string{"[email protected]", "[email protected]"},
"connection-purchase_order_number": randString(10),
"connection-vlan_stag": randInt(2000),
"connection-purchase_order_number": acctest.RandString(10),
"connection-vlan_stag": acctest.RandIntRange(0, 2000),
"connection-seller_metro_code": "LD",
"connection-authorization_key": serviceKey,
"connection-named_tag": "PRIVATE",
"connection-secondary_name": fmt.Sprintf("%s-%s", tstResourcePrefix, randString(6)),
"connection-secondary_vlan_stag": randInt(2000),
"connection-secondary_name": fmt.Sprintf("%s-%s", tstResourcePrefix, acctest.RandString(6)),
"connection-secondary_vlan_stag": acctest.RandIntRange(0, 2000),
}
contextWithChanges := copyMap(context)
contextWithChanges["connection-name"] = fmt.Sprintf("%s-%s", tstResourcePrefix, randString(6))
contextWithChanges["connection-secondary_name"] = fmt.Sprintf("%s-%s", tstResourcePrefix, randString(6))
contextWithChanges["connection-name"] = fmt.Sprintf("%s-%s", tstResourcePrefix, acctest.RandString(6))
contextWithChanges["connection-secondary_name"] = fmt.Sprintf("%s-%s", tstResourcePrefix, acctest.RandString(6))
resourceName := fmt.Sprintf("equinix_ecx_l2_connection.%s", context["connection-resourceName"].(string))
var primary, secondary ecx.L2Connection
resource.ParallelTest(t, resource.TestCase{
Expand Down Expand Up @@ -207,35 +208,35 @@ func TestAccFabricL2Connection_Device_HA_GCP(t *testing.T) {
"device-account_name": accountName.(string),
"device-self_managed": true,
"device-byol": true,
"device-name": fmt.Sprintf("%s-%s", tstResourcePrefix, randString(6)),
"device-name": fmt.Sprintf("%s-%s", tstResourcePrefix, acctest.RandString(6)),
"device-metro_code": deviceMetro.(string),
"device-type_code": "PA-VM",
"device-package_code": "VM100",
"device-notifications": []string{"[email protected]", "[email protected]"},
"device-hostname": fmt.Sprintf("tf-%s", randString(6)),
"device-hostname": fmt.Sprintf("tf-%s", acctest.RandString(6)),
"device-term_length": 1,
"device-version": "9.0.4",
"device-core_count": 2,
"device-purchase_order_number": randString(10),
"device-order_reference": randString(10),
"device-secondary_name": fmt.Sprintf("%s-%s", tstResourcePrefix, randString(6)),
"device-secondary_hostname": fmt.Sprintf("tf-%s", randString(6)),
"device-purchase_order_number": acctest.RandString(10),
"device-order_reference": acctest.RandString(10),
"device-secondary_name": fmt.Sprintf("%s-%s", tstResourcePrefix, acctest.RandString(6)),
"device-secondary_hostname": fmt.Sprintf("tf-%s", acctest.RandString(6)),
"device-secondary_notifications": []string{"[email protected]"},
"sshkey-resourceName": "test",
"sshkey-name": fmt.Sprintf("%s-%s", tstResourcePrefix, randString(6)),
"sshkey-name": fmt.Sprintf("%s-%s", tstResourcePrefix, acctest.RandString(6)),
"sshkey-public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCXdzXBHaVpKpdO0udnB+4JOgUq7APO2rPXfrevvlZrps98AtlwXXVWZ5duRH5NFNfU4G9HCSiAPsebgjY0fG85tcShpXfHfACLt0tBW8XhfLQP2T6S50FQ1brBdURMDCMsD7duOXqvc0dlbs2/KcswHvuUmqVzob3bz7n1bQ48wIHsPg4ARqYhy5LN3OkllJH/6GEfqi8lKZx01/P/gmJMORcJujuOyXRB+F2iXBVYdhjML3Qg4+tEekBcVZOxUbERRZ0pvQ52Y6wUhn2VsjljixyqeOdmD0m6DayDQgSWms6bKPpBqN7zhXXk4qe8bXT4tQQba65b2CQ2A91jw2KgM/YZNmjyUJ+Rf1cQosJf9twqbAZDZ6rAEmj9zzvQ5vD/CGuzxdVMkePLlUK4VGjPu7cVzhXrnq4318WqZ5/lNiCST8NQ0fssChN8ANUzr/p/wwv3faFMVNmjxXTZMsbMFT/fbb2MVVuqNFN65drntlg6/xEao8gZROuRYiakBx8= user@host",
"connection-resourceName": "test",
"connection-name": fmt.Sprintf("%s-%s", tstResourcePrefix, randString(6)),
"connection-name": fmt.Sprintf("%s-%s", tstResourcePrefix, acctest.RandString(6)),
"connection-profile_name": priSPName.(string),
"connection-speed": 50,
"connection-speed_unit": "MB",
"connection-notifications": []string{"[email protected]", "[email protected]"},
"connection-purchase_order_number": randString(10),
"connection-purchase_order_number": acctest.RandString(10),
"connection-seller_metro_code": "SV",
"connection-seller_region": "us-west2",
"connection-authorization_key": priServiceKey.(string),
"connection-device_interface_id": 5,
"connection-secondary_name": fmt.Sprintf("%s-%s", tstResourcePrefix, randString(6)),
"connection-secondary_name": fmt.Sprintf("%s-%s", tstResourcePrefix, acctest.RandString(6)),
"connection-secondary_profile_name": secSPName.(string),
"connection-secondary_speed": 100,
"connection-secondary_speed_unit": "MB",
Expand Down
103 changes: 52 additions & 51 deletions equinix/resource_ecx_l2_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/equinix/ecx-go/v2"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -69,34 +70,34 @@ func TestFabricL2Connection_updateResourceData(t *testing.T) {
// given
d := schema.TestResourceDataRaw(t, createECXL2ConnectionResourceSchema(), make(map[string]interface{}))
input := &ecx.L2Connection{
UUID: ecx.String(randString(36)),
Name: ecx.String(randString(36)),
ProfileUUID: ecx.String(randString(36)),
UUID: ecx.String(acctest.RandString(36)),
Name: ecx.String(acctest.RandString(36)),
ProfileUUID: ecx.String(acctest.RandString(36)),
Speed: ecx.Int(50),
SpeedUnit: ecx.String("MB"),
Status: ecx.String(ecx.ConnectionStatusProvisioned),
ProviderStatus: ecx.String(ecx.ConnectionStatusProvisioned),
Notifications: []string{"[email protected]"},
PurchaseOrderNumber: ecx.String(randString(10)),
PortUUID: ecx.String(randString(36)),
DeviceUUID: ecx.String(randString(36)),
VendorToken: ecx.String(randString(36)),
VlanSTag: ecx.Int(randInt(2000)),
VlanCTag: ecx.Int(randInt(2000)),
NamedTag: ecx.String(randString(100)),
AdditionalInfo: []ecx.L2ConnectionAdditionalInfo{{Name: ecx.String(randString(10)), Value: ecx.String(randString(10))}},
ZSidePortUUID: ecx.String(randString(36)),
ZSideVlanCTag: ecx.Int(randInt(2000)),
ZSideVlanSTag: ecx.Int(randInt(2000)),
SellerRegion: ecx.String(randString(10)),
SellerMetroCode: ecx.String(randString(2)),
AuthorizationKey: ecx.String(randString(10)),
RedundancyGroup: ecx.String(randString(36)),
RedundancyType: ecx.String(randString(10)),
PurchaseOrderNumber: ecx.String(acctest.RandString(10)),
PortUUID: ecx.String(acctest.RandString(36)),
DeviceUUID: ecx.String(acctest.RandString(36)),
VendorToken: ecx.String(acctest.RandString(36)),
VlanSTag: ecx.Int(acctest.RandIntRange(0, 2000)),
VlanCTag: ecx.Int(acctest.RandIntRange(0, 2000)),
NamedTag: ecx.String(acctest.RandString(100)),
AdditionalInfo: []ecx.L2ConnectionAdditionalInfo{{Name: ecx.String(acctest.RandString(10)), Value: ecx.String(acctest.RandString(10))}},
ZSidePortUUID: ecx.String(acctest.RandString(36)),
ZSideVlanCTag: ecx.Int(acctest.RandIntRange(0, 2000)),
ZSideVlanSTag: ecx.Int(acctest.RandIntRange(0, 2000)),
SellerRegion: ecx.String(acctest.RandString(10)),
SellerMetroCode: ecx.String(acctest.RandString(2)),
AuthorizationKey: ecx.String(acctest.RandString(10)),
RedundancyGroup: ecx.String(acctest.RandString(36)),
RedundancyType: ecx.String(acctest.RandString(10)),
}
prevServiceToken := ecx.String(randString(20))
prevServiceToken := ecx.String(acctest.RandString(20))
d.Set(ecxL2ConnectionSchemaNames["ServiceToken"], prevServiceToken)
prevZsideServiceToken := ecx.String(randString(20))
prevZsideServiceToken := ecx.String(acctest.RandString(20))
d.Set(ecxL2ConnectionSchemaNames["ZSideServiceToken"], prevZsideServiceToken)

// when
Expand Down Expand Up @@ -138,30 +139,30 @@ func TestFabricL2Connection_updateResourceData(t *testing.T) {
func TestFabricL2Connection_flattenSecondary(t *testing.T) {
// given
input := &ecx.L2Connection{
UUID: ecx.String(randString(36)),
Name: ecx.String(randString(36)),
ProfileUUID: ecx.String(randString(36)),
UUID: ecx.String(acctest.RandString(36)),
Name: ecx.String(acctest.RandString(36)),
ProfileUUID: ecx.String(acctest.RandString(36)),
Speed: ecx.Int(50),
SpeedUnit: ecx.String("MB"),
Status: ecx.String(ecx.ConnectionStatusProvisioned),
ProviderStatus: ecx.String(ecx.ConnectionStatusProvisioned),
PortUUID: ecx.String(randString(36)),
DeviceUUID: ecx.String(randString(36)),
VlanSTag: ecx.Int(randInt(2000)),
VlanCTag: ecx.Int(randInt(2000)),
ZSidePortUUID: ecx.String(randString(36)),
ZSideVlanCTag: ecx.Int(randInt(2000)),
ZSideVlanSTag: ecx.Int(randInt(2000)),
SellerRegion: ecx.String(randString(10)),
SellerMetroCode: ecx.String(randString(2)),
AuthorizationKey: ecx.String(randString(10)),
RedundancyGroup: ecx.String(randString(10)),
RedundancyType: ecx.String(randString(10)),
VendorToken: ecx.String(randString(36)),
PortUUID: ecx.String(acctest.RandString(36)),
DeviceUUID: ecx.String(acctest.RandString(36)),
VlanSTag: ecx.Int(acctest.RandIntRange(0, 2000)),
VlanCTag: ecx.Int(acctest.RandIntRange(0, 2000)),
ZSidePortUUID: ecx.String(acctest.RandString(36)),
ZSideVlanCTag: ecx.Int(acctest.RandIntRange(0, 2000)),
ZSideVlanSTag: ecx.Int(acctest.RandIntRange(0, 2000)),
SellerRegion: ecx.String(acctest.RandString(10)),
SellerMetroCode: ecx.String(acctest.RandString(2)),
AuthorizationKey: ecx.String(acctest.RandString(10)),
RedundancyGroup: ecx.String(acctest.RandString(10)),
RedundancyType: ecx.String(acctest.RandString(10)),
VendorToken: ecx.String(acctest.RandString(36)),
}
previousInput := &ecx.L2Connection{
DeviceInterfaceID: ecx.Int(randInt(10)),
ServiceToken: ecx.String(randString(36)),
DeviceInterfaceID: ecx.Int(acctest.RandIntRange(0, 10)),
ServiceToken: ecx.String(acctest.RandString(36)),
}
expected := []interface{}{
map[string]interface{}{
Expand Down Expand Up @@ -246,8 +247,8 @@ func TestFabricL2Connection_flattenAdditionalInfo(t *testing.T) {
// given
input := []ecx.L2ConnectionAdditionalInfo{
{
Name: ecx.String(randString(32)),
Value: ecx.String(randString(32)),
Name: ecx.String(acctest.RandString(32)),
Value: ecx.String(acctest.RandString(32)),
},
}
expected := []interface{}{
Expand All @@ -271,8 +272,8 @@ func TestFabricL2Connection_expandAdditionalInfo(t *testing.T) {
// given
input := schema.NewSet(f, []interface{}{
map[string]interface{}{
ecxL2ConnectionAdditionalInfoSchemaNames["Name"]: randString(36),
ecxL2ConnectionAdditionalInfoSchemaNames["Value"]: randString(36),
ecxL2ConnectionAdditionalInfoSchemaNames["Name"]: acctest.RandString(36),
ecxL2ConnectionAdditionalInfoSchemaNames["Value"]: acctest.RandString(36),
},
})
inputList := input.List()
Expand All @@ -293,16 +294,16 @@ func TestFabricL2Connection_flattenActions(t *testing.T) {
// given
input := []ecx.L2ConnectionAction{
{
Type: ecx.String(randString(32)),
OperationID: ecx.String(randString(32)),
Message: ecx.String(randString(32)),
Type: ecx.String(acctest.RandString(32)),
OperationID: ecx.String(acctest.RandString(32)),
Message: ecx.String(acctest.RandString(32)),
RequiredData: []ecx.L2ConnectionActionData{
{
Key: ecx.String(randString(10)),
Label: ecx.String(randString(10)),
Value: ecx.String(randString(10)),
Key: ecx.String(acctest.RandString(10)),
Label: ecx.String(acctest.RandString(10)),
Value: ecx.String(acctest.RandString(10)),
IsEditable: ecx.Bool(true),
ValidationPattern: ecx.String(randString(10)),
ValidationPattern: ecx.String(acctest.RandString(10)),
},
},
},
Expand Down Expand Up @@ -365,7 +366,7 @@ func TestFabricL2Connection_fillUpdateRequest(t *testing.T) {
// given
updateReq := mockedL2ConnectionUpdateRequest{}
changes := map[string]interface{}{
ecxL2ConnectionSchemaNames["Name"]: randString(32),
ecxL2ConnectionSchemaNames["Name"]: acctest.RandString(32),
ecxL2ConnectionSchemaNames["Speed"]: 50,
ecxL2ConnectionSchemaNames["SpeedUnit"]: "MB",
}
Expand Down
5 changes: 3 additions & 2 deletions equinix/resource_ecx_l2_serviceprofile_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/equinix/terraform-provider-equinix/internal/config"

"github.com/equinix/ecx-go/v2"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
Expand All @@ -17,8 +18,8 @@ func TestAccFabricL2ServiceProfile_Private(t *testing.T) {
secPortName, _ := schema.EnvDefaultFunc(secPortEnvVar, "sit-001-CX-SV5-NL-Dot1q-BO-10G-SEC-JUN-36")()
context := map[string]interface{}{
"resourceName": "test",
"name": fmt.Sprintf("%s-%s", tstResourcePrefix, randString(6)),
"description": randString(100),
"name": fmt.Sprintf("%s-%s", tstResourcePrefix, acctest.RandString(6)),
"description": acctest.RandString(100),
"bandwidth_threshold_notifications": []string{"[email protected]", "[email protected]"},
"profile_statuschange_notifications": []string{"[email protected]", "[email protected]"},
"vc_statuschange_notifications": []string{"[email protected]", "[email protected]"},
Expand Down
11 changes: 6 additions & 5 deletions equinix/resource_network_acl_template_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/equinix/terraform-provider-equinix/internal/config"

"github.com/equinix/ne-go"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)
Expand Down Expand Up @@ -55,13 +56,13 @@ func testSweepNetworkACLTemplate(region string) error {
func TestAccNetworkACLTemplate(t *testing.T) {
context := map[string]interface{}{
"resourceName": "test",
"name": fmt.Sprintf("%s-%s", tstResourcePrefix, randString(6)),
"description": randString(50),
"name": fmt.Sprintf("%s-%s", tstResourcePrefix, acctest.RandString(6)),
"description": acctest.RandString(50),
"inbound_rule_1_subnet": "10.0.0.0/16",
"inbound_rule_1_protocol": "TCP",
"inbound_rule_1_src_port": "any",
"inbound_rule_1_dst_port": "22-23",
"inbound_rule_1_description": randString(50),
"inbound_rule_1_description": acctest.RandString(50),
"inbound_rule_2_subnet": "192.168.16.0/24",
"inbound_rule_2_protocol": "UDP",
"inbound_rule_2_src_port": "any",
Expand All @@ -72,8 +73,8 @@ func TestAccNetworkACLTemplate(t *testing.T) {
"inbound_rule_3_dst_port": "any",
}
contextWithChanges := copyMap(context)
contextWithChanges["description"] = randString(50)
contextWithChanges["inbound_rule_1_description"] = randString(50)
contextWithChanges["description"] = acctest.RandString(50)
contextWithChanges["inbound_rule_1_description"] = acctest.RandString(50)
contextWithChanges["inbound_rule_3_subnet"] = "4.4.4.4/32"
contextWithChanges["inbound_rule_3_protocol"] = "TCP"
contextWithChanges["inbound_rule_3_dst_port"] = "2048"
Expand Down
Loading
Loading