Skip to content

Commit

Permalink
get rid of ensure.NotNil
Browse files Browse the repository at this point in the history
  • Loading branch information
vtopc committed Nov 2, 2024
1 parent 6d4748a commit 99c5d11
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 25 deletions.
3 changes: 1 addition & 2 deletions attachments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"
"testing"

"github.com/facebookgo/ensure"
"github.com/mailgun/mailgun-go/v4"
"github.com/mailgun/mailgun-go/v4/events"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -44,7 +43,7 @@ func TestMultipleAttachments(t *testing.T) {
t.Logf("New Email: %s Id: %s\n", msg, id)

e, err := findAcceptedMessage(mg, id)
ensure.NotNil(t, e)
require.NotNil(t, e)

require.Equal(t, e.ID, id)
require.Len(t, e.Message.Attachments, 2)
Expand Down
4 changes: 1 addition & 3 deletions bounces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (

"github.com/mailgun/mailgun-go/v4"
"github.com/stretchr/testify/require"

"github.com/facebookgo/ensure"
)

func TestGetBounces(t *testing.T) {
Expand All @@ -39,7 +37,7 @@ func TestGetSingleBounce(t *testing.T) {
exampleEmail := fmt.Sprintf("%s@%s", strings.ToLower(randomString(64, "")),
os.Getenv("MG_DOMAIN"))
_, err := mg.GetBounce(ctx, exampleEmail)
ensure.NotNil(t, err)
require.NotNil(t, err)

var ure *mailgun.UnexpectedResponseError
require.ErrorAs(t, err, &ure)
Expand Down
2 changes: 1 addition & 1 deletion events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestEventPoller(t *testing.T) {
}
}
// Ensure we found our email
ensure.NotNil(t, it.Err())
require.NotNil(t, it.Err())
require.NotNil(t, accepted)
require.Equal(t, "user@"+testDomain, accepted.Recipient)
}
Expand Down
5 changes: 2 additions & 3 deletions mailing_lists_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"testing"

"github.com/facebookgo/ensure"
"github.com/mailgun/mailgun-go/v4"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -90,7 +89,7 @@ func TestMailingListMembers(t *testing.T) {
theMember, err = mg.GetMember(ctx, "[email protected]", address)
require.NoError(t, err)
require.Equal(t, "Joe's Cool Account", theMember.Name)
ensure.NotNil(t, theMember.Subscribed)
require.NotNil(t, theMember.Subscribed)
require.True(t, *theMember.Subscribed)
}

Expand Down Expand Up @@ -125,7 +124,7 @@ func TestMailingLists(t *testing.T) {
require.NoError(t, mg.DeleteMailingList(ctx, address))

_, err := mg.GetMailingList(ctx, address)
ensure.NotNil(t, err)
require.NotNil(t, err)
}()

actualCount := countLists()
Expand Down
8 changes: 4 additions & 4 deletions messages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func TestSendMGBatchFailRecipients(t *testing.T) {
err := m.AddRecipientAndVariables(toUser, nil)
// In case of error the SDK didn't send the message,
// OR the API didn't check for empty To: headers.
ensure.NotNil(t, err)
require.NotNil(t, err)
})
}

Expand Down Expand Up @@ -417,7 +417,7 @@ func TestAddRecipientsError(t *testing.T) {
}

err := m.AddRecipient("[email protected]")
ensure.NotNil(t, err)
require.NotNil(t, err)
require.EqualError(t, err, "recipient limit exceeded (max 1000)")
}

