Skip to content

Commit

Permalink
cleaning up recordsetchanges
Browse files Browse the repository at this point in the history
  • Loading branch information
brucedewald committed Jun 10, 2024
1 parent cda4b5b commit fe4cc96
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 24 deletions.
10 changes: 3 additions & 7 deletions vinyldns/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func recordSetEP(c *Client, zoneID, recordSetID string) string {
return concatStrs("", recordSetsEP(c, zoneID), "/", recordSetID)
}

func recordSetChangesEP(c *Client, zoneID string, f ListFilterInt) string {
query := buildQueryInt(f, "nameFilter")
func recordSetChangesEP(c *Client, zoneID string, f ListFilterRecordSetChanges) string {
query := buildRecordSetChangesQuery(f)

return concatStrs("", zoneEP(c, zoneID), "/recordsetchanges", query)
}
Expand Down Expand Up @@ -133,14 +133,10 @@ func buildQuery(f ListFilter, nameFilterName string) string {
return query + strings.Join(params, "&")
}

func buildQueryInt(f ListFilterInt, nameFilterName string) string {
func buildRecordSetChangesQuery(f ListFilterRecordSetChanges) string {
params := []string{}
query := "?"

if f.NameFilter != "" {
params = append(params, fmt.Sprintf("%s=%s", nameFilterName, f.NameFilter))
}

if f.StartFrom != 0 {
params = append(params, fmt.Sprintf("startFrom=%d", f.StartFrom))
}
Expand Down
4 changes: 2 additions & 2 deletions vinyldns/endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func TestRecordSetEP(t *testing.T) {
}

func TestRecordSetChangesEP(t *testing.T) {
rsc := recordSetChangesEP(c, "123", ListFilterInt{})
rsc := recordSetChangesEP(c, "123", ListFilterRecordSetChanges{})
expected := "http://host.com/zones/123/recordsetchanges"

if rsc != expected {
Expand All @@ -238,7 +238,7 @@ func TestRecordSetChangesEP(t *testing.T) {
}

func TestRecordSetChangesEPWithQuery(t *testing.T) {
rsc := recordSetChangesEP(c, "123", ListFilterInt{
rsc := recordSetChangesEP(c, "123", ListFilterRecordSetChanges{
MaxItems: 3,
StartFrom: 1,
})
Expand Down
6 changes: 3 additions & 3 deletions vinyldns/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ func TestRecordSetChangesIntegration(t *testing.T) {
t.Error(err)
}

changes, err := c.RecordSetChanges(zones[0].ID, ListFilterInt{})
changes, err := c.RecordSetChanges(zones[0].ID, ListFilterRecordSetChanges{})
if err != nil {
t.Error(err)
}
Expand All @@ -483,7 +483,7 @@ func TestRecordSetChangesIntegrationWithMaxItems(t *testing.T) {
t.Error(err)
}

changes, err := c.RecordSetChanges(zones[0].ID, ListFilterInt{
changes, err := c.RecordSetChanges(zones[0].ID, ListFilterRecordSetChanges{
MaxItems: 1,
})
if err != nil {
Expand All @@ -502,7 +502,7 @@ func TestRecordSetChangesListAllIntegration(t *testing.T) {
t.Error(err)
}

changes, err := c.RecordSetChangesListAll(zones[0].ID, ListFilterInt{})
changes, err := c.RecordSetChangesListAll(zones[0].ID, ListFilterRecordSetChanges{})
if err != nil {
t.Error(err)
}
Expand Down
4 changes: 2 additions & 2 deletions vinyldns/recordsets.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func (c *Client) RecordSetDelete(zoneID, recordSetID string) (*RecordSetUpdateRe
}

// RecordSetChanges retrieves the RecordSetChanges response for the Zone and ListFilter it's passed.
func (c *Client) RecordSetChanges(zoneID string, f ListFilterInt) (*RecordSetChanges, error) {
func (c *Client) RecordSetChanges(zoneID string, f ListFilterRecordSetChanges) (*RecordSetChanges, error) {
rsc := &RecordSetChanges{}
err := resourceRequest(c, recordSetChangesEP(c, zoneID, f), "GET", nil, rsc)
if err != nil {
Expand All @@ -221,7 +221,7 @@ func (c *Client) RecordSetChanges(zoneID string, f ListFilterInt) (*RecordSetCha

// RecordSetChangesListAll retrieves the complete list of record set changes for the Zone ListFilter criteria passed.
// Handles paging through results on the user's behalf.
func (c *Client) RecordSetChangesListAll(zoneID string, filter ListFilterInt) ([]RecordSetChange, error) {
func (c *Client) RecordSetChangesListAll(zoneID string, filter ListFilterRecordSetChanges) ([]RecordSetChange, error) {
if filter.MaxItems > 100 {
return nil, fmt.Errorf("MaxItems must be between 1 and 100")
}
Expand Down
6 changes: 3 additions & 3 deletions vinyldns/recordsets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ func TestRecordSetChangessListAllWhenNoneExist(t *testing.T) {

defer server.Close()

changes, err := client.RecordSetChangesListAll("123", ListFilterInt{})
changes, err := client.RecordSetChangesListAll("123", ListFilterRecordSetChanges{})
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -556,13 +556,13 @@ func TestRecordSetChangesListAll(t *testing.T) {

defer server.Close()

if _, err := client.RecordSetChangesListAll("123", ListFilterInt{
if _, err := client.RecordSetChangesListAll("123", ListFilterRecordSetChanges{
MaxItems: 200,
}); err == nil {
t.Error("Expected error -- MaxItems must be between 1 and 100")
}

changes, err := client.RecordSetChangesListAll("123", ListFilterInt{
changes, err := client.RecordSetChangesListAll("123", ListFilterRecordSetChanges{
MaxItems: 1,
})
if err != nil {
Expand Down
12 changes: 5 additions & 7 deletions vinyldns/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,11 @@ type ListFilter struct {
MaxItems int
}

// ListFilterInt represents the list query parameters that may be passed to
// VinylDNS API endpoints such as /zones and /zones/${zone_id}/recordsets
// Same as ListFilter except for resources where StartFrom is an int instead of string
type ListFilterInt struct {
NameFilter string
StartFrom int
MaxItems int
// ListFilterRecordSetChanges represents the list query parameters that may be passed to
// VinylDNS API endpoint /zones/${zone_id}/recordsetchanges
type ListFilterRecordSetChanges struct {
StartFrom int
MaxItems int
}

// NameSort specifies the name sort order for record sets returned by the global list record set response.
Expand Down

0 comments on commit fe4cc96

Please sign in to comment.