Repository: cloudflare/cloudflare-go
Pull request #1173 (2023-01-10 08:40:14)

dns: clean up ListDNSRecordsParams and actually support tags for searching
## Description

This is the sequel to #1170 to clean up `ListDNSRecordsParams`.

## Has your change been tested?

My (free) Cloudflare plan cannot test the new features `tag-match` and `tag` enabled by this PR. Otherwise, this PR passes the minimum test case, which barely tests the tags beyond mocking.

@jacobbednarz @janik-cloudflare **Help is needed to confirm the "real" behavior of tags.**

## Types of changes

What sort of change does your code introduce/modify?

- [x] Bug fix (non-breaking change which fixes an issue)\
  Previously, `tags` was listed as a parameter but the URL parameter name was `tags`, which should have been `tag`.
- [x] New feature (non-breaking change which adds functionality)\
  The parameter `tag-match` is added.
- [x] Breaking change (fix or feature that would cause existing functionality to change)\
  All the fields not documented in the public API are removed except `Priority`.

## Checklist:

- [x] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [x] I have added tests to cover my changes.
- [x] All new and existing tests passed.
- [x] This change is using publicly documented (api.cloudflare.com or developers.cloudflare.com) and stable APIs.

github-actions[bot]: Oops! It looks like no changelog entry is attached to this PR. Please include a release note as described in https://github.com/cloudflare/cloudflare-go/blob/master/docs/changelog-process.md.

Example: 

~~~
```release-note:TYPE
Release note
```
~~~

