Skip to content

Commit 3d5dae9

Browse files
committed
chore: use shared test constants
Replace repeated hard-coded test literals with named constants to centralize values and reduce duplication. Signed-off-by: Ryan Johnson <ryan@tenthirtyam.org>
1 parent f7e9a9d commit 3d5dae9

4 files changed

Lines changed: 74 additions & 61 deletions

File tree

internal/helper/request_url_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"github.com/stretchr/testify/require"
1212
)
1313

14+
const testMultiPathWithQueryParams = "p1/p2/p3?k1=v1&k2=v2"
15+
1416
func TestConstructRequestURL(t *testing.T) {
1517
t.Parallel()
1618

@@ -75,7 +77,7 @@ func TestAppendQueryParams(t *testing.T) {
7577
"k1": []string{"v1"},
7678
"k2": []string{"v2"},
7779
},
78-
expected: "p1/p2/p3?k1=v1&k2=v2",
80+
expected: testMultiPathWithQueryParams,
7981
},
8082
}
8183

@@ -103,8 +105,8 @@ func TestString(t *testing.T) {
103105
},
104106
{
105107
name: "case for multiple paths and query parameters",
106-
requestURL: "p1/p2/p3?k1=v1&k2=v2",
107-
expected: "p1/p2/p3?k1=v1&k2=v2",
108+
requestURL: testMultiPathWithQueryParams,
109+
expected: testMultiPathWithQueryParams,
108110
},
109111
}
110112

internal/resources/cluster/tkgaws/distribution_flatten_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestFlattenDistribution(t *testing.T) {
3333
OsArch: "amd",
3434
Region: "us-west-2",
3535
Version: "v1.21.2+vmware.1-tkg.2",
36-
ProvisionerCredentialName: "default",
36+
ProvisionerCredentialName: testDefaultID,
3737
},
3838
expected: []interface{}{
3939
map[string]interface{}{
@@ -42,7 +42,7 @@ func TestFlattenDistribution(t *testing.T) {
4242
osArchKey: "amd",
4343
regionKey: "us-west-2",
4444
versionKey: "v1.21.2+vmware.1-tkg.2",
45-
provisionerCredentialKey: "default",
45+
provisionerCredentialKey: testDefaultID,
4646
},
4747
},
4848
},

