Fix: bot_test errcheck issue (#28822)
Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
64b30abbce
Коммит
4f5a389185
@@ -92,7 +92,6 @@ issues:
|
|||||||
channels/app/authorization_test.go|\
|
channels/app/authorization_test.go|\
|
||||||
channels/app/auto_responder_test.go|\
|
channels/app/auto_responder_test.go|\
|
||||||
channels/app/bot.go|\
|
channels/app/bot.go|\
|
||||||
channels/app/bot_test.go|\
|
|
||||||
channels/app/brand.go|\
|
channels/app/brand.go|\
|
||||||
channels/app/busy_test.go|\
|
channels/app/busy_test.go|\
|
||||||
channels/app/channel.go|\
|
channels/app/channel.go|\
|
||||||
|
|||||||
@@ -79,7 +79,10 @@ func TestCreateBot(t *testing.T) {
|
|||||||
OwnerId: th.BasicUser.Id,
|
OwnerId: th.BasicUser.Id,
|
||||||
})
|
})
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
defer th.App.PermanentDeleteBot(th.Context, bot.UserId)
|
defer func() {
|
||||||
|
err = th.App.PermanentDeleteBot(th.Context, bot.UserId)
|
||||||
|
require.Nil(t, err)
|
||||||
|
}()
|
||||||
assert.Equal(t, "username", bot.Username)
|
assert.Equal(t, "username", bot.Username)
|
||||||
assert.Equal(t, "a bot", bot.Description)
|
assert.Equal(t, "a bot", bot.Description)
|
||||||
assert.Equal(t, th.BasicUser.Id, bot.OwnerId)
|
assert.Equal(t, th.BasicUser.Id, bot.OwnerId)
|
||||||
@@ -197,7 +200,10 @@ func TestPatchBot(t *testing.T) {
|
|||||||
OwnerId: th.BasicUser.Id,
|
OwnerId: th.BasicUser.Id,
|
||||||
})
|
})
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
defer th.App.PermanentDeleteBot(th.Context, bot.UserId)
|
defer func() {
|
||||||
|
err = th.App.PermanentDeleteBot(th.Context, bot.UserId)
|
||||||
|
require.Nil(t, err)
|
||||||
|
}()
|
||||||
|
|
||||||
botPatch := &model.BotPatch{
|
botPatch := &model.BotPatch{
|
||||||
Username: sToP("invalid username"),
|
Username: sToP("invalid username"),
|
||||||
@@ -220,7 +226,10 @@ func TestPatchBot(t *testing.T) {
|
|||||||
OwnerId: th.BasicUser.Id,
|
OwnerId: th.BasicUser.Id,
|
||||||
})
|
})
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
defer th.App.PermanentDeleteBot(th.Context, bot.UserId)
|
defer func() {
|
||||||
|
err = th.App.PermanentDeleteBot(th.Context, bot.UserId)
|
||||||
|
require.Nil(t, err)
|
||||||
|
}()
|
||||||
|
|
||||||
botPatch := &model.BotPatch{
|
botPatch := &model.BotPatch{
|
||||||
Username: sToP("username"),
|
Username: sToP("username"),
|
||||||
@@ -246,7 +255,10 @@ func TestPatchBot(t *testing.T) {
|
|||||||
|
|
||||||
createdBot, err := th.App.CreateBot(th.Context, bot)
|
createdBot, err := th.App.CreateBot(th.Context, bot)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
defer th.App.PermanentDeleteBot(th.Context, createdBot.UserId)
|
defer func() {
|
||||||
|
err = th.App.PermanentDeleteBot(th.Context, createdBot.UserId)
|
||||||
|
require.Nil(t, err)
|
||||||
|
}()
|
||||||
|
|
||||||
botPatch := &model.BotPatch{
|
botPatch := &model.BotPatch{
|
||||||
Username: sToP("username2"),
|
Username: sToP("username2"),
|
||||||
@@ -278,7 +290,10 @@ func TestPatchBot(t *testing.T) {
|
|||||||
OwnerId: th.BasicUser.Id,
|
OwnerId: th.BasicUser.Id,
|
||||||
})
|
})
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
defer th.App.PermanentDeleteBot(th.Context, bot.UserId)
|
defer func() {
|
||||||
|
err = th.App.PermanentDeleteBot(th.Context, bot.UserId)
|
||||||
|
require.Nil(t, err)
|
||||||
|
}()
|
||||||
|
|
||||||
botPatch := &model.BotPatch{
|
botPatch := &model.BotPatch{
|
||||||
Username: sToP(th.BasicUser2.Username),
|
Username: sToP(th.BasicUser2.Username),
|
||||||
@@ -300,7 +315,10 @@ func TestGetBot(t *testing.T) {
|
|||||||
OwnerId: th.BasicUser.Id,
|
OwnerId: th.BasicUser.Id,
|
||||||
})
|
})
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
defer th.App.PermanentDeleteBot(th.Context, bot1.UserId)
|
defer func() {
|
||||||
|
err = th.App.PermanentDeleteBot(th.Context, bot1.UserId)
|
||||||
|
require.Nil(t, err)
|
||||||
|
}()
|
||||||
|
|
||||||
bot2, err := th.App.CreateBot(th.Context, &model.Bot{
|
bot2, err := th.App.CreateBot(th.Context, &model.Bot{
|
||||||
Username: "username2",
|
Username: "username2",
|
||||||
@@ -308,7 +326,10 @@ func TestGetBot(t *testing.T) {
|
|||||||
OwnerId: th.BasicUser.Id,
|
OwnerId: th.BasicUser.Id,
|
||||||
})
|
})
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
defer th.App.PermanentDeleteBot(th.Context, bot2.UserId)
|
defer func() {
|
||||||
|
err = th.App.PermanentDeleteBot(th.Context, bot2.UserId)
|
||||||
|
require.Nil(t, err)
|
||||||
|
}()
|
||||||
|
|
||||||
deletedBot, err := th.App.CreateBot(th.Context, &model.Bot{
|
deletedBot, err := th.App.CreateBot(th.Context, &model.Bot{
|
||||||
Username: "username3",
|
Username: "username3",
|
||||||
@@ -318,7 +339,10 @@ func TestGetBot(t *testing.T) {
|
|||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
deletedBot, err = th.App.UpdateBotActive(th.Context, deletedBot.UserId, false)
|
deletedBot, err = th.App.UpdateBotActive(th.Context, deletedBot.UserId, false)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
defer th.App.PermanentDeleteBot(th.Context, deletedBot.UserId)
|
defer func() {
|
||||||
|
err := th.App.PermanentDeleteBot(th.Context, deletedBot.UserId)
|
||||||
|
require.Nil(t, err)
|
||||||
|
}()
|
||||||
|
|
||||||
t.Run("get unknown bot", func(t *testing.T) {
|
t.Run("get unknown bot", func(t *testing.T) {
|
||||||
_, err := th.App.GetBot(th.Context, model.NewId(), false)
|
_, err := th.App.GetBot(th.Context, model.NewId(), false)
|
||||||
@@ -364,7 +388,10 @@ func TestGetBots(t *testing.T) {
|
|||||||
OwnerId: OwnerId1,
|
OwnerId: OwnerId1,
|
||||||
})
|
})
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
defer th.App.PermanentDeleteBot(th.Context, bot1.UserId)
|
defer func() {
|
||||||
|
err = th.App.PermanentDeleteBot(th.Context, bot1.UserId)
|
||||||
|
require.Nil(t, err)
|
||||||
|
}()
|
||||||
|
|
||||||
deletedBot1, err := th.App.CreateBot(th.Context, &model.Bot{
|
deletedBot1, err := th.App.CreateBot(th.Context, &model.Bot{
|
||||||
Username: "username4",
|
Username: "username4",
|
||||||
@@ -374,7 +401,10 @@ func TestGetBots(t *testing.T) {
|
|||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
deletedBot1, err = th.App.UpdateBotActive(th.Context, deletedBot1.UserId, false)
|
deletedBot1, err = th.App.UpdateBotActive(th.Context, deletedBot1.UserId, false)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
defer th.App.PermanentDeleteBot(th.Context, deletedBot1.UserId)
|
defer func() {
|
||||||
|
err = th.App.PermanentDeleteBot(th.Context, deletedBot1.UserId)
|
||||||
|
require.Nil(t, err)
|
||||||
|
}()
|
||||||
|
|
||||||
bot2, err := th.App.CreateBot(th.Context, &model.Bot{
|
bot2, err := th.App.CreateBot(th.Context, &model.Bot{
|
||||||
Username: "username2",
|
Username: "username2",
|
||||||
@@ -382,7 +412,10 @@ func TestGetBots(t *testing.T) {
|
|||||||
OwnerId: OwnerId1,
|
OwnerId: OwnerId1,
|
||||||
})
|
})
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
defer th.App.PermanentDeleteBot(th.Context, bot2.UserId)
|
defer func() {
|
||||||
|
err = th.App.PermanentDeleteBot(th.Context, bot2.UserId)
|
||||||
|
require.Nil(t, err)
|
||||||
|
}()
|
||||||
|
|
||||||
bot3, err := th.App.CreateBot(th.Context, &model.Bot{
|
bot3, err := th.App.CreateBot(th.Context, &model.Bot{
|
||||||
Username: "username3",
|
Username: "username3",
|
||||||
@@ -390,7 +423,10 @@ func TestGetBots(t *testing.T) {
|
|||||||
OwnerId: OwnerId1,
|
OwnerId: OwnerId1,
|
||||||
})
|
})
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
defer th.App.PermanentDeleteBot(th.Context, bot3.UserId)
|
defer func() {
|
||||||
|
err = th.App.PermanentDeleteBot(th.Context, bot3.UserId)
|
||||||
|
require.Nil(t, err)
|
||||||
|
}()
|
||||||
|
|
||||||
bot4, err := th.App.CreateBot(th.Context, &model.Bot{
|
bot4, err := th.App.CreateBot(th.Context, &model.Bot{
|
||||||
Username: "username5",
|
Username: "username5",
|
||||||
@@ -398,7 +434,10 @@ func TestGetBots(t *testing.T) {
|
|||||||
OwnerId: OwnerId2,
|
OwnerId: OwnerId2,
|
||||||
})
|
})
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
defer th.App.PermanentDeleteBot(th.Context, bot4.UserId)
|
defer func() {
|
||||||
|
err = th.App.PermanentDeleteBot(th.Context, bot4.UserId)
|
||||||
|
require.Nil(t, err)
|
||||||
|
}()
|
||||||
|
|
||||||
deletedBot2, err := th.App.CreateBot(th.Context, &model.Bot{
|
deletedBot2, err := th.App.CreateBot(th.Context, &model.Bot{
|
||||||
Username: "username6",
|
Username: "username6",
|
||||||
@@ -408,7 +447,10 @@ func TestGetBots(t *testing.T) {
|
|||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
deletedBot2, err = th.App.UpdateBotActive(th.Context, deletedBot2.UserId, false)
|
deletedBot2, err = th.App.UpdateBotActive(th.Context, deletedBot2.UserId, false)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
defer th.App.PermanentDeleteBot(th.Context, deletedBot2.UserId)
|
defer func() {
|
||||||
|
err := th.App.PermanentDeleteBot(th.Context, deletedBot2.UserId)
|
||||||
|
require.Nil(t, err)
|
||||||
|
}()
|
||||||
|
|
||||||
t.Run("get bots, page=0, perPage=10", func(t *testing.T) {
|
t.Run("get bots, page=0, perPage=10", func(t *testing.T) {
|
||||||
bots, err := th.App.GetBots(th.Context, &model.BotGetOptions{
|
bots, err := th.App.GetBots(th.Context, &model.BotGetOptions{
|
||||||
@@ -563,7 +605,10 @@ func TestUpdateBotActive(t *testing.T) {
|
|||||||
OwnerId: th.BasicUser.Id,
|
OwnerId: th.BasicUser.Id,
|
||||||
})
|
})
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
defer th.App.PermanentDeleteBot(th.Context, bot.UserId)
|
defer func() {
|
||||||
|
err = th.App.PermanentDeleteBot(th.Context, bot.UserId)
|
||||||
|
require.Nil(t, err)
|
||||||
|
}()
|
||||||
|
|
||||||
disabledBot, err := th.App.UpdateBotActive(th.Context, bot.UserId, false)
|
disabledBot, err := th.App.UpdateBotActive(th.Context, bot.UserId, false)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
@@ -613,7 +658,8 @@ func TestDisableUserBots(t *testing.T) {
|
|||||||
bots := []*model.Bot{}
|
bots := []*model.Bot{}
|
||||||
defer func() {
|
defer func() {
|
||||||
for _, bot := range bots {
|
for _, bot := range bots {
|
||||||
th.App.PermanentDeleteBot(th.Context, bot.UserId)
|
err := th.App.PermanentDeleteBot(th.Context, bot.UserId)
|
||||||
|
require.Nil(t, err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -634,7 +680,10 @@ func TestDisableUserBots(t *testing.T) {
|
|||||||
OwnerId: ownerId2,
|
OwnerId: ownerId2,
|
||||||
})
|
})
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
defer th.App.PermanentDeleteBot(th.Context, u2bot1.UserId)
|
defer func() {
|
||||||
|
err = th.App.PermanentDeleteBot(th.Context, u2bot1.UserId)
|
||||||
|
require.Nil(t, err)
|
||||||
|
}()
|
||||||
|
|
||||||
err = th.App.disableUserBots(th.Context, ownerId1)
|
err = th.App.disableUserBots(th.Context, ownerId1)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
@@ -667,7 +716,8 @@ func TestNotifySysadminsBotOwnerDisabled(t *testing.T) {
|
|||||||
userBots := []*model.Bot{}
|
userBots := []*model.Bot{}
|
||||||
defer func() {
|
defer func() {
|
||||||
for _, bot := range userBots {
|
for _, bot := range userBots {
|
||||||
th.App.PermanentDeleteBot(th.Context, bot.UserId)
|
err := th.App.PermanentDeleteBot(th.Context, bot.UserId)
|
||||||
|
require.Nil(t, err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@@ -680,7 +730,8 @@ func TestNotifySysadminsBotOwnerDisabled(t *testing.T) {
|
|||||||
Roles: model.SystemAdminRoleId + " " + model.SystemUserRoleId}
|
Roles: model.SystemAdminRoleId + " " + model.SystemUserRoleId}
|
||||||
_, err := th.App.CreateUser(th.Context, &sysadmin1)
|
_, err := th.App.CreateUser(th.Context, &sysadmin1)
|
||||||
require.Nil(t, err, "failed to create user")
|
require.Nil(t, err, "failed to create user")
|
||||||
th.App.UpdateUserRoles(th.Context, sysadmin1.Id, model.SystemUserRoleId+" "+model.SystemAdminRoleId, false)
|
_, err = th.App.UpdateUserRoles(th.Context, sysadmin1.Id, model.SystemUserRoleId+" "+model.SystemAdminRoleId, false)
|
||||||
|
require.Nil(t, err)
|
||||||
|
|
||||||
sysadmin2 := model.User{
|
sysadmin2 := model.User{
|
||||||
Email: "sys2@example.com",
|
Email: "sys2@example.com",
|
||||||
@@ -690,7 +741,8 @@ func TestNotifySysadminsBotOwnerDisabled(t *testing.T) {
|
|||||||
Roles: model.SystemAdminRoleId + " " + model.SystemUserRoleId}
|
Roles: model.SystemAdminRoleId + " " + model.SystemUserRoleId}
|
||||||
_, err = th.App.CreateUser(th.Context, &sysadmin2)
|
_, err = th.App.CreateUser(th.Context, &sysadmin2)
|
||||||
require.Nil(t, err, "failed to create user")
|
require.Nil(t, err, "failed to create user")
|
||||||
th.App.UpdateUserRoles(th.Context, sysadmin2.Id, model.SystemUserRoleId+" "+model.SystemAdminRoleId, false)
|
_, err = th.App.UpdateUserRoles(th.Context, sysadmin2.Id, model.SystemUserRoleId+" "+model.SystemAdminRoleId, false)
|
||||||
|
require.Nil(t, err)
|
||||||
|
|
||||||
// create user to be disabled
|
// create user to be disabled
|
||||||
user1, err := th.App.CreateUser(th.Context, &model.User{
|
user1, err := th.App.CreateUser(th.Context, &model.User{
|
||||||
@@ -829,7 +881,10 @@ func TestConvertUserToBot(t *testing.T) {
|
|||||||
Id: th.BasicUser.Id,
|
Id: th.BasicUser.Id,
|
||||||
})
|
})
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
defer th.App.PermanentDeleteBot(th.Context, bot.UserId)
|
defer func() {
|
||||||
|
err := th.App.PermanentDeleteBot(th.Context, bot.UserId)
|
||||||
|
require.Nil(t, err)
|
||||||
|
}()
|
||||||
assert.Equal(t, "username", bot.Username)
|
assert.Equal(t, "username", bot.Username)
|
||||||
assert.Equal(t, th.BasicUser.Id, bot.OwnerId)
|
assert.Equal(t, th.BasicUser.Id, bot.OwnerId)
|
||||||
})
|
})
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user