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

refactor: Use errors.Is() instead of direct comparison. #581

Merged
merged 2 commits into from
Jan 24, 2025
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: 2 additions & 1 deletion fastly/account_event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fastly

import (
"bytes"
"errors"
"io"
"testing"
)
Expand Down Expand Up @@ -43,7 +44,7 @@ func TestClient_GetAPIEvent_validation(t *testing.T) {
_, err = TestClient.GetAPIEvent(&GetAPIEventInput{
EventID: "",
})
if err != ErrMissingEventID {
if !errors.Is(err, ErrMissingEventID) {
t.Errorf("bad error: %s", err)
}
}
Expand Down
33 changes: 17 additions & 16 deletions fastly/acl_entry_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fastly

import (
"errors"
"testing"
)

Expand Down Expand Up @@ -171,14 +172,14 @@ func TestClient_ListACLEntries_validation(t *testing.T) {
var err error

_, err = TestClient.ListACLEntries(&ListACLEntriesInput{})
if err != ErrMissingACLID {
if !errors.Is(err, ErrMissingACLID) {
t.Errorf("bad ACL ID: %s", err)
}

_, err = TestClient.ListACLEntries(&ListACLEntriesInput{
ACLID: "123",
})
if err != ErrMissingServiceID {
if !errors.Is(err, ErrMissingServiceID) {
t.Errorf("bad Service ID: %s", err)
}
}
Expand All @@ -187,14 +188,14 @@ func TestClient_CreateACLEntry_validation(t *testing.T) {
var err error

_, err = TestClient.CreateACLEntry(&CreateACLEntryInput{})
if err != ErrMissingACLID {
if !errors.Is(err, ErrMissingACLID) {
t.Errorf("bad error: %s", err)
}

_, err = TestClient.CreateACLEntry(&CreateACLEntryInput{
ACLID: "123",
})
if err != ErrMissingServiceID {
if !errors.Is(err, ErrMissingServiceID) {
t.Errorf("bad error: %s", err)
}
}
Expand All @@ -203,22 +204,22 @@ func TestClient_GetACLEntry_validation(t *testing.T) {
var err error

_, err = TestClient.GetACLEntry(&GetACLEntryInput{})
if err != ErrMissingACLID {
if !errors.Is(err, ErrMissingACLID) {
t.Errorf("bad error: %s", err)
}

_, err = TestClient.GetACLEntry(&GetACLEntryInput{
ACLID: "123",
})
if err != ErrMissingID {
if !errors.Is(err, ErrMissingID) {
t.Errorf("bad error: %s", err)
}

_, err = TestClient.GetACLEntry(&GetACLEntryInput{
ACLID: "123",
EntryID: "456",
})
if err != ErrMissingServiceID {
if !errors.Is(err, ErrMissingServiceID) {
t.Errorf("bad error: %s", err)
}
}
Expand All @@ -227,22 +228,22 @@ func TestClient_UpdateACLEntry_validation(t *testing.T) {
var err error

_, err = TestClient.UpdateACLEntry(&UpdateACLEntryInput{})
if err != ErrMissingACLID {
if !errors.Is(err, ErrMissingACLID) {
t.Errorf("bad error: %s", err)
}

_, err = TestClient.UpdateACLEntry(&UpdateACLEntryInput{
ACLID: "123",
})
if err != ErrMissingID {
if !errors.Is(err, ErrMissingID) {
t.Errorf("bad error: %s", err)
}

_, err = TestClient.UpdateACLEntry(&UpdateACLEntryInput{
ACLID: "123",
EntryID: "456",
})
if err != ErrMissingServiceID {
if !errors.Is(err, ErrMissingServiceID) {
t.Errorf("bad error: %s", err)
}
}
Expand All @@ -251,22 +252,22 @@ func TestClient_DeleteACLEntry_validation(t *testing.T) {
var err error

err = TestClient.DeleteACLEntry(&DeleteACLEntryInput{})
if err != ErrMissingACLID {
if !errors.Is(err, ErrMissingACLID) {
t.Errorf("bad error: %s", err)
}

err = TestClient.DeleteACLEntry(&DeleteACLEntryInput{
ACLID: "123",
})
if err != ErrMissingEntryID {
if !errors.Is(err, ErrMissingEntryID) {
t.Errorf("bad error: %s", err)
}

err = TestClient.DeleteACLEntry(&DeleteACLEntryInput{
ACLID: "123",
EntryID: "456",
})
if err != ErrMissingServiceID {
if !errors.Is(err, ErrMissingServiceID) {
t.Errorf("bad error: %s", err)
}
}
Expand All @@ -275,14 +276,14 @@ func TestClient_BatchModifyACLEntries_validation(t *testing.T) {
var err error

err = TestClient.BatchModifyACLEntries(&BatchModifyACLEntriesInput{})
if err != ErrMissingACLID {
if !errors.Is(err, ErrMissingACLID) {
t.Errorf("bad error: %s", err)
}

err = TestClient.BatchModifyACLEntries(&BatchModifyACLEntriesInput{
ACLID: "123",
})
if err != ErrMissingServiceID {
if !errors.Is(err, ErrMissingServiceID) {
t.Errorf("bad error: %s", err)
}

Expand All @@ -292,7 +293,7 @@ func TestClient_BatchModifyACLEntries_validation(t *testing.T) {
ServiceID: "456",
Entries: oversizedACLEntries,
})
if err != ErrMaxExceededEntries {
if !errors.Is(err, ErrMaxExceededEntries) {
t.Errorf("bad error: %s", err)
}
}
27 changes: 14 additions & 13 deletions fastly/acl_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fastly

import (
"errors"
"testing"
)

Expand Down Expand Up @@ -128,15 +129,15 @@ func TestClient_ListACLs_validation(t *testing.T) {
_, err = TestClient.ListACLs(&ListACLsInput{
ServiceID: "",
})
if err != ErrMissingServiceID {
if !errors.Is(err, ErrMissingServiceID) {
t.Errorf("bad error: %s", err)
}

_, err = TestClient.ListACLs(&ListACLsInput{
ServiceID: "foo",
ServiceVersion: 0,
})
if err != ErrMissingServiceVersion {
if !errors.Is(err, ErrMissingServiceVersion) {
t.Errorf("bad error: %s", err)
}
}
Expand All @@ -146,15 +147,15 @@ func TestClient_CreateACL_validation(t *testing.T) {
_, err = TestClient.CreateACL(&CreateACLInput{
ServiceID: "",
})
if err != ErrMissingServiceID {
if !errors.Is(err, ErrMissingServiceID) {
t.Errorf("bad error: %s", err)
}

_, err = TestClient.CreateACL(&CreateACLInput{
ServiceID: "foo",
ServiceVersion: 0,
})
if err != ErrMissingServiceVersion {
if !errors.Is(err, ErrMissingServiceVersion) {
t.Errorf("bad error: %s", err)
}
}
Expand All @@ -165,23 +166,23 @@ func TestClient_GetACL_validation(t *testing.T) {
ServiceID: "foo",
ServiceVersion: 1,
})
if err != ErrMissingName {
if !errors.Is(err, ErrMissingName) {
t.Errorf("bad error: %s", err)
}

_, err = TestClient.GetACL(&GetACLInput{
Name: "test",
ServiceVersion: 1,
})
if err != ErrMissingServiceID {
if !errors.Is(err, ErrMissingServiceID) {
t.Errorf("bad error: %s", err)
}

_, err = TestClient.GetACL(&GetACLInput{
Name: "test",
ServiceID: "foo",
})
if err != ErrMissingServiceVersion {
if !errors.Is(err, ErrMissingServiceVersion) {
t.Errorf("bad error: %s", err)
}
}
Expand All @@ -193,23 +194,23 @@ func TestClient_UpdateACL_validation(t *testing.T) {
ServiceID: "foo",
ServiceVersion: 1,
})
if err != ErrMissingName {
if !errors.Is(err, ErrMissingName) {
t.Errorf("bad error: %s", err)
}

_, err = TestClient.UpdateACL(&UpdateACLInput{
Name: "test",
ServiceVersion: 1,
})
if err != ErrMissingServiceID {
if !errors.Is(err, ErrMissingServiceID) {
t.Errorf("bad error: %s", err)
}

_, err = TestClient.UpdateACL(&UpdateACLInput{
Name: "test",
ServiceID: "foo",
})
if err != ErrMissingServiceVersion {
if !errors.Is(err, ErrMissingServiceVersion) {
t.Errorf("bad error: %s", err)
}
}
Expand All @@ -221,23 +222,23 @@ func TestClient_DeleteACL_validation(t *testing.T) {
ServiceID: "foo",
ServiceVersion: 1,
})
if err != ErrMissingName {
if !errors.Is(err, ErrMissingName) {
t.Errorf("bad error: %s", err)
}

err = TestClient.DeleteACL(&DeleteACLInput{
Name: "test",
ServiceVersion: 0,
})
if err != ErrMissingServiceID {
if !errors.Is(err, ErrMissingServiceID) {
t.Errorf("bad error: %s", err)
}

err = TestClient.DeleteACL(&DeleteACLInput{
Name: "test",
ServiceID: "foo",
})
if err != ErrMissingServiceVersion {
if !errors.Is(err, ErrMissingServiceVersion) {
t.Errorf("bad error: %s", err)
}
}
7 changes: 4 additions & 3 deletions fastly/alerts_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fastly

import (
"errors"
"testing"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -238,7 +239,7 @@ func TestClient_GetAlertDefinition_validation(t *testing.T) {
_, err = TestClient.GetAlertDefinition(&GetAlertDefinitionInput{
ID: nil,
})
if err != ErrMissingID {
if !errors.Is(err, ErrMissingID) {
t.Errorf("bad error: %s", err)
}
}
Expand All @@ -248,7 +249,7 @@ func TestClient_UpdateAlertDefinition_validation(t *testing.T) {
_, err = TestClient.UpdateAlertDefinition(&UpdateAlertDefinitionInput{
ID: nil,
})
if err != ErrMissingID {
if !errors.Is(err, ErrMissingID) {
t.Errorf("bad error: %s", err)
}
}
Expand All @@ -257,7 +258,7 @@ func TestClient_DeleteAlertDefinition_validation(t *testing.T) {
err := TestClient.DeleteAlertDefinition(&DeleteAlertDefinitionInput{
ID: nil,
})
if err != ErrMissingID {
if !errors.Is(err, ErrMissingID) {
t.Errorf("bad error: %s", err)
}
}
Loading
Loading