Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dns: test empty DNS record IDs #1174

Merged
merged 3 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/1174.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
dns: `GetDNSRecord`, `UpdateDNSRecord` and `DeleteDNSRecord` now return the new, dedicated error `ErrMissingDNSRecordID` when an empty DNS record ID is given.
```
4 changes: 4 additions & 0 deletions dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ func (api *API) DeleteDNSRecord(ctx context.Context, rc *ResourceContainer, reco
if rc.Identifier == "" {
return ErrMissingZoneID
}
if recordID == "" {
return ErrMissingDNSRecordID
}

uri := fmt.Sprintf("/zones/%s/dns_records/%s", rc.Identifier, recordID)
res, err := api.makeRequestContext(ctx, http.MethodDelete, uri, nil)
if err != nil {
Expand Down
23 changes: 16 additions & 7 deletions dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func TestCreateDNSRecord(t *testing.T) {
}

_, err := client.CreateDNSRecord(context.Background(), ZoneIdentifier(""), CreateDNSRecordParams{})
assert.Equal(t, ErrMissingZoneID, err)
assert.ErrorIs(t, err, ErrMissingZoneID)

actual, err := client.CreateDNSRecord(context.Background(), ZoneIdentifier(testZoneID), CreateDNSRecordParams{
Type: "A",
Expand Down Expand Up @@ -230,7 +230,7 @@ func TestListDNSRecords(t *testing.T) {
}}

_, _, err := client.ListDNSRecords(context.Background(), ZoneIdentifier(""), ListDNSRecordsParams{})
assert.Equal(t, ErrMissingZoneID, err)
assert.ErrorIs(t, err, ErrMissingZoneID)

actual, _, err := client.ListDNSRecords(context.Background(), ZoneIdentifier(testZoneID), ListDNSRecordsParams{
Name: "😺.example.com",
Expand Down Expand Up @@ -377,7 +377,7 @@ func TestListDNSRecordsPagination(t *testing.T) {
assert.Len(t, actual, 2)
}

func TestDNSRecord(t *testing.T) {
func TestGetDNSRecord(t *testing.T) {
setup()
defer teardown()

Expand Down Expand Up @@ -442,7 +442,10 @@ func TestDNSRecord(t *testing.T) {
}

_, err := client.GetDNSRecord(context.Background(), ZoneIdentifier(""), dnsRecordID)
assert.Equal(t, ErrMissingZoneID, err)
assert.ErrorIs(t, err, ErrMissingZoneID)

_, err = client.GetDNSRecord(context.Background(), ZoneIdentifier(testZoneID), "")
assert.ErrorIs(t, err, ErrMissingDNSRecordID)

actual, err := client.GetDNSRecord(context.Background(), ZoneIdentifier(testZoneID), dnsRecordID)
require.NoError(t, err)
Expand Down Expand Up @@ -504,8 +507,11 @@ func TestUpdateDNSRecord(t *testing.T) {

mux.HandleFunc("/zones/"+testZoneID+"/dns_records/"+dnsRecordID, handler)

err := client.UpdateDNSRecord(context.Background(), ZoneIdentifier(""), UpdateDNSRecordParams{})
assert.Equal(t, ErrMissingZoneID, err)
err := client.UpdateDNSRecord(context.Background(), ZoneIdentifier(""), UpdateDNSRecordParams{ID: dnsRecordID})
assert.ErrorIs(t, err, ErrMissingZoneID)

err = client.UpdateDNSRecord(context.Background(), ZoneIdentifier(testZoneID), UpdateDNSRecordParams{})
assert.ErrorIs(t, err, ErrMissingDNSRecordID)

err = client.UpdateDNSRecord(context.Background(), ZoneIdentifier(testZoneID), UpdateDNSRecordParams{
ID: dnsRecordID,
Expand Down Expand Up @@ -541,7 +547,10 @@ func TestDeleteDNSRecord(t *testing.T) {
mux.HandleFunc("/zones/"+testZoneID+"/dns_records/"+dnsRecordID, handler)

err := client.DeleteDNSRecord(context.Background(), ZoneIdentifier(""), dnsRecordID)
assert.Equal(t, ErrMissingZoneID, err)
assert.ErrorIs(t, err, ErrMissingZoneID)

err = client.DeleteDNSRecord(context.Background(), ZoneIdentifier(testZoneID), "")
assert.ErrorIs(t, err, ErrMissingDNSRecordID)

err = client.DeleteDNSRecord(context.Background(), ZoneIdentifier(testZoneID), dnsRecordID)
require.NoError(t, err)
Expand Down