Skip to content

Commit ad39f9b

Browse files
committed
dns: allow sending empty strings
Updates the SDK to allow sending empty strings to the API to clear DNS comment values. Fixes #1166
1 parent fc27011 commit ad39f9b

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

dns.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ type UpdateDNSRecordParams struct {
7171
Priority *uint16 `json:"-"` // internal use only
7272
TTL int `json:"ttl,omitempty"`
7373
Proxied *bool `json:"proxied,omitempty"`
74-
Comment string `json:"comment,omitempty"`
74+
Comment string `json:"comment"`
7575
Tags []string `json:"tags,omitempty"`
7676
}
7777

@@ -229,6 +229,7 @@ func (api *API) UpdateDNSRecord(ctx context.Context, rc *ResourceContainer, para
229229
if rc.Identifier == "" {
230230
return ErrMissingZoneID
231231
}
232+
232233
if params.ID == "" {
233234
return ErrMissingDNSRecordID
234235
}

dns_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,64 @@ func TestUpdateDNSRecord(t *testing.T) {
528528
require.NoError(t, err)
529529
}
530530

531+
func TestUpdateDNSRecord_ClearComment(t *testing.T) {
532+
setup()
533+
defer teardown()
534+
535+
input := DNSRecord{
536+
ID: "372e67954025e0ba6aaa6d586b9e0b59",
537+
Comment: "",
538+
}
539+
540+
handler := func(w http.ResponseWriter, r *http.Request) {
541+
assert.Equal(t, http.MethodPatch, r.Method, "Expected method 'PATCH', got %s", r.Method)
542+
543+
var v DNSRecord
544+
err := json.NewDecoder(r.Body).Decode(&v)
545+
require.NoError(t, err)
546+
v.ID = "372e67954025e0ba6aaa6d586b9e0b59"
547+
assert.Equal(t, input, v)
548+
549+
w.Header().Set("content-type", "application/json")
550+
fmt.Fprint(w, `{
551+
"success": true,
552+
"errors": [],
553+
"messages": [],
554+
"result": {
555+
"id": "372e67954025e0ba6aaa6d586b9e0b59",
556+
"type": "A",
557+
"name": "example.com",
558+
"content": "198.51.100.4",
559+
"proxiable": true,
560+
"proxied": false,
561+
"ttl": 120,
562+
"locked": false,
563+
"zone_id": "d56084adb405e0b7e32c52321bf07be6",
564+
"zone_name": "example.com",
565+
"created_on": "2014-01-01T05:20:00Z",
566+
"modified_on": "2014-01-01T05:20:00Z",
567+
"comment":null,
568+
"tags":[],
569+
"data": {},
570+
"meta": {
571+
"auto_added": true,
572+
"source": "primary"
573+
}
574+
}
575+
}`)
576+
}
577+
578+
dnsRecordID := "372e67954025e0ba6aaa6d586b9e0b59"
579+
580+
mux.HandleFunc("/zones/"+testZoneID+"/dns_records/"+dnsRecordID, handler)
581+
582+
err := client.UpdateDNSRecord(context.Background(), ZoneIdentifier(testZoneID), UpdateDNSRecordParams{
583+
ID: dnsRecordID,
584+
Comment: "",
585+
})
586+
require.NoError(t, err)
587+
}
588+
531589
func TestDeleteDNSRecord(t *testing.T) {
532590
setup()
533591
defer teardown()

0 commit comments

Comments
 (0)