internal/resources/cluster/tkgaws/settings_flatten_test.go

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,27 @@ func TestFlattenSettings(t *testing.T) {
3333
APIServerPort: 6443,
3434
Pods: []*tkgawsmodel.VmwareTanzuManageV1alpha1ClusterInfrastructureTkgawsNetworkRange{
3535
{
36-
CidrBlocks: "100.96.0.0/11",
36+
CidrBlocks: testPodsCIDRBlock,
3737
},
3838
},
3939
Services: []*tkgawsmodel.VmwareTanzuManageV1alpha1ClusterInfrastructureTkgawsNetworkRange{
4040
{
41-
CidrBlocks: "100.64.0.0/13",
41+
CidrBlocks: testServicesCIDRBlock,
4242
},
4343
},
4444
},
4545
Provider: &tkgawsmodel.VmwareTanzuManageV1alpha1ClusterInfrastructureTkgawsProviderNetwork{
4646
Subnets: []*tkgawsmodel.VmwareTanzuManageV1alpha1ClusterInfrastructureTkgawsSubnet{
4747
{
48-
AvailabilityZone: "us-west-2a",
49-
CidrBlock: "10.0.0.0/16",
50-
ID: "default",
48+
AvailabilityZone: testUsWest2aAvailabilityZone,
49+
CidrBlock: testVpcCIDRBlock,
50+
ID: testDefaultID,
5151
IsPublic: false,
5252
},
5353
},
5454
Vpc: &tkgawsmodel.VmwareTanzuManageV1alpha1ClusterInfrastructureTkgawsVPC{
55-
CidrBlock: "10.0.0.0/16",
56-
ID: "default",
55+
CidrBlock: testVpcCIDRBlock,
56+
ID: testDefaultID,
5757
},
5858
},
5959
},
@@ -67,12 +67,12 @@ func TestFlattenSettings(t *testing.T) {
6767
apiServerPortKey: int32(6443),
6868
podsKey: []interface{}{
6969
map[string]interface{}{
70-
cidrBlocksKey: "100.96.0.0/11",
70+
cidrBlocksKey: testPodsCIDRBlock,
7171
},
7272
},
7373
servicesKey: []interface{}{
7474
map[string]interface{}{
75-
cidrBlocksKey: "100.64.0.0/13",
75+
cidrBlocksKey: testServicesCIDRBlock,
7676
},
7777
},
7878
},
@@ -81,16 +81,16 @@ func TestFlattenSettings(t *testing.T) {
8181
map[string]interface{}{
8282
subnetsKey: []interface{}{
8383
map[string]interface{}{
84-
availabilityZoneKey: "us-west-2a",
85-
subnetCIDRBlockKey: "10.0.0.0/16",
86-
subnetIDKey: "default",
84+
availabilityZoneKey: testUsWest2aAvailabilityZone,
85+
subnetCIDRBlockKey: testVpcCIDRBlock,
86+
subnetIDKey: testDefaultID,
8787
isPublicKey: false,
8888
},
8989
},
9090
vpcKey: []interface{}{
9191
map[string]interface{}{
92-
vpcCIDRBlockKey: "10.0.0.0/16",
93-
vpcIDKey: "default",
92+
vpcCIDRBlockKey: testVpcCIDRBlock,
93+
vpcIDKey: testDefaultID,
9494
},
9595
},
9696
},
@@ -104,14 +104,14 @@ func TestFlattenSettings(t *testing.T) {
104104
name: "normal scenario with security settings data",
105105
input: &tkgawsmodel.VmwareTanzuManageV1alpha1ClusterInfrastructureTkgawsSettings{
106106
Security: &tkgawsmodel.VmwareTanzuManageV1alpha1ClusterInfrastructureTkgawsSecuritySettings{
107-
SSHKey: "jumper_ssh_key-sh-1529663-220321-074908",
107+
SSHKey: testJumperSSHKey,
108108
},
109109
},
110110
expected: []interface{}{
111111
map[string]interface{}{
112112
securityKey: []interface{}{
113113
map[string]interface{}{
114-
sshKey: "jumper_ssh_key-sh-1529663-220321-074908",
114+
sshKey: testJumperSSHKey,
115115
},
116116
},
117117
},
@@ -125,32 +125,32 @@ func TestFlattenSettings(t *testing.T) {
125125
APIServerPort: 6443,
126126
Pods: []*tkgawsmodel.VmwareTanzuManageV1alpha1ClusterInfrastructureTkgawsNetworkRange{
127127
{
128-
CidrBlocks: "100.96.0.0/11",
128+
CidrBlocks: testPodsCIDRBlock,
129129
},
130130
},
131131
Services: []*tkgawsmodel.VmwareTanzuManageV1alpha1ClusterInfrastructureTkgawsNetworkRange{
132132
{
133-
CidrBlocks: "100.64.0.0/13",
133+
CidrBlocks: testServicesCIDRBlock,
134134
},
135135
},
136136
},
137137
Provider: &tkgawsmodel.VmwareTanzuManageV1alpha1ClusterInfrastructureTkgawsProviderNetwork{
138138
Subnets: []*tkgawsmodel.VmwareTanzuManageV1alpha1ClusterInfrastructureTkgawsSubnet{
139139
{
140-
AvailabilityZone: "us-west-2a",
141-
CidrBlock: "10.0.0.0/16",
142-
ID: "default",
140+
AvailabilityZone: testUsWest2aAvailabilityZone,
141+
CidrBlock: testVpcCIDRBlock,
142+
ID: testDefaultID,
143143
IsPublic: false,
144144
},
145145
},
146146
Vpc: &tkgawsmodel.VmwareTanzuManageV1alpha1ClusterInfrastructureTkgawsVPC{
147-
CidrBlock: "10.0.0.0/16",
148-
ID: "default",
147+
CidrBlock: testVpcCIDRBlock,
148+
ID: testDefaultID,
149149
},
150150
},
151151
},
152152
Security: &tkgawsmodel.VmwareTanzuManageV1alpha1ClusterInfrastructureTkgawsSecuritySettings{
153-
SSHKey: "jumper_ssh_key-sh-1529663-220321-074908",
153+
SSHKey: testJumperSSHKey,
154154
},
155155
},
156156
expected: []interface{}{
@@ -162,12 +162,12 @@ func TestFlattenSettings(t *testing.T) {
162162
apiServerPortKey: int32(6443),
163163
podsKey: []interface{}{
164164
map[string]interface{}{
165-
cidrBlocksKey: "100.96.0.0/11",
165+
cidrBlocksKey: testPodsCIDRBlock,
166166
},
167167
},
168168
servicesKey: []interface{}{
169169
map[string]interface{}{
170-
cidrBlocksKey: "100.64.0.0/13",
170+
cidrBlocksKey: testServicesCIDRBlock,
171171
},
172172
},
173173
},
@@ -176,16 +176,16 @@ func TestFlattenSettings(t *testing.T) {
176176
map[string]interface{}{
177177
subnetsKey: []interface{}{
178178
map[string]interface{}{
179-
availabilityZoneKey: "us-west-2a",
180-
subnetCIDRBlockKey: "10.0.0.0/16",
181-
subnetIDKey: "default",
179+
availabilityZoneKey: testUsWest2aAvailabilityZone,
180+
subnetCIDRBlockKey: testVpcCIDRBlock,
181+
subnetIDKey: testDefaultID,
182182
isPublicKey: false,
183183
},
184184
},
185185
vpcKey: []interface{}{
186186
map[string]interface{}{
187-
vpcCIDRBlockKey: "10.0.0.0/16",
188-
vpcIDKey: "default",
187+
vpcCIDRBlockKey: testVpcCIDRBlock,
188+
vpcIDKey: testDefaultID,
189189
},
190190
},
191191
},
@@ -194,7 +194,7 @@ func TestFlattenSettings(t *testing.T) {
194194
},
195195
securityKey: []interface{}{
196196
map[string]interface{}{
197-
sshKey: "jumper_ssh_key-sh-1529663-220321-074908",
197+
sshKey: testJumperSSHKey,
198198
},
199199
},
200200
},

internal/resources/cluster/tkgaws/topology_flatten_test.go

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ import (
1313
tkgawsmodel "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/cluster/tkgaws"
1414
)
1515

16+
const (
17+
testM5LargeInstanceType = "m5.large"
18+
testUSEastAvailabilityZone = "us-east"
19+
testUsWest2aAvailabilityZone = "us-west-2a"
20+
testDefaultID = "default"
21+
testVpcCIDRBlock = "10.0.0.0/16"
22+
testPodsCIDRBlock = "100.96.0.0/11"
23+
testServicesCIDRBlock = "100.64.0.0/13"
24+
testJumperSSHKey = "jumper_ssh_key-sh-1529663-220321-074908"
25+
)
26+
1627
func TestFlattenTopology(t *testing.T) {
1728
t.Parallel()
1829

@@ -46,17 +57,17 @@ func TestFlattenTopology(t *testing.T) {
4657
name: "normal scenario with control plane data of topology",
4758
input: &tkgawsmodel.VmwareTanzuManageV1alpha1ClusterInfrastructureTkgawsTopology{
4859
ControlPlane: &tkgawsmodel.VmwareTanzuManageV1alpha1ClusterInfrastructureTkgawsControlPlane{
49-
AvailabilityZones: []string{"us-east"},
50-
InstanceType: "m5.large",
60+
AvailabilityZones: []string{testUSEastAvailabilityZone},
61+
InstanceType: testM5LargeInstanceType,
5162
HighAvailability: false,
5263
},
5364
},
5465
expected: []interface{}{
5566
map[string]interface{}{
5667
controlPlaneKey: []interface{}{
5768
map[string]interface{}{
58-
availabilityZonesKey: []string{"us-east"},
59-
instanceTypeKey: "m5.large",
69+
availabilityZonesKey: []string{testUSEastAvailabilityZone},
70+
instanceTypeKey: testM5LargeInstanceType,
6071
highAvailabilityKey: false,
6172
},
6273
},
@@ -76,14 +87,14 @@ func TestFlattenTopology(t *testing.T) {
7687
Spec: &nodepoolmodel.VmwareTanzuManageV1alpha1ClusterNodepoolSpec{
7788
WorkerNodeCount: "1",
7889
TkgAws: &nodepoolmodel.VmwareTanzuManageV1alpha1ClusterNodepoolTKGAWSNodepool{
79-
AvailabilityZone: "us-west-2a",
80-
InstanceType: "m5.large",
90+
AvailabilityZone: testUsWest2aAvailabilityZone,
91+
InstanceType: testM5LargeInstanceType,
8192
NodePlacement: []*nodepoolmodel.VmwareTanzuManageV1alpha1ClusterNodepoolTKGAWSNodePlacement{
8293
{
83-
AvailabilityZone: "us-west-2a",
94+
AvailabilityZone: testUsWest2aAvailabilityZone,
8495
},
8596
},
86-
SubnetID: "default",
97+
SubnetID: testDefaultID,
8798
Version: "v1.21.2+vmware.1",
8899
},
89100
},
@@ -106,14 +117,14 @@ func TestFlattenTopology(t *testing.T) {
106117
workerNodeCountKey: "1",
107118
tkgAWSKey: []interface{}{
108119
map[string]interface{}{
109-
nodepoolAvailabilityZoneKey: "us-west-2a",
110-
nodepoolInstanceTypeKey: "m5.large",
120+
nodepoolAvailabilityZoneKey: testUsWest2aAvailabilityZone,
121+
nodepoolInstanceTypeKey: testM5LargeInstanceType,
111122
nodePlacementKey: []interface{}{
112123
map[string]interface{}{
113-
awsAvailabilityZoneKey: "us-west-2a",
124+
awsAvailabilityZoneKey: testUsWest2aAvailabilityZone,
114125
},
115126
},
116-
nodePoolSubnetIDKey: "default",
127+
nodePoolSubnetIDKey: testDefaultID,
117128
nodepoolVersionKey: "v1.21.2+vmware.1",
118129
},
119130
},
@@ -128,8 +139,8 @@ func TestFlattenTopology(t *testing.T) {
128139
name: "normal scenario with all fields of topology data",
129140
input: &tkgawsmodel.VmwareTanzuManageV1alpha1ClusterInfrastructureTkgawsTopology{
130141
ControlPlane: &tkgawsmodel.VmwareTanzuManageV1alpha1ClusterInfrastructureTkgawsControlPlane{
131-
AvailabilityZones: []string{"us-east"},
132-
InstanceType: "m5.large",
142+
AvailabilityZones: []string{testUSEastAvailabilityZone},
143+
InstanceType: testM5LargeInstanceType,
133144
HighAvailability: false,
134145
},
135146
NodePools: []*nodepoolmodel.VmwareTanzuManageV1alpha1ClusterNodepoolDefinition{
@@ -141,14 +152,14 @@ func TestFlattenTopology(t *testing.T) {
141152
Spec: &nodepoolmodel.VmwareTanzuManageV1alpha1ClusterNodepoolSpec{
142153
WorkerNodeCount: "1",
143154
TkgAws: &nodepoolmodel.VmwareTanzuManageV1alpha1ClusterNodepoolTKGAWSNodepool{
144-
AvailabilityZone: "us-west-2a",
145-
InstanceType: "m5.large",
155+
AvailabilityZone: testUsWest2aAvailabilityZone,
156+
InstanceType: testM5LargeInstanceType,
146157
NodePlacement: []*nodepoolmodel.VmwareTanzuManageV1alpha1ClusterNodepoolTKGAWSNodePlacement{
147158
{
148-
AvailabilityZone: "us-west-2a",
159+
AvailabilityZone: testUsWest2aAvailabilityZone,
149160
},
150161
},
151-
SubnetID: "default",
162+
SubnetID: testDefaultID,
152163
Version: "v1.21.2+vmware.1",
153164
},
154165
},
@@ -159,8 +170,8 @@ func TestFlattenTopology(t *testing.T) {
159170
map[string]interface{}{
160171
controlPlaneKey: []interface{}{
161172
map[string]interface{}{
162-
availabilityZonesKey: []string{"us-east"},
163-
instanceTypeKey: "m5.large",
173+
availabilityZonesKey: []string{testUSEastAvailabilityZone},
174+
instanceTypeKey: testM5LargeInstanceType,
164175
highAvailabilityKey: false,
165176
},
166177
},
@@ -177,14 +188,14 @@ func TestFlattenTopology(t *testing.T) {
177188
workerNodeCountKey: "1",
178189
tkgAWSKey: []interface{}{
179190
map[string]interface{}{
180-
nodepoolAvailabilityZoneKey: "us-west-2a",
181-
nodepoolInstanceTypeKey: "m5.large",
191+
nodepoolAvailabilityZoneKey: testUsWest2aAvailabilityZone,
192+
nodepoolInstanceTypeKey: testM5LargeInstanceType,
182193
nodePlacementKey: []interface{}{
183194
map[string]interface{}{
184-
awsAvailabilityZoneKey: "us-west-2a",
195+
awsAvailabilityZoneKey: testUsWest2aAvailabilityZone,
185196
},
186197
},
187-
nodePoolSubnetIDKey: "default",
198+
nodePoolSubnetIDKey: testDefaultID,
188199
nodepoolVersionKey: "v1.21.2+vmware.1",
189200
},
190201
},

0 commit comments

Comments
 (0)