Expand Down Expand Up @@ -491,7 +491,7 @@ func TestSendEOFError(t *testing.T) {

m := mailgun.NewMessage(fromUser, exampleSubject, exampleText, toUser)
_, _, err := mg.Send(context.Background(), m)
ensure.NotNil(t, err)
require.NotNil(t, err)
ensure.StringContains(t, err.Error(), "remote server prematurely closed connection: Post ")
ensure.StringContains(t, err.Error(), "EOF")
}
Expand Down Expand Up @@ -553,7 +553,7 @@ func TestResendStored(t *testing.T) {
mg.SetAPIBase(srv.URL + "/v3")

msg, id, err := mg.ReSend(context.Background(), srv.URL+"/v3/some-url")
ensure.NotNil(t, err)
require.NotNil(t, err)
require.Equal(t, err.Error(), "must provide at least one recipient")

msg, id, err = mg.ReSend(context.Background(), srv.URL+"/v3/some-url", toUser)
Expand Down
2 changes: 1 addition & 1 deletion routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestRouteCRUD(t *testing.T) {
defer func() {
require.NoError(t, mg.DeleteRoute(ctx, newRoute.Id))
_, err = mg.GetRoute(ctx, newRoute.Id)
ensure.NotNil(t, err)
require.NotNil(t, err)
}()

newCount := countRoutes()
Expand Down
3 changes: 1 addition & 2 deletions spam_complaints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"strings"
"testing"

"github.com/facebookgo/ensure"
"github.com/mailgun/mailgun-go/v4"
"github.com/stretchr/testify/require"
)
Expand All @@ -31,7 +30,7 @@ func TestGetComplaintFromRandomNoComplaint(t *testing.T) {
ctx := context.Background()

_, err := mg.GetComplaint(ctx, randomString(64, "")+"@example.com")
ensure.NotNil(t, err)
require.NotNil(t, err)

var ure *mailgun.UnexpectedResponseError
require.ErrorAs(t, err, &ure)
Expand Down
9 changes: 4 additions & 5 deletions subaccounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"net/http"
"testing"

"github.com/facebookgo/ensure"
"github.com/mailgun/mailgun-go/v4"
"github.com/stretchr/testify/require"
)
Expand All @@ -21,7 +20,7 @@ func TestListSubaccounts(t *testing.T) {
mg.SetAPIBase(server.URL())

iterator := mg.ListSubaccounts(nil)
ensure.NotNil(t, iterator)
require.NotNil(t, iterator)

ctx := context.Background()

Expand All @@ -43,15 +42,15 @@ func TestSubaccountDetails(t *testing.T) {
ctx := context.Background()

iterator := mg.ListSubaccounts(nil)
ensure.NotNil(t, iterator)
require.NotNil(t, iterator)

page := []mailgun.Subaccount{}
require.True(t, iterator.Next(context.Background(), &page))
require.NoError(t, iterator.Err())

resp, err := mg.SubaccountDetails(ctx, page[0].Id)
require.NoError(t, err)
ensure.NotNil(t, resp)
require.NotNil(t, resp)
}

func TestSubaccountDetailsStatusNotFound(t *testing.T) {
Expand All @@ -77,7 +76,7 @@ func TestCreateSubaccount(t *testing.T) {

resp, err := mg.CreateSubaccount(ctx, testSubaccountName)
require.NoError(t, err)
ensure.NotNil(t, resp)
require.NotNil(t, resp)
}

func TestEnableSubaccountAlreadyEnabled(t *testing.T) {
Expand Down
7 changes: 3 additions & 4 deletions tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"testing"
"time"

"github.com/facebookgo/ensure"
"github.com/mailgun/errors"
"github.com/mailgun/mailgun-go/v4"
"github.com/stretchr/testify/require"
Expand All @@ -24,8 +23,8 @@ func TestTags(t *testing.T) {
require.NoError(t, msg.AddTag("newsletter"))
require.NoError(t, msg.AddTag("homer"))
require.NoError(t, msg.AddTag("bart"))
ensure.NotNil(t, msg.AddTag("disco-steve"))
ensure.NotNil(t, msg.AddTag("newsletter"))
require.NotNil(t, msg.AddTag("disco-steve"))
require.NotNil(t, msg.AddTag("newsletter"))

ctx := context.Background()
// Create an email with some tags attached
Expand Down Expand Up @@ -60,7 +59,7 @@ func TestTags(t *testing.T) {
require.Equal(t, "homer", tag.Value)

_, err = mg.GetTag(ctx, "i-dont-exist")
ensure.NotNil(t, err)
require.NotNil(t, err)
require.Equal(t, 404, mailgun.GetStatusFromErr(err))
}

Expand Down

0 comments on commit 99c5d11

Please sign in to comment.