Channels/api4 testing improvements (#22938)

* api4/post_test: fix missing TearDown

* api4/plugin_test: dont test timeout, saving 120s

* api4/channel_test: dont try to delete town square

* api4/channel_test: check public channel names deterministically

* api4/file_test: fix darwin assertions on go files

* api4/notify_admin_test: fix expect/actual order

* api4/team_test: make TestGetAllTeams deterministic

* api4/plugin_test: avoid nested test helpers

* api4/post_test: avoid nested test helpers

* api4/websocket_test: externalize log buffer

* testlib/helper: unset common env

* linting issues

* simplify TestGetFileHeaders

* team_test: leverage ElementsMatch
Этот коммит содержится в:
Jesse Hallam
2023-04-20 09:52:59 -03:00
коммит произвёл GitHub
родитель dd2b1db420
Коммит 89f2ebc836
9 изменённых файлов: 232 добавлений и 138 удалений

Просмотреть файл

@@ -859,14 +859,23 @@ func TestGetPublicChannelsForTeam(t *testing.T) {
require.NoError(t, err)
require.Len(t, channels, 4, "wrong path")
for i, c := range channels {
var foundPublicChannel1, foundPublicChannel2 bool
for _, c := range channels {
// check all channels included are open
require.Equal(t, model.ChannelTypeOpen, c.Type, "should include open channel only")
// only check the created 2 public channels
require.False(t, i < 2 && !(c.DisplayName == publicChannel1.DisplayName || c.DisplayName == publicChannel2.DisplayName), "should match public channel display name")
switch c.DisplayName {
case publicChannel1.DisplayName:
foundPublicChannel1 = true
case publicChannel2.DisplayName:
foundPublicChannel2 = true
}
}
require.True(t, foundPublicChannel1, "failed to find publicChannel1")
require.True(t, foundPublicChannel2, "failed to find publicChannel2")
privateChannel := th.CreatePrivateChannel()
channels, _, err = client.GetPublicChannelsForTeam(team.Id, 0, 100, "")
require.NoError(t, err)
@@ -1135,9 +1144,14 @@ func TestGetAllChannels(t *testing.T) {
require.NoError(t, err)
beforeCount := len(channels)
firstChannel := channels[0].Channel
deletedChannel := channels[0].Channel
_, err = client.DeleteChannel(firstChannel.Id)
// Never try to delete the default channel
if deletedChannel.Name == "town-square" {
deletedChannel = channels[1].Channel
}
_, err = client.DeleteChannel(deletedChannel.Id)
require.NoError(t, err)
channels, _, err = client.GetAllChannels(0, 10000, "")
@@ -1147,7 +1161,7 @@ func TestGetAllChannels(t *testing.T) {
}
require.NoError(t, err)
require.Len(t, channels, beforeCount-1)
require.NotContains(t, ids, firstChannel.Id)
require.NotContains(t, ids, deletedChannel.Id)
channels, _, err = client.GetAllChannelsIncludeDeleted(0, 10000, "")
ids = []string{}
@@ -1156,7 +1170,7 @@ func TestGetAllChannels(t *testing.T) {
}
require.NoError(t, err)
require.True(t, len(channels) > beforeCount)
require.Contains(t, ids, firstChannel.Id)
require.Contains(t, ids, deletedChannel.Id)
})
_, resp, err := client.GetAllChannels(0, 20, "")