Skip to content

Commit

Permalink
Add Route53
Browse files Browse the repository at this point in the history
  • Loading branch information
james03160927 committed Jul 23, 2024
1 parent 609f0c7 commit e9e4b65
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
20 changes: 15 additions & 5 deletions modules/aws/route53.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ import (
"github.com/stretchr/testify/require"
)

func GetRoute53Record(t *testing.T, hostedZoneID, recordName, awsRegion string) *route53.ResourceRecordSet {
r, err := GetRoute53RecordE(t, hostedZoneID, recordName, awsRegion)
// GetRoute53Record returns a Route 53 Record
func GetRoute53Record(t *testing.T, hostedZoneID, recordName, recordType, awsRegion string) *route53.ResourceRecordSet {
r, err := GetRoute53RecordE(t, hostedZoneID, recordName, recordType, awsRegion)
require.NoError(t, err)

return r
}

func GetRoute53RecordE(t *testing.T, hostedZoneID, recordName, awsRegion string) (record *route53.ResourceRecordSet, err error) {
// GetRoute53RecordE returns a Route 53 Record
func GetRoute53RecordE(t *testing.T, hostedZoneID, recordName, recordType, awsRegion string) (record *route53.ResourceRecordSet, err error) {
route53Client, err := NewRoute53ClientE(t, awsRegion)
if err != nil {
return nil, err
Expand All @@ -26,7 +28,7 @@ func GetRoute53RecordE(t *testing.T, hostedZoneID, recordName, awsRegion string)
o, err := route53Client.ListResourceRecordSets(&route53.ListResourceRecordSetsInput{
HostedZoneId: &hostedZoneID,
StartRecordName: &recordName,
StartRecordType: proto.String("A"),
StartRecordType: &recordType,
MaxItems: proto.String("1"),
})
if err != nil {
Expand All @@ -44,7 +46,15 @@ func GetRoute53RecordE(t *testing.T, hostedZoneID, recordName, awsRegion string)
return
}

// NewS3ClientE creates an S3 client.
// NewRoute53ClientE creates a route 53 client.
func NewRoute53Client(t *testing.T, region string) *route53.Route53 {
c, err := NewRoute53ClientE(t, region)
require.NoError(t, err)

return c
}

// NewRoute53ClientE creates a route 53 client.
func NewRoute53ClientE(t *testing.T, region string) (*route53.Route53, error) {
sess, err := NewAuthenticatedSession(region)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions modules/aws/route53_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ func TestRoute53Record(t *testing.T) {
})

t.Run("ExistingRecord", func(t *testing.T) {
route53Record := GetRoute53Record(t, *hostedZone.HostedZone.Id, recordName, region)
route53Record := GetRoute53Record(t, *hostedZone.HostedZone.Id, recordName, *resourceRecordSet.Type, region)
require.NotNil(t, route53Record)
assert.Equal(t, recordName+".", *route53Record.Name)
assert.Equal(t, "A", *route53Record.Type)
assert.Equal(t, *resourceRecordSet.Type, *route53Record.Type)
assert.Equal(t, "127.0.0.1", *route53Record.ResourceRecords[0].Value)
})

t.Run("NotExistRecord", func(t *testing.T) {
route53Record, err := GetRoute53RecordE(t, *hostedZone.HostedZone.Id, "ne"+recordName, region)
route53Record, err := GetRoute53RecordE(t, *hostedZone.HostedZone.Id, "ne"+recordName, "A", region)
assert.Error(t, err)
assert.Nil(t, route53Record)
})
Expand Down

0 comments on commit e9e4b65

Please sign in to comment.