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

Revive #378

Merged
merged 8 commits into from
Nov 3, 2022
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
24 changes: 17 additions & 7 deletions fastly/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"
)

// ACL represents a server response from the Fastly API.
type ACL struct {
CreatedAt *time.Time `mapstructure:"created_at"`
DeletedAt *time.Time `mapstructure:"deleted_at"`
Expand All @@ -20,9 +21,17 @@ type ACL struct {
// ACLsByName is a sortable list of ACLs.
type ACLsByName []*ACL

// Len, Swap, and Less implement the sortable interface.
func (s ACLsByName) Len() int { return len(s) }
func (s ACLsByName) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
// Len implements the sortable interface.
func (s ACLsByName) Len() int {
return len(s)
}

// Swap implements the sortable interface.
func (s ACLsByName) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}

// Less implements the sortable interface.
func (s ACLsByName) Less(i, j int) bool {
return s[i].Name < s[j].Name
}
Expand All @@ -35,7 +44,7 @@ type ListACLsInput struct {
ServiceVersion int
}

// ListACLs returns the list of ACLs for the configuration version.
// ListACLs retrieves all resources.
func (c *Client) ListACLs(i *ListACLsInput) ([]*ACL, error) {
if i.ServiceID == "" {
return nil, ErrMissingServiceID
Expand Down Expand Up @@ -70,6 +79,7 @@ type CreateACLInput struct {
ServiceVersion int
}

// CreateACL creates a new resource.
func (c *Client) CreateACL(i *CreateACLInput) (*ACL, error) {
if i.ServiceID == "" {
return nil, ErrMissingServiceID
Expand Down Expand Up @@ -103,7 +113,7 @@ type DeleteACLInput struct {
ServiceVersion int
}

// DeleteACL deletes the given ACL version.
// DeleteACL deletes the specified resource.
func (c *Client) DeleteACL(i *DeleteACLInput) error {
if i.ServiceID == "" {
return ErrMissingServiceID
Expand Down Expand Up @@ -144,7 +154,7 @@ type GetACLInput struct {
ServiceVersion int
}

// GetACL gets the ACL configuration with the given parameters.
// GetACL retrieves the specified resource.
func (c *Client) GetACL(i *GetACLInput) (*ACL, error) {
if i.ServiceID == "" {
return nil, ErrMissingServiceID
Expand Down Expand Up @@ -184,7 +194,7 @@ type UpdateACLInput struct {
ServiceVersion int
}

// UpdateACL updates the name of the ACL with the given parameters.
// UpdateACL updates the specified resource.
func (c *Client) UpdateACL(i *UpdateACLInput) (*ACL, error) {
if i.ServiceID == "" {
return nil, ErrMissingServiceID
Expand Down
26 changes: 8 additions & 18 deletions fastly/acl_entries_batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
)

func TestClient_BatchModifyAclEntries_Create(t *testing.T) {

fixtureBase := "acl_entries_batch/create/"
nameSuffix := "BatchModifyAclEntries_Create"

Expand Down Expand Up @@ -72,12 +71,11 @@ func TestClient_BatchModifyAclEntries_Create(t *testing.T) {
}

for i, entry := range actualACLEntries {
actualIP := entry.IP
expectedIP := batchCreateOperations.Entries[i].IP

actualIp := entry.IP
expectedIp := batchCreateOperations.Entries[i].IP

if actualIp != *expectedIp {
t.Errorf("IP did not match, expected %v, got %v", expectedIp, actualIp)
if actualIP != *expectedIP {
t.Errorf("IP did not match, expected %v, got %v", expectedIP, actualIP)
}

actualSubnet := entry.Subnet
Expand All @@ -101,11 +99,9 @@ func TestClient_BatchModifyAclEntries_Create(t *testing.T) {
t.Errorf("Comment did not match, expected %v, got %v", expectedComment, actualComment)
}
}

}

func TestClient_BatchModifyAclEntries_Delete(t *testing.T) {

fixtureBase := "acl_entries_batch/delete/"
nameSuffix := "BatchModifyAclEntries_Delete"

Expand Down Expand Up @@ -141,7 +137,6 @@ func TestClient_BatchModifyAclEntries_Delete(t *testing.T) {

var err error
record(t, fixtureBase+"create_acl_entries", func(c *Client) {

err = c.BatchModifyACLEntries(batchCreateOperations)
})
if err != nil {
Expand Down Expand Up @@ -176,7 +171,6 @@ func TestClient_BatchModifyAclEntries_Delete(t *testing.T) {
}

record(t, fixtureBase+"delete_acl_entries", func(c *Client) {

err = c.BatchModifyACLEntries(batchDeleteOperations)
})
if err != nil {
Expand Down Expand Up @@ -207,7 +201,6 @@ func TestClient_BatchModifyAclEntries_Delete(t *testing.T) {
}

func TestClient_BatchModifyAclEntries_Update(t *testing.T) {

fixtureBase := "acl_entries_batch/update/"
nameSuffix := "BatchModifyAclEntries_Update"

Expand Down Expand Up @@ -243,7 +236,6 @@ func TestClient_BatchModifyAclEntries_Update(t *testing.T) {

var err error
record(t, fixtureBase+"create_acl_entries", func(c *Client) {

err = c.BatchModifyACLEntries(batchCreateOperations)
})
if err != nil {
Expand Down Expand Up @@ -282,7 +274,6 @@ func TestClient_BatchModifyAclEntries_Update(t *testing.T) {
}

record(t, fixtureBase+"update_acl_entries", func(c *Client) {

err = c.BatchModifyACLEntries(batchUpdateOperations)
})
if err != nil {
Expand All @@ -305,10 +296,10 @@ func TestClient_BatchModifyAclEntries_Update(t *testing.T) {
return actualACLEntries[i].IP < actualACLEntries[j].IP
})

actualNumberOfAclEntries := len(actualACLEntries)
expectedNumberOfAclEntries := len(batchCreateOperations.Entries)
if actualNumberOfAclEntries != expectedNumberOfAclEntries {
t.Errorf("Incorrect number of ACL entries returned, expected: %d, got %d", expectedNumberOfAclEntries, actualNumberOfAclEntries)
actualNumberOfACLEntries := len(actualACLEntries)
expectedNumberOfACLEntries := len(batchCreateOperations.Entries)
if actualNumberOfACLEntries != expectedNumberOfACLEntries {
t.Errorf("Incorrect number of ACL entries returned, expected: %d, got %d", expectedNumberOfACLEntries, actualNumberOfACLEntries)
}

actualID := actualACLEntries[0].ID
Expand Down Expand Up @@ -345,5 +336,4 @@ func TestClient_BatchModifyAclEntries_Update(t *testing.T) {
if actualComment != *expectedComment {
t.Errorf("First Comment did not match, expected %v, got %v", expectedComment, actualComment)
}

}
Loading