If you do not require a release note to be included, please add the `workflow/skip-changelog-entry` label.
codecov-commenter: # [Codecov](https://codecov.io/gh/cloudflare/cloudflare-go/pull/1173?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudflare) Report
> Merging [#1173](https://codecov.io/gh/cloudflare/cloudflare-go/pull/1173?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudflare) (c6a55bc) into [master](https://codecov.io/gh/cloudflare/cloudflare-go/commit/6153c1e32fa46b7049683687b7f76eb554c95217?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudflare) (6153c1e) will **decrease** coverage by `0.09%`.
> The diff coverage is `45.07%`.

```diff
@@            Coverage Diff             @@
##           master    #1173      +/-   ##
==========================================
- Coverage   49.40%   49.30%   -0.10%     
==========================================
  Files         127      128       +1     
  Lines       12290    12408     +118     
==========================================
+ Hits         6072     6118      +46     
- Misses       4840     4886      +46     
- Partials     1378     1404      +26     
```


| [Impacted Files](https://codecov.io/gh/cloudflare/cloudflare-go/pull/1173?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudflare) | Coverage Δ | |
|---|---|---|
| [access\_organization.go](https://codecov.io/gh/cloudflare/cloudflare-go/pull/1173?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudflare#diff-YWNjZXNzX29yZ2FuaXphdGlvbi5nbw==) | `64.70% <ø> (ø)` | |
| [cloudflare\_experimental.go](https://codecov.io/gh/cloudflare/cloudflare-go/pull/1173?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudflare#diff-Y2xvdWRmbGFyZV9leHBlcmltZW50YWwuZ28=) | `0.00% <0.00%> (ø)` | |
| [utils.go](https://codecov.io/gh/cloudflare/cloudflare-go/pull/1173?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudflare#diff-dXRpbHMuZ28=) | `72.72% <ø> (ø)` | |
| [cloudflare.go](https://codecov.io/gh/cloudflare/cloudflare-go/pull/1173?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudflare#diff-Y2xvdWRmbGFyZS5nbw==) | `68.37% <14.28%> (-0.34%)` | :arrow_down: |
| [mtls\_certificates.go](https://codecov.io/gh/cloudflare/cloudflare-go/pull/1173?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudflare#diff-bXRsc19jZXJ0aWZpY2F0ZXMuZ28=) | `26.59% <26.59%> (ø)` | |
| [dns.go](https://codecov.io/gh/cloudflare/cloudflare-go/pull/1173?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudflare#diff-ZG5zLmdv) | `66.35% <84.61%> (+2.62%)` | :arrow_up: |
| [origin\_ca.go](https://codecov.io/gh/cloudflare/cloudflare-go/pull/1173?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudflare#diff-b3JpZ2luX2NhLmdv) | `57.26% <90.90%> (-2.09%)` | :arrow_down: |
| [devices\_managed\_networks.go](https://codecov.io/gh/cloudflare/cloudflare-go/pull/1173?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudflare#diff-ZGV2aWNlc19tYW5hZ2VkX25ldHdvcmtzLmdv) | `41.55% <100.00%> (+9.09%)` | :arrow_up: |
| [email\_routing\_destination.go](https://codecov.io/gh/cloudflare/cloudflare-go/pull/1173?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudflare#diff-ZW1haWxfcm91dGluZ19kZXN0aW5hdGlvbi5nbw==) | `66.66% <100.00%> (+0.41%)` | :arrow_up: |
| [email\_routing\_rules.go](https://codecov.io/gh/cloudflare/cloudflare-go/pull/1173?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudflare#diff-ZW1haWxfcm91dGluZ19ydWxlcy5nbw==) | `65.64% <100.00%> (+0.26%)` | :arrow_up: |
| ... and [9 more](https://codecov.io/gh/cloudflare/cloudflare-go/pull/1173?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudflare) | |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudflare). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cloudflare)


Patch:
diff --git a/.changelog/1173.txt b/.changelog/1173.txt
new file mode 100644
index 000000000..403a2feff
--- /dev/null
+++ b/.changelog/1173.txt
@@ -0,0 +1,11 @@
+```release-note:bug
+dns: the field `Tags` in `ListDNSRecordsParams` was not correctly serialized into URL queries
+```
+
+```release-note:enhancement
+dns: the URL parameter `tag-match` for listing DNS records is now supported as the field `TagMatch` in `ListDNSRecordsParams`
+```
+
+```release-note:breaking-change
+dns: the fields `CreatedOn` and `ModifiedOn` are removed from `ListDNSRecordsParams`
+```
diff --git a/dns.go b/dns.go
index c2943ed23..9eaa52dc1 100644
--- a/dns.go
+++ b/dns.go
@@ -47,18 +47,17 @@ const (
 )
 
 type ListDNSRecordsParams struct {
-	CreatedOn  time.Time     `json:"created_on,omitempty" url:"created_on,omitempty"`
-	ModifiedOn time.Time     `json:"modified_on,omitempty" url:"modified_on,omitempty"`
-	Type       string        `json:"type,omitempty" url:"type,omitempty"`
-	Name       string        `json:"name,omitempty" url:"name,omitempty"`
-	Content    string        `json:"content,omitempty" url:"content,omitempty"`
-	Proxied    *bool         `json:"proxied,omitempty" url:"proxied,omitempty"`
-	Comment    string        `json:"comment,omitempty" url:"comment,omitempty"`
-	Tags       []string      `json:"tags,omitempty"`
-	Order      string        `url:"order,omitempty"`
-	Direction  ListDirection `url:"direction,omitempty"`
-	Match      string        `url:"match,omitempty"`
-	Priority   *uint16       `url:"-"`
+	Type      string        `url:"type,omitempty"`
+	Name      string        `url:"name,omitempty"`
+	Content   string        `url:"content,omitempty"`
+	Proxied   *bool         `url:"proxied,omitempty"`
+	Comment   string        `url:"comment,omitempty"`
+	Tags      []string      `url:"tag,omitempty"` // potentially multiple `tag=`
+	TagMatch  string        `url:"tag-match,omitempty"`
+	Order     string        `url:"order,omitempty"`
+	Direction ListDirection `url:"direction,omitempty"`
+	Match     string        `url:"match,omitempty"`
+	Priority  *uint16       `url:"-"`
 
 	ResultInfo
 }
@@ -157,9 +156,7 @@ func (api *API) ListDNSRecords(ctx context.Context, rc *ResourceContainer, param
 		return nil, nil, ErrMissingZoneID
 	}
 
-	if params.Name != "" {
-		params.Name = toUTS46ASCII(params.Name)
-	}
+	params.Name = toUTS46ASCII(params.Name)
 
 	autoPaginate := true
 	if params.PerPage >= 1 || params.Page >= 1 {


Test patch:
diff --git a/dns_test.go b/dns_test.go
index 8cd08386c..086f32ade 100644
--- a/dns_test.go
+++ b/dns_test.go
@@ -261,6 +261,8 @@ func TestListDNSRecordsSearch(t *testing.T) {
 		assert.Equal(t, "1", r.URL.Query().Get("page"))
 		assert.Equal(t, "type", r.URL.Query().Get("order"))
 		assert.Equal(t, "asc", r.URL.Query().Get("direction"))
+		assert.Equal(t, "any", r.URL.Query().Get("tag-match"))
+		assert.ElementsMatch(t, []string{"tag1", "tag2"}, r.URL.Query()["tag"])
 
 		w.Header().Set("content-type", "application/json")
 		fmt.Fprint(w, `{
@@ -334,6 +336,8 @@ func TestListDNSRecordsSearch(t *testing.T) {
 		Name:      "example.com",
 		Type:      "A",
 		Content:   "198.51.100.4",
+		TagMatch:  "any",
+		Tags:      []string{"tag1", "tag2"},
 	})
 	require.NoError(t, err)
 	assert.Equal(t, 2000, resultInfo.Total)