@@ -13,10 +13,10 @@ import (
1313
1414// mockRoute53Client implements Route53ClientAPI for testing.
1515type mockRoute53Client struct {
16- listHostedZonesFunc func (ctx context.Context , params * route53.ListHostedZonesInput , optFns ... func (* route53.Options )) (* route53.ListHostedZonesOutput , error )
17- listResourceRecordSetsFunc func (ctx context.Context , params * route53.ListResourceRecordSetsInput , optFns ... func (* route53.Options )) (* route53.ListResourceRecordSetsOutput , error )
16+ listHostedZonesFunc func (ctx context.Context , params * route53.ListHostedZonesInput , optFns ... func (* route53.Options )) (* route53.ListHostedZonesOutput , error )
17+ listResourceRecordSetsFunc func (ctx context.Context , params * route53.ListResourceRecordSetsInput , optFns ... func (* route53.Options )) (* route53.ListResourceRecordSetsOutput , error )
1818 changeResourceRecordSetsFunc func (ctx context.Context , params * route53.ChangeResourceRecordSetsInput , optFns ... func (* route53.Options )) (* route53.ChangeResourceRecordSetsOutput , error )
19- getChangeFunc func (ctx context.Context , params * route53.GetChangeInput , optFns ... func (* route53.Options )) (* route53.GetChangeOutput , error )
19+ getChangeFunc func (ctx context.Context , params * route53.GetChangeInput , optFns ... func (* route53.Options )) (* route53.GetChangeOutput , error )
2020}
2121
2222func (m * mockRoute53Client ) ListHostedZones (ctx context.Context , params * route53.ListHostedZonesInput , optFns ... func (* route53.Options )) (* route53.ListHostedZonesOutput , error ) {
@@ -49,17 +49,17 @@ func TestListHostedZones_Success(t *testing.T) {
4949 return & route53.ListHostedZonesOutput {
5050 HostedZones : []r53types.HostedZone {
5151 {
52- Id : awssdk .String ("/hostedzone/Z1234567890" ),
53- Name : awssdk .String ("example.com." ),
52+ Id : awssdk .String ("/hostedzone/Z1234567890" ),
53+ Name : awssdk .String ("example.com." ),
5454 ResourceRecordSetCount : awssdk .Int64 (10 ),
5555 Config : & r53types.HostedZoneConfig {
5656 PrivateZone : false ,
5757 Comment : awssdk .String ("Production zone" ),
5858 },
5959 },
6060 {
61- Id : awssdk .String ("/hostedzone/Z0987654321" ),
62- Name : awssdk .String ("internal.example.com." ),
61+ Id : awssdk .String ("/hostedzone/Z0987654321" ),
62+ Name : awssdk .String ("internal.example.com." ),
6363 ResourceRecordSetCount : awssdk .Int64 (5 ),
6464 Config : & r53types.HostedZoneConfig {
6565 PrivateZone : true ,
@@ -144,10 +144,10 @@ func TestListHostedZones_NilConfig(t *testing.T) {
144144 return & route53.ListHostedZonesOutput {
145145 HostedZones : []r53types.HostedZone {
146146 {
147- Id : awssdk .String ("/hostedzone/Z111" ),
148- Name : awssdk .String ("noconfig.com." ),
147+ Id : awssdk .String ("/hostedzone/Z111" ),
148+ Name : awssdk .String ("noconfig.com." ),
149149 ResourceRecordSetCount : awssdk .Int64 (1 ),
150- Config : nil ,
150+ Config : nil ,
151151 },
152152 },
153153 IsTruncated : false ,
@@ -171,6 +171,32 @@ func TestListHostedZones_NilConfig(t *testing.T) {
171171 }
172172}
173173
174+ func TestListHostedZones_SortedByName (t * testing.T ) {
175+ mock := & mockRoute53Client {
176+ listHostedZonesFunc : func (_ context.Context , _ * route53.ListHostedZonesInput , _ ... func (* route53.Options )) (* route53.ListHostedZonesOutput , error ) {
177+ return & route53.ListHostedZonesOutput {
178+ HostedZones : []r53types.HostedZone {
179+ {Id : awssdk .String ("/hostedzone/Z2" ), Name : awssdk .String ("zeta.example.com." )},
180+ {Id : awssdk .String ("/hostedzone/Z1" ), Name : awssdk .String ("alpha.example.com." )},
181+ },
182+ IsTruncated : false ,
183+ }, nil
184+ },
185+ }
186+
187+ repo := & AwsRepository {Route53Client : mock }
188+ zones , err := repo .ListHostedZones (context .Background ())
189+ if err != nil {
190+ t .Fatalf ("unexpected error: %v" , err )
191+ }
192+ if len (zones ) != 2 {
193+ t .Fatalf ("expected 2 zones, got %d" , len (zones ))
194+ }
195+ if zones [0 ].Name != "alpha.example.com." || zones [1 ].Name != "zeta.example.com." {
196+ t .Fatalf ("expected alphabetical hosted zone order, got %+v" , zones )
197+ }
198+ }
199+
174200// --- ListResourceRecordSets tests ---
175201
176202func TestListResourceRecordSets_Success (t * testing.T ) {
0 commit comments