Fix staticcheck errors from _test.go files (#18033)

Automatic Merge
Этот коммит содержится в:
dave
2021-08-10 13:15:03 +08:00
коммит произвёл GitHub
родитель 3f01129ddf
Коммит 16c2925ba2
28 изменённых файлов: 70 добавлений и 88 удалений

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

@@ -1450,7 +1450,7 @@ func TestConvertBotToUser(t *testing.T) {
require.NotNil(t, user)
require.Equal(t, bot.UserId, user.Id)
bot, resp = client.GetBot(bot.UserId, "")
_, resp = client.GetBot(bot.UserId, "")
CheckNotFoundStatus(t, resp)
bot = &model.Bot{
@@ -1466,7 +1466,7 @@ func TestConvertBotToUser(t *testing.T) {
require.Equal(t, bot.UserId, user.Id)
require.Contains(t, user.GetRoles(), model.SystemAdminRoleId)
bot, resp = client.GetBot(bot.UserId, "")
_, resp = client.GetBot(bot.UserId, "")
CheckNotFoundStatus(t, resp)
})
}

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

@@ -180,13 +180,13 @@ func TestUpdateChannel(t *testing.T) {
// Test that changing the type fails and returns error
private.Type = model.ChannelTypeOpen
newPrivateChannel, resp = Client.UpdateChannel(private)
_, resp = Client.UpdateChannel(private)
CheckBadRequestStatus(t, resp)
// Test that keeping the same type succeeds
private.Type = model.ChannelTypePrivate
newPrivateChannel, resp = Client.UpdateChannel(private)
_, resp = Client.UpdateChannel(private)
CheckNoError(t, resp)
//Non existing channel

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

@@ -63,13 +63,6 @@ func TestGetConfigWithAccessTag(t *testing.T) {
th := Setup(t)
defer th.TearDown()
varyByHeader := *&th.App.Config().RateLimitSettings.VaryByHeader // environment perm.
supportEmail := *&th.App.Config().SupportSettings.SupportEmail // site perm.
defer th.App.UpdateConfig(func(cfg *model.Config) {
cfg.RateLimitSettings.VaryByHeader = varyByHeader
cfg.SupportSettings.SupportEmail = supportEmail
})
// set some values so that we know they're not blank
mockVaryByHeader := model.NewId()
mockSupportEmail := model.NewId() + "@mattermost.com"
@@ -353,7 +346,7 @@ func TestUpdateConfigMessageExportSpecialHandling(t *testing.T) {
CheckNoError(t, resp)
*cfg.MessageExportSettings.EnableExport = true
cfg, resp = th.SystemAdminClient.UpdateConfig(cfg)
_, resp = th.SystemAdminClient.UpdateConfig(cfg)
CheckNoError(t, resp)
assert.True(t, *th.App.Config().MessageExportSettings.EnableExport)
@@ -364,7 +357,7 @@ func TestUpdateConfigMessageExportSpecialHandling(t *testing.T) {
CheckNoError(t, resp)
*cfg.MessageExportSettings.EnableExport = false
cfg, resp = th.SystemAdminClient.UpdateConfig(cfg)
_, resp = th.SystemAdminClient.UpdateConfig(cfg)
CheckNoError(t, resp)
assert.False(t, *th.App.Config().MessageExportSettings.EnableExport)
@@ -381,7 +374,7 @@ func TestUpdateConfigMessageExportSpecialHandling(t *testing.T) {
CheckNoError(t, resp)
*cfg.MessageExportSettings.EnableExport = true
cfg, resp = th.SystemAdminClient.UpdateConfig(cfg)
_, resp = th.SystemAdminClient.UpdateConfig(cfg)
CheckNoError(t, resp)
assert.True(t, *th.App.Config().MessageExportSettings.EnableExport)
@@ -392,7 +385,7 @@ func TestUpdateConfigMessageExportSpecialHandling(t *testing.T) {
CheckNoError(t, resp)
*cfg.MessageExportSettings.EnableExport = false
cfg, resp = th.SystemAdminClient.UpdateConfig(cfg)
_, resp = th.SystemAdminClient.UpdateConfig(cfg)
CheckNoError(t, resp)
assert.False(t, *th.App.Config().MessageExportSettings.EnableExport)
@@ -745,7 +738,7 @@ func TestPatchConfig(t *testing.T) {
SiteURL: model.NewString(""),
},
}
updatedConfig, resp = th.SystemAdminClient.PatchConfig(&config)
_, resp = th.SystemAdminClient.PatchConfig(&config)
CheckBadRequestStatus(t, resp)
CheckErrorMessage(t, resp, "api.config.update_config.clear_siteurl.app_error")

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

@@ -128,7 +128,7 @@ func TestCreateEmoji(t *testing.T) {
Name: model.NewId(),
}
newEmoji, resp = Client.CreateEmoji(emoji, utils.CreateTestGif(t, 10, app.MaxEmojiOriginalWidth+1), "image.gif")
_, resp = Client.CreateEmoji(emoji, utils.CreateTestGif(t, 10, app.MaxEmojiOriginalWidth+1), "image.gif")
require.NotNil(t, resp.Error, "should fail - emoji is too wide")
// try to create an emoji that's too tall
@@ -137,7 +137,7 @@ func TestCreateEmoji(t *testing.T) {
Name: model.NewId(),
}
newEmoji, resp = Client.CreateEmoji(emoji, utils.CreateTestGif(t, app.MaxEmojiOriginalHeight+1, 10), "image.gif")
_, resp = Client.CreateEmoji(emoji, utils.CreateTestGif(t, app.MaxEmojiOriginalHeight+1, 10), "image.gif")
require.NotNil(t, resp.Error, "should fail - emoji is too tall")
// try to create an emoji that's too large

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

@@ -669,8 +669,8 @@ func TestUploadFiles(t *testing.T) {
require.NoError(t, err)
if !bytes.Equal(data, expected) {
tf, err := ioutil.TempFile("", fmt.Sprintf("test_%v_*_%s", i, name))
defer tf.Close()
require.NoError(t, err)
defer tf.Close()
_, err = io.Copy(tf, bytes.NewReader(data))
require.NoError(t, err)
t.Errorf("Actual data mismatched %s, written to %q - expected %d bytes, got %d.", name, tf.Name(), len(expected), len(data))

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

@@ -553,7 +553,7 @@ func TestPatchGroupTeam(t *testing.T) {
assert.Equal(t, model.GroupSyncableTypeTeam, groupSyncable.Type)
patch.AutoAdd = model.NewBool(true)
groupSyncable, response = th.SystemAdminClient.PatchGroupSyncable(g.Id, th.BasicTeam.Id, model.GroupSyncableTypeTeam, patch)
_, response = th.SystemAdminClient.PatchGroupSyncable(g.Id, th.BasicTeam.Id, model.GroupSyncableTypeTeam, patch)
CheckOKStatus(t, response)
_, response = th.SystemAdminClient.PatchGroupSyncable(model.NewId(), th.BasicTeam.Id, model.GroupSyncableTypeTeam, patch)
@@ -628,7 +628,7 @@ func TestPatchGroupChannel(t *testing.T) {
assert.Equal(t, model.GroupSyncableTypeChannel, groupSyncable.Type)
patch.AutoAdd = model.NewBool(true)
groupSyncable, response = th.SystemAdminClient.PatchGroupSyncable(g.Id, th.BasicChannel.Id, model.GroupSyncableTypeChannel, patch)
_, response = th.SystemAdminClient.PatchGroupSyncable(g.Id, th.BasicChannel.Id, model.GroupSyncableTypeChannel, patch)
CheckOKStatus(t, response)
_, response = th.SystemAdminClient.PatchGroupSyncable(model.NewId(), th.BasicChannel.Id, model.GroupSyncableTypeChannel, patch)

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

@@ -345,7 +345,7 @@ func testCreatePostWithOutgoingHook(
ResponseType: respPostType,
}
fmt.Fprintf(w, outGoingHookResponse.ToJson())
fmt.Fprint(w, outGoingHookResponse.ToJson())
success <- true
}))
defer ts.Close()
@@ -835,7 +835,7 @@ func TestUpdateOthersPostInDirectMessageChannel(t *testing.T) {
CheckNoError(t, resp)
post.Message = "changed"
post, resp = th.SystemAdminClient.UpdatePost(post.Id, post)
_, resp = th.SystemAdminClient.UpdatePost(post.Id, post)
CheckNoError(t, resp)
}
@@ -1422,7 +1422,7 @@ func TestGetPostsBefore(t *testing.T) {
require.Equal(t, post3.Id, posts.NextPostId, "should match NextPostId")
require.Equal(t, post1.Id, posts.PrevPostId, "should match PrevPostId")
posts, resp = Client.GetPostsBefore(th.BasicChannel.Id, "junk", 1, 1, "", false)
_, resp = Client.GetPostsBefore(th.BasicChannel.Id, "junk", 1, 1, "", false)
CheckBadRequestStatus(t, resp)
posts, resp = Client.GetPostsBefore(th.BasicChannel.Id, post5.Id, 0, 3, "", false)
@@ -1562,7 +1562,7 @@ func TestGetPostsAfter(t *testing.T) {
require.Equal(t, post5.Id, posts.NextPostId, "should match NextPostId")
require.Equal(t, post3.Id, posts.PrevPostId, "should match PrevPostId")
posts, resp = Client.GetPostsAfter(th.BasicChannel.Id, "junk", 1, 1, "", false)
_, resp = Client.GetPostsAfter(th.BasicChannel.Id, "junk", 1, 1, "", false)
CheckBadRequestStatus(t, resp)
posts, resp = Client.GetPostsAfter(th.BasicChannel.Id, post1.Id, 0, 3, "", false)

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

@@ -2015,7 +2015,7 @@ func TestAddTeamMember(t *testing.T) {
_, resp = Client.Login(guest.Email, guest.Password)
CheckNoError(t, resp)
tm, resp = Client.AddTeamMemberFromInvite("", team.InviteId)
_, resp = Client.AddTeamMemberFromInvite("", team.InviteId)
CheckForbiddenStatus(t, resp)
// by invite_id
@@ -2046,11 +2046,11 @@ func TestAddTeamMember(t *testing.T) {
model.MapToJson(map[string]string{"teamId": team.Id}),
)
require.NoError(t, th.App.Srv().Store.Token().Save(token))
tm, resp = Client.AddTeamMemberFromInvite(token.Token, "")
_, resp = Client.AddTeamMemberFromInvite(token.Token, "")
require.Equal(t, "app.team.invite_token.group_constrained.error", resp.Error.Id)
// Attempt to use an invite id
tm, resp = Client.AddTeamMemberFromInvite("", team.InviteId)
_, resp = Client.AddTeamMemberFromInvite("", team.InviteId)
require.Equal(t, "app.team.invite_id.group_constrained.error", resp.Error.Id)
// User is not in associated groups so shouldn't be allowed

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

@@ -5453,12 +5453,10 @@ func TestGetThreadsForUser(t *testing.T) {
var rootIds []*model.Post
for i := 0; i < 30; i++ {
time.Sleep(1)
rpost, resp := Client.CreatePost(&model.Post{ChannelId: th.BasicChannel.Id, Message: "testMsg"})
CheckNoError(t, resp)
CheckCreatedStatus(t, resp)
rootIds = append(rootIds, rpost)
time.Sleep(1)
_, resp2 := Client.CreatePost(&model.Post{ChannelId: th.BasicChannel.Id, Message: "testReply", RootId: rpost.Id})
CheckNoError(t, resp2)
CheckCreatedStatus(t, resp2)
@@ -5482,10 +5480,8 @@ func TestGetThreadsForUser(t *testing.T) {
var rootIds []*model.Post
for i := 0; i < 30; i++ {
time.Sleep(1)
rpost, _ := postAndCheck(t, Client, &model.Post{ChannelId: th.BasicChannel.Id, Message: fmt.Sprintf("testMsg-%d", i)})
rootIds = append(rootIds, rpost)
time.Sleep(1)
postAndCheck(t, Client, &model.Post{ChannelId: th.BasicChannel.Id, Message: fmt.Sprintf("testReply-%d", i), RootId: rpost.Id})
}
rootId := rootIds[15].Id // middle point
@@ -5822,14 +5818,11 @@ func TestThreadCounts(t *testing.T) {
// create a post by regular user
rpost, _ := postAndCheck(t, Client, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testMsg"})
// reply with another
time.Sleep(1)
postAndCheck(t, th.SystemAdminClient, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testReply", RootId: rpost.Id})
// create another post by regular user
time.Sleep(1)
rpost2, _ := postAndCheck(t, Client, &model.Post{ChannelId: th.BasicChannel2.Id, Message: "testMsg1"})
// reply with another 2 times
time.Sleep(1)
postAndCheck(t, th.SystemAdminClient, &model.Post{ChannelId: th.BasicChannel2.Id, Message: "testReply2", RootId: rpost2.Id})
postAndCheck(t, th.SystemAdminClient, &model.Post{ChannelId: th.BasicChannel2.Id, Message: "testReply22", RootId: rpost2.Id})
@@ -5868,12 +5861,10 @@ func TestSingleThreadGet(t *testing.T) {
// create a post by regular user
rpost, _ := postAndCheck(t, Client, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testMsg"})
// reply with another
time.Sleep(1)
postAndCheck(t, th.SystemAdminClient, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testReply", RootId: rpost.Id})
// create another thread to check that we are not returning it by mistake
rpost2, _ := postAndCheck(t, Client, &model.Post{ChannelId: th.BasicChannel2.Id, Message: "testMsg2"})
time.Sleep(1)
postAndCheck(t, th.SystemAdminClient, &model.Post{ChannelId: th.BasicChannel2.Id, Message: "testReply", RootId: rpost2.Id})
// regular user should have two threads with 3 replies total
@@ -5982,7 +5973,6 @@ func TestReadThreads(t *testing.T) {
CheckNoError(t, resp)
require.Len(t, uss.Threads, 1)
time.Sleep(1)
resp = th.Client.UpdateThreadsReadForUser(th.BasicUser.Id, th.BasicTeam.Id)
CheckNoError(t, resp)
CheckOKStatus(t, resp)
@@ -6044,9 +6034,7 @@ func TestMarkThreadUnreadMentionCount(t *testing.T) {
require.Nil(t, appErr)
rpost, _ := postAndCheck(t, Client, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testMsg @" + th.BasicUser2.Username})
time.Sleep(1)
reply, _ := postAndCheck(t, Client, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testReply1", RootId: rpost.Id})
time.Sleep(1)
postAndCheck(t, Client, &model.Post{ChannelId: th.BasicChannel.Id, Message: "testReply2", RootId: rpost.Id})
th.SystemAdminClient.UpdateThreadReadForUser(th.BasicUser2.Id, th.BasicTeam.Id, rpost.Id, model.GetMillis())

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

@@ -130,7 +130,7 @@ func TestCreateIncomingWebhook_BypassTeamPermissions(t *testing.T) {
channel := th.CreateChannelWithClientAndTeam(th.SystemAdminClient, model.ChannelTypeOpen, team.Id)
hook = &model.IncomingWebhook{ChannelId: channel.Id}
rhook, resp = th.Client.CreateIncomingWebhook(hook)
_, resp = th.Client.CreateIncomingWebhook(hook)
CheckForbiddenStatus(t, resp)
}
@@ -915,7 +915,7 @@ func TestUpdateIncomingWebhook_BypassTeamPermissions(t *testing.T) {
channel := th.CreateChannelWithClientAndTeam(th.SystemAdminClient, model.ChannelTypeOpen, team.Id)
hook2 := &model.IncomingWebhook{Id: rhook.Id, ChannelId: channel.Id}
rhook, resp = th.Client.UpdateIncomingWebhook(hook2)
_, resp = th.Client.UpdateIncomingWebhook(hook2)
CheckBadRequestStatus(t, resp)
}
@@ -1171,7 +1171,7 @@ func TestUpdateOutgoingWebhook_BypassTeamPermissions(t *testing.T) {
channel := th.CreateChannelWithClientAndTeam(th.SystemAdminClient, model.ChannelTypeOpen, team.Id)
hook2 := &model.OutgoingWebhook{Id: rhook.Id, ChannelId: channel.Id}
rhook, resp = th.Client.UpdateOutgoingWebhook(hook2)
_, resp = th.Client.UpdateOutgoingWebhook(hook2)
CheckForbiddenStatus(t, resp)
}