Skip to content

Commit 2e4e389

Browse files
committed
Cleanup tests
1 parent 9f8cbfe commit 2e4e389

File tree

3 files changed

+15
-56
lines changed

3 files changed

+15
-56
lines changed

test/component_test.go

Lines changed: 12 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ import (
1515

1616
"github.com/stretchr/testify/assert"
1717

18-
"github.com/aws/aws-sdk-go-v2/aws"
19-
"github.com/aws/aws-sdk-go-v2/service/route53"
20-
"github.com/aws/aws-sdk-go-v2/service/route53/types"
2118
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2219
"k8s.io/apimachinery/pkg/runtime/schema"
2320
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -144,23 +141,27 @@ func (s *ComponentSuite) TestBasic() {
144141
return
145142
}
146143

147-
observedGeneration, found, err := unstructured.NestedInt64(newDNS.Object, "status", "observedGeneration")
144+
name, found, err := unstructured.NestedString(newDNS.Object, "metadata", "name")
148145
if err != nil {
149-
fmt.Printf("Error getting status: %v\n", err)
146+
fmt.Printf("Error getting name: %v\n", err)
150147
return
151148
}
152149
if !found {
153-
fmt.Printf("Status not found\n")
150+
fmt.Printf("Name not found\n")
151+
return
152+
}
153+
if name != dnsEndpointName {
154+
fmt.Printf("DNS record is not %s\n", dnsEndpointName)
154155
return
155156
}
156157

157-
name, found, err := unstructured.NestedString(newDNS.Object, "metadata", "name")
158+
observedGeneration, found, err := unstructured.NestedInt64(newDNS.Object, "status", "observedGeneration")
158159
if err != nil {
159-
fmt.Printf("Error getting name: %v\n", err)
160+
fmt.Printf("Error getting status: %v\n", err)
160161
return
161162
}
162163
if !found {
163-
fmt.Printf("Name not found\n")
164+
fmt.Printf("Status not found\n")
164165
return
165166
}
166167

@@ -186,54 +187,10 @@ func (s *ComponentSuite) TestBasic() {
186187
delegatedNSRecord := awsTerratest.GetRoute53Record(s.T(), defaultDNSZoneId, dnsRecordHostName, "A", awsRegion)
187188
assert.Equal(s.T(), fmt.Sprintf("%s.", dnsRecordHostName), *delegatedNSRecord.Name)
188189

189-
190190
defer func() {
191-
route53Client, err := awsTerratest.NewRoute53ClientE(s.T(), awsRegion)
192-
if err != nil {
193-
return
191+
if err := awsHelper.CleanDNSZoneID(s.T(), context.Background(), defaultDNSZoneId, awsRegion); err != nil {
192+
fmt.Printf("Error cleaning DNS zone %s: %v\n", defaultDNSZoneId, err)
194193
}
195-
196-
o, err := route53Client.ListResourceRecordSets(context.Background(), &route53.ListResourceRecordSetsInput{
197-
HostedZoneId: &defaultDNSZoneId,
198-
MaxItems: aws.Int32(100),
199-
})
200-
if err != nil {
201-
return
202-
}
203-
204-
var changes []types.Change
205-
206-
for _, record := range o.ResourceRecordSets {
207-
208-
if record.Type == types.RRTypeNs || record.Type == types.RRTypeSoa {
209-
continue
210-
}
211-
// Build a deletion change for each record
212-
changes = append(changes, types.Change{
213-
Action: types.ChangeActionDelete,
214-
ResourceRecordSet: &record,
215-
})
216-
}
217-
218-
if len(changes) == 0 {
219-
fmt.Println("No deletable records found.")
220-
return
221-
}
222-
223-
// Prepare the change batch
224-
changeBatch := &types.ChangeBatch{
225-
Changes: changes,
226-
}
227-
228-
// Call ChangeResourceRecordSets to delete the records
229-
changeInput := &route53.ChangeResourceRecordSetsInput{
230-
HostedZoneId: aws.String(defaultDNSZoneId),
231-
ChangeBatch: changeBatch,
232-
}
233-
234-
_, err = route53Client.ChangeResourceRecordSets(context.Background(), changeInput)
235-
assert.NoError(s.T(), err)
236-
237194
}()
238195

239196
s.DriftTest(component, stack, &inputs)

test/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.24.0
55
toolchain go1.24.1
66

77
require (
8-
github.com/cloudposse/test-helpers v0.22.1-0.20250325083919-2452aea08a23
8+
github.com/cloudposse/test-helpers v0.22.1-0.20250326115004-9e5a8774b3c1
99
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
1010
github.com/gruntwork-io/terratest v0.48.2
1111
github.com/mattn/go-zglob v0.0.6 // indirect

test/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ github.com/cloudposse/test-helpers v0.22.1-0.20250324180101-e380ecb769de h1:xxaJ
127127
github.com/cloudposse/test-helpers v0.22.1-0.20250324180101-e380ecb769de/go.mod h1:UmmPgiLL44aJe9E98xXFn+y5aybGsU4l6pJ3iQZvmJ0=
128128
github.com/cloudposse/test-helpers v0.22.1-0.20250325083919-2452aea08a23 h1:mI+w8PJX2ryIzh5HvUBac0N1JLRjeH/Zc6l/wcbn7OQ=
129129
github.com/cloudposse/test-helpers v0.22.1-0.20250325083919-2452aea08a23/go.mod h1:UmmPgiLL44aJe9E98xXFn+y5aybGsU4l6pJ3iQZvmJ0=
130+
github.com/cloudposse/test-helpers v0.22.1-0.20250326115004-9e5a8774b3c1 h1:Pp00IP/ERAO4+Awj43LVNiNXuS+K0ljhe7W501352FM=
131+
github.com/cloudposse/test-helpers v0.22.1-0.20250326115004-9e5a8774b3c1/go.mod h1:UmmPgiLL44aJe9E98xXFn+y5aybGsU4l6pJ3iQZvmJ0=
130132
github.com/cpuguy83/go-md2man/v2 v2.0.6 h1:XJtiaUW6dEEqVuZiMTn1ldk455QWwEIsMIJlo5vtkx0=
131133
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
132134
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

0 commit comments

Comments
 (0)