@@ -118,26 +118,6 @@ func NewMockCloudFlareClientWithRecords(records map[string][]dns.RecordResponse)
118118 return m
119119}
120120
121- func getDNSRecordFromRecordParams (rp any ) dns.RecordResponse {
122- switch params := rp .(type ) {
123- case cloudflarev0.UpdateDNSRecordParams :
124- record := dns.RecordResponse {
125- ID : params .ID ,
126- Name : params .Name ,
127- TTL : dns .TTL (params .TTL ),
128- Proxied : params .Proxied != nil && * params .Proxied ,
129- Type : dns .RecordResponseType (params .Type ),
130- Content : params .Content ,
131- }
132- if params .Type == "MX" {
133- record .Priority = float64 (* params .Priority )
134- }
135- return record
136- default :
137- return dns.RecordResponse {}
138- }
139- }
140-
141121func generateDNSRecordID (rrtype string , name string , content string ) string {
142122 return fmt .Sprintf ("%s-%s-%s" , name , rrtype , content )
143123}
@@ -189,23 +169,35 @@ func (m *mockCloudFlareClient) ListDNSRecords(ctx context.Context, params dns.Re
189169 return iter
190170}
191171
192- func (m * mockCloudFlareClient ) UpdateDNSRecord (ctx context.Context , rc * cloudflarev0.ResourceContainer , rp cloudflarev0.UpdateDNSRecordParams ) error {
193- recordData := getDNSRecordFromRecordParams (rp )
172+ func (m * mockCloudFlareClient ) UpdateDNSRecord (ctx context.Context , recordID string , params dns.RecordUpdateParams ) (* dns.RecordResponse , error ) {
173+ zoneID := params .ZoneID .String ()
174+ body := params .Body .(dns.RecordUpdateParamsBody )
175+
176+ record := dns.RecordResponse {
177+ ID : recordID ,
178+ Name : body .Name .Value ,
179+ TTL : dns .TTL (body .TTL .Value ),
180+ Proxied : body .Proxied .Value ,
181+ Type : dns .RecordResponseType (body .Type .String ()),
182+ Content : body .Content .Value ,
183+ Priority : body .Priority .Value ,
184+ }
185+
194186 m .Actions = append (m .Actions , MockAction {
195187 Name : "Update" ,
196- ZoneId : rc . Identifier ,
197- RecordId : rp . ID ,
198- RecordData : recordData ,
188+ ZoneId : zoneID ,
189+ RecordId : recordID ,
190+ RecordData : record ,
199191 })
200- if zone , ok := m .Records [rc . Identifier ]; ok {
201- if _ , ok := zone [rp . ID ]; ok {
202- if strings .HasPrefix (recordData .Name , "newerror-update-" ) {
203- return errors .New ("failed to update erroring DNS record" )
192+ if zone , ok := m .Records [zoneID ]; ok {
193+ if _ , ok := zone [recordID ]; ok {
194+ if strings .HasPrefix (record .Name , "newerror-update-" ) {
195+ return nil , errors .New ("failed to update erroring DNS record" )
204196 }
205- zone [rp . ID ] = recordData
197+ zone [recordID ] = record
206198 }
207199 }
208- return nil
200+ return & record , nil
209201}
210202
211203func (m * mockCloudFlareClient ) DeleteDNSRecord (ctx context.Context , recordID string , params dns.RecordDeleteParams ) error {
@@ -3321,6 +3313,33 @@ func TestDnsRecordFromLegacyAPI(t *testing.T) {
33213313 }
33223314}
33233315
3316+ func TestGetUpdateDNSRecordParam (t * testing.T ) {
3317+ cfc := cloudFlareChange {
3318+ ResourceRecord : dns.RecordResponse {
3319+ ID : "1234" ,
3320+ Name : "example.com" ,
3321+ Type : endpoint .RecordTypeA ,
3322+ TTL : 120 ,
3323+ Proxied : true ,
3324+ Content : "1.2.3.4" ,
3325+ Priority : 10 ,
3326+ Comment : "test-comment" ,
3327+ },
3328+ }
3329+
3330+ params := getUpdateDNSRecordParam ("zone-123" , cfc )
3331+ body := params .Body .(dns.RecordUpdateParamsBody )
3332+
3333+ assert .Equal (t , "zone-123" , params .ZoneID .Value )
3334+ assert .Equal (t , "example.com" , body .Name .Value )
3335+ assert .InDelta (t , 120 , float64 (body .TTL .Value ), 0 )
3336+ assert .True (t , body .Proxied .Value )
3337+ assert .EqualValues (t , "A" , body .Type .Value )
3338+ assert .Equal (t , "1.2.3.4" , body .Content .Value )
3339+ assert .InDelta (t , 10 , float64 (body .Priority .Value ), 0 )
3340+ assert .Equal (t , "test-comment" , body .Comment .Value )
3341+ }
3342+
33243343func TestZoneService (t * testing.T ) {
33253344 t .Parallel ()
33263345
@@ -3336,7 +3355,6 @@ func TestZoneService(t *testing.T) {
33363355 }
33373356
33383357 zoneID := "foo"
3339- rc := cloudflarev0 .ZoneIdentifier (zoneID )
33403358
33413359 t .Run ("ListDNSRecord" , func (t * testing.T ) {
33423360 t .Parallel ()
@@ -3356,9 +3374,8 @@ func TestZoneService(t *testing.T) {
33563374
33573375 t .Run ("UpdateDNSRecord" , func (t * testing.T ) {
33583376 t .Parallel ()
3359- params := updateDNSRecordParam (cloudFlareChange {})
3360- params .ID = "1234"
3361- err := client .UpdateDNSRecord (ctx , rc , params )
3377+ recordParam := getUpdateDNSRecordParam (zoneID , cloudFlareChange {})
3378+ _ , err := client .UpdateDNSRecord (ctx , "1234" , recordParam )
33623379 assert .ErrorIs (t , err , context .Canceled )
33633380 })
33643381
0 commit comments