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

Fix: Replace assert pkg with the require pkg #285

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
69 changes: 34 additions & 35 deletions channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"path"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -56,11 +55,11 @@ func TestClient_CreateChannel(t *testing.T) {
require.NoError(t, err, "create channel", ch)

channel := resp.Channel
assert.Equal(t, c, channel.client, "client link")
assert.Equal(t, ch.Type, channel.Type, "channel type")
assert.Equal(t, ch.ID, channel.ID, "channel id")
assert.Equal(t, ch.MemberCount, channel.MemberCount, "member count")
assert.Len(t, channel.Members, ch.MemberCount, "members length")
require.Equal(t, c, channel.client, "client link")
require.Equal(t, ch.Type, channel.Type, "channel type")
require.Equal(t, ch.ID, channel.ID, "channel id")
require.Equal(t, ch.MemberCount, channel.MemberCount, "member count")
require.Len(t, channel.Members, ch.MemberCount, "members length")
})

tests := []struct {
Expand Down Expand Up @@ -98,13 +97,13 @@ func TestClient_CreateChannel(t *testing.T) {
require.NoError(t, err, "create channel", tt)

channel := resp.Channel
assert.Equal(t, tt.channelType, channel.Type, "channel type")
assert.NotEmpty(t, channel.ID)
require.Equal(t, tt.channelType, channel.Type, "channel type")
require.NotEmpty(t, channel.ID)
if tt.id != "" {
assert.Equal(t, tt.id, channel.ID, "channel id")
require.Equal(t, tt.id, channel.ID, "channel id")
}

assert.Equal(t, tt.userID, channel.CreatedBy.ID, "channel created by")
require.Equal(t, tt.userID, channel.CreatedBy.ID, "channel created by")
})
}
}
Expand Down Expand Up @@ -134,7 +133,7 @@ func TestChannel_AddMembers(t *testing.T) {
require.NoError(t, err, "create channel")
ch := resp.Channel

assert.Empty(t, ch.Members, "members are empty")
require.Empty(t, ch.Members, "members are empty")

user := randomUser(t, c)

Expand All @@ -148,7 +147,7 @@ func TestChannel_AddMembers(t *testing.T) {

// refresh channel state
require.NoError(t, ch.refresh(ctx), "refresh channel")
assert.Equal(t, user.ID, ch.Members[0].User.ID, "members contain user id")
require.Equal(t, user.ID, ch.Members[0].User.ID, "members contain user id")
}

func TestChannel_AssignRoles(t *testing.T) {
Expand Down Expand Up @@ -177,7 +176,7 @@ func TestChannel_QueryMembers(t *testing.T) {
require.NoError(t, err, "create channel")
ch := resp1.Channel

assert.Empty(t, ch.Members, "members are empty")
require.Empty(t, ch.Members, "members are empty")

prefix := randomString(12)
names := []string{"paul", "george", "john", "jessica", "john2"}
Expand Down Expand Up @@ -225,7 +224,7 @@ func TestChannel_InviteMembers(t *testing.T) {
require.NoError(t, err, "create channel")
ch := resp.Channel

assert.Empty(t, ch.Members, "members are empty")
require.Empty(t, ch.Members, "members are empty")

user := randomUser(t, c)

Expand All @@ -235,10 +234,10 @@ func TestChannel_InviteMembers(t *testing.T) {
// refresh channel state
require.NoError(t, ch.refresh(ctx), "refresh channel")

assert.Equal(t, user.ID, ch.Members[0].User.ID, "members contain user id")
assert.True(t, ch.Members[0].Invited, "member is invited")
assert.Nil(t, ch.Members[0].InviteAcceptedAt, "invite is not accepted")
assert.Nil(t, ch.Members[0].InviteRejectedAt, "invite is not rejected")
require.Equal(t, user.ID, ch.Members[0].User.ID, "members contain user id")
require.True(t, ch.Members[0].Invited, "member is invited")
require.Nil(t, ch.Members[0].InviteAcceptedAt, "invite is not accepted")
require.Nil(t, ch.Members[0].InviteRejectedAt, "invite is not rejected")
}

func TestChannel_Moderation(t *testing.T) {
Expand All @@ -251,7 +250,7 @@ func TestChannel_Moderation(t *testing.T) {
require.NoError(t, err, "create channel")
ch := resp.Channel

assert.Empty(t, ch.Members, "members are empty")
require.Empty(t, ch.Members, "members are empty")

user := randomUser(t, c)

Expand All @@ -265,17 +264,17 @@ func TestChannel_Moderation(t *testing.T) {
// refresh channel state
require.NoError(t, ch.refresh(ctx), "refresh channel")

assert.Equal(t, user.ID, ch.Members[0].User.ID, "user exists")
assert.Equal(t, "moderator", ch.Members[0].Role, "user role is moderator")
require.Equal(t, user.ID, ch.Members[0].User.ID, "user exists")
require.Equal(t, "moderator", ch.Members[0].Role, "user role is moderator")

_, err = ch.DemoteModerators(ctx, user.ID)
require.NoError(t, err, "demote moderators")

// refresh channel state
require.NoError(t, ch.refresh(ctx), "refresh channel")

assert.Equal(t, user.ID, ch.Members[0].User.ID, "user exists")
assert.Equal(t, "member", ch.Members[0].Role, "user role is member")
require.Equal(t, user.ID, ch.Members[0].User.ID, "user exists")
require.Equal(t, "member", ch.Members[0].Role, "user role is member")
}

func TestChannel_Delete(t *testing.T) {
Expand Down Expand Up @@ -305,7 +304,7 @@ func TestChannel_GetReplies(t *testing.T) {

repliesResp, err := ch.GetReplies(ctx, msg.ID, nil)
require.NoError(t, err, "get replies")
assert.Len(t, repliesResp.Messages, 1)
require.Len(t, repliesResp.Messages, 1)
}

func TestChannel_RemoveMembers(t *testing.T) {
Expand All @@ -322,7 +321,7 @@ func TestChannel_RemoveMembers(t *testing.T) {
require.NoError(t, err, "remove members")

for _, member := range ch.Members {
assert.NotEqual(t, member.User.ID, user.ID, "member is not present")
require.NotEqual(t, member.User.ID, user.ID, "member is not present")
}
}

Expand Down Expand Up @@ -358,8 +357,8 @@ func TestChannel_SendMessage(t *testing.T) {

// check that message was updated
msg = resp.Message
assert.NotEmpty(t, msg.ID, "message has ID")
assert.NotEmpty(t, msg.HTML, "message has HTML body")
require.NotEmpty(t, msg.ID, "message has ID")
require.NotEmpty(t, msg.HTML, "message has HTML body")

msg2 := &Message{
Text: "text message 2",
Expand All @@ -371,9 +370,9 @@ func TestChannel_SendMessage(t *testing.T) {

// check that message was updated
msg2 = resp.Message
assert.NotEmpty(t, msg2.ID, "message has ID")
assert.NotEmpty(t, msg2.HTML, "message has HTML body")
assert.True(t, msg2.Silent, "message silent flag is set")
require.NotEmpty(t, msg2.ID, "message has ID")
require.NotEmpty(t, msg2.HTML, "message has HTML body")
require.True(t, msg2.Silent, "message silent flag is set")
}

func TestChannel_SendSystemMessage(t *testing.T) {
Expand All @@ -391,8 +390,8 @@ func TestChannel_SendSystemMessage(t *testing.T) {

// check that message was updated
msg = resp.Message
assert.NotEmpty(t, msg.ID, "message has ID")
assert.Equal(t, MessageTypeSystem, msg.Type, "message type is system")
require.NotEmpty(t, msg.ID, "message has ID")
require.Equal(t, MessageTypeSystem, msg.Type, "message type is system")
}

func TestChannel_Truncate(t *testing.T) {
Expand All @@ -410,13 +409,13 @@ func TestChannel_Truncate(t *testing.T) {
resp, err := ch.SendMessage(ctx, msg, user.ID)
require.NoError(t, err, "send message")
require.NoError(t, ch.refresh(ctx), "refresh channel")
assert.Equal(t, ch.Messages[0].ID, resp.Message.ID, "message exists")
require.Equal(t, ch.Messages[0].ID, resp.Message.ID, "message exists")

// Now truncate it
_, err = ch.Truncate(ctx)
require.NoError(t, err, "truncate channel")
require.NoError(t, ch.refresh(ctx), "refresh channel")
assert.Empty(t, ch.Messages, "channel is empty")
require.Empty(t, ch.Messages, "channel is empty")
}

func TestChannel_TruncateWithOptions(t *testing.T) {
Expand All @@ -434,7 +433,7 @@ func TestChannel_TruncateWithOptions(t *testing.T) {
resp, err := ch.SendMessage(ctx, msg, user.ID)
require.NoError(t, err, "send message")
require.NoError(t, ch.refresh(ctx), "refresh channel")
assert.Equal(t, ch.Messages[0].ID, resp.Message.ID, "message exists")
require.Equal(t, ch.Messages[0].ID, resp.Message.ID, "message exists")

// Now truncate it
_, err = ch.Truncate(ctx,
Expand Down
11 changes: 5 additions & 6 deletions channel_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -40,10 +39,10 @@ func TestClient_GetChannelType(t *testing.T) {
resp, err := c.GetChannelType(ctx, ct.Name)
require.NoError(t, err, "get channel type")

assert.Equal(t, ct.Name, resp.ChannelType.Name)
assert.Equal(t, len(ct.Commands), len(resp.ChannelType.Commands))
assert.Equal(t, ct.Permissions, resp.ChannelType.Permissions)
assert.NotEmpty(t, resp.Grants)
require.Equal(t, ct.Name, resp.ChannelType.Name)
require.Equal(t, len(ct.Commands), len(resp.ChannelType.Commands))
require.Equal(t, ct.Permissions, resp.ChannelType.Permissions)
require.NotEmpty(t, resp.Grants)
}

func TestClient_ListChannelTypes(t *testing.T) {
Expand All @@ -54,7 +53,7 @@ func TestClient_ListChannelTypes(t *testing.T) {
resp, err := c.ListChannelTypes(ctx)
require.NoError(t, err, "list channel types")

assert.Contains(t, resp.ChannelTypes, ct.Name)
require.Contains(t, resp.ChannelTypes, ct.Name)
}

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

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -35,8 +34,8 @@ func TestClient_GetCommand(t *testing.T) {
resp, err := c.GetCommand(ctx, cmd.Name)
require.NoError(t, err, "get command")

assert.Equal(t, cmd.Name, resp.Command.Name)
assert.Equal(t, cmd.Description, resp.Command.Description)
require.Equal(t, cmd.Name, resp.Command.Name)
require.Equal(t, cmd.Description, resp.Command.Description)
}

func TestClient_ListCommands(t *testing.T) {
Expand All @@ -47,7 +46,7 @@ func TestClient_ListCommands(t *testing.T) {
resp, err := c.ListCommands(ctx)
require.NoError(t, err, "list commands")

assert.Contains(t, resp.Commands, cmd)
require.Contains(t, resp.Commands, cmd)
}

func TestClient_UpdateCommand(t *testing.T) {
Expand All @@ -59,8 +58,8 @@ func TestClient_UpdateCommand(t *testing.T) {
resp, err := c.UpdateCommand(ctx, cmd.Name, &update)
require.NoError(t, err, "update command")

assert.Equal(t, cmd.Name, resp.Command.Name)
assert.Equal(t, "new description", resp.Command.Description)
require.Equal(t, cmd.Name, resp.Command.Name)
require.Equal(t, "new description", resp.Command.Description)
}

// See https://getstream.io/chat/docs/custom_commands/ for more details.
Expand Down
5 changes: 2 additions & 3 deletions device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand All @@ -14,7 +13,7 @@ func TestClient_Devices(t *testing.T) {
user := randomUser(t, c)

devices := []*Device{
{UserID: user.ID, ID: randomString(12), PushProvider: PushProviderFirebase},
{UserID: user.ID, ID: "xxxx", PushProvider: PushProviderFirebase},
{UserID: user.ID, ID: randomString(12), PushProvider: PushProviderAPNS},
}

Expand All @@ -25,7 +24,7 @@ func TestClient_Devices(t *testing.T) {
resp, err := c.GetDevices(ctx, user.ID)
require.NoError(t, err, "get devices")

assert.True(t, deviceIDExists(resp.Devices, dev.ID), "device with ID %s was created", dev.ID)
require.True(t, deviceIDExists(resp.Devices, dev.ID), "device with ID %s was created", dev.ID)
_, err = c.DeleteDevice(ctx, user.ID, dev.ID)
require.NoError(t, err, "delete device")
}
Expand Down
3 changes: 1 addition & 2 deletions event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -39,7 +38,7 @@ func TestEventSupportsAllFields(t *testing.T) {
t.Errorf("Error unmarshaling %q: %v", name, err)
}

assert.Equal(t, name, result.Type)
require.Equal(t, name, result.Type)
}
}

Expand Down
37 changes: 18 additions & 19 deletions message_history_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand All @@ -29,12 +28,12 @@ func TestMessageHistory(t *testing.T) {
updatedCustomFieldValue := "updated custom value"
// update the message by user1
_, err = client.UpdateMessage(ctx, &Message{Text: updatedText1, ExtraData: map[string]interface{}{customField: updatedCustomFieldValue}, UserID: user1.ID}, message.ID)
assert.NoError(t, err)
require.NoError(t, err)

updatedText2 := "updated text 2"
// update the message by user2
_, err = client.UpdateMessage(ctx, &Message{Text: updatedText2, UserID: user2.ID}, message.ID)
assert.NoError(t, err)
require.NoError(t, err)

t.Run("test query", func(t *testing.T) {
req := QueryMessageHistoryRequest{
Expand All @@ -43,21 +42,21 @@ func TestMessageHistory(t *testing.T) {
},
}
messageHistoryResponse, err := client.QueryMessageHistory(ctx, req)
assert.NoError(t, err)
assert.NotNil(t, messageHistoryResponse)
require.NoError(t, err)
require.NotNil(t, messageHistoryResponse)

history := messageHistoryResponse.MessageHistory
assert.Equal(t, 2, len(history))
require.Equal(t, 2, len(history))

firstUpdate := history[1]
assert.Equal(t, initialText, firstUpdate.Text)
assert.Equal(t, user1.ID, firstUpdate.MessageUpdatedByID)
assert.Equal(t, initialCustomFieldValue, firstUpdate.ExtraData[customField].(string))
require.Equal(t, initialText, firstUpdate.Text)
require.Equal(t, user1.ID, firstUpdate.MessageUpdatedByID)
require.Equal(t, initialCustomFieldValue, firstUpdate.ExtraData[customField].(string))

secondUpdate := history[0]
assert.Equal(t, updatedText1, secondUpdate.Text)
assert.Equal(t, user2.ID, secondUpdate.MessageUpdatedByID)
assert.Equal(t, updatedCustomFieldValue, secondUpdate.ExtraData[customField].(string))
require.Equal(t, updatedText1, secondUpdate.Text)
require.Equal(t, user2.ID, secondUpdate.MessageUpdatedByID)
require.Equal(t, updatedCustomFieldValue, secondUpdate.ExtraData[customField].(string))
})

t.Run("test sorting", func(t *testing.T) {
Expand All @@ -73,18 +72,18 @@ func TestMessageHistory(t *testing.T) {
},
}
sortedHistoryResponse, err := client.QueryMessageHistory(ctx, sortedHistoryQueryRequest)
assert.NoError(t, err)
assert.NotNil(t, sortedHistoryResponse)
require.NoError(t, err)
require.NotNil(t, sortedHistoryResponse)

sortedHistory := sortedHistoryResponse.MessageHistory
assert.Equal(t, 2, len(sortedHistory))
require.Equal(t, 2, len(sortedHistory))

firstUpdate := sortedHistory[0]
assert.Equal(t, initialText, firstUpdate.Text)
assert.Equal(t, user1.ID, firstUpdate.MessageUpdatedByID)
require.Equal(t, initialText, firstUpdate.Text)
require.Equal(t, user1.ID, firstUpdate.MessageUpdatedByID)

secondUpdate := sortedHistory[1]
assert.Equal(t, updatedText1, secondUpdate.Text)
assert.Equal(t, user2.ID, secondUpdate.MessageUpdatedByID)
require.Equal(t, updatedText1, secondUpdate.Text)
require.Equal(t, user2.ID, secondUpdate.MessageUpdatedByID)
})
}
Loading