Replacing require.nil in plugin package (#16961)

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Jesús Espino
2021-03-09 09:45:00 +01:00
коммит произвёл GitHub
родитель 5a89208944
Коммит 857e18f3ab
5 изменённых файлов: 48 добавлений и 47 удалений

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

@@ -38,7 +38,7 @@ func TestEnsureBot(t *testing.T) {
_, retErr := p.EnsureBot(nil)
assert.NotNil(t, retErr)
assert.Error(t, retErr)
assert.Equal(t, "failed to ensure bot: incompatible server version for plugin, minimum required version: 5.10.0, current version: 5.9.0", retErr.Error())
})
@@ -51,7 +51,7 @@ func TestEnsureBot(t *testing.T) {
p.API = api
botID, err := p.EnsureBot(nil)
assert.Equal(t, "", botID)
assert.NotNil(t, err)
assert.Error(t, err)
})
t.Run("bad username", func(t *testing.T) {
api := setupAPI()
@@ -63,7 +63,7 @@ func TestEnsureBot(t *testing.T) {
Username: "",
})
assert.Equal(t, "", botID)
assert.NotNil(t, err)
assert.Error(t, err)
})
})
@@ -87,7 +87,7 @@ func TestEnsureBot(t *testing.T) {
botID, err := p.EnsureBot(testbot)
assert.Equal(t, expectedBotID, botID)
assert.Nil(t, err)
assert.NoError(t, err)
})
t.Run("should return an error if unable to get bot", func(t *testing.T) {
@@ -102,7 +102,7 @@ func TestEnsureBot(t *testing.T) {
botID, err := p.EnsureBot(testbot)
assert.Equal(t, "", botID)
assert.NotNil(t, err)
assert.Error(t, err)
})
t.Run("should set the bot profile image when specified", func(t *testing.T) {
@@ -127,11 +127,11 @@ func TestEnsureBot(t *testing.T) {
p := &plugin.HelpersImpl{}
p.API = api
assert.Nil(t, err)
assert.NoError(t, err)
botID, err := p.EnsureBot(testbot, plugin.ProfileImagePath(testImage))
assert.Equal(t, expectedBotID, botID)
assert.Nil(t, err)
assert.NoError(t, err)
})
t.Run("should set the bot icon image when specified", func(t *testing.T) {
@@ -141,7 +141,7 @@ func TestEnsureBot(t *testing.T) {
testsDir, _ := fileutils.FindDir("tests")
testImage := filepath.Join(testsDir, "test.png")
imageBytes, err := ioutil.ReadFile(testImage)
assert.Nil(t, err)
assert.NoError(t, err)
api.On("KVGet", plugin.BotUserKey).Return([]byte(expectedBotID), nil)
api.On("GetBundlePath").Return("", nil)
@@ -159,7 +159,7 @@ func TestEnsureBot(t *testing.T) {
botID, err := p.EnsureBot(testbot, plugin.IconImagePath(testImage))
assert.Equal(t, expectedBotID, botID)
assert.Nil(t, err)
assert.NoError(t, err)
})
t.Run("should set both the profile image and bot icon image when specified", func(t *testing.T) {
@@ -169,7 +169,7 @@ func TestEnsureBot(t *testing.T) {
testsDir, _ := fileutils.FindDir("tests")
testImage := filepath.Join(testsDir, "test.png")
imageBytes, err := ioutil.ReadFile(testImage)
assert.Nil(t, err)
assert.NoError(t, err)
api.On("KVGet", plugin.BotUserKey).Return([]byte(expectedBotID), nil)
api.On("GetBundlePath").Return("", nil)
@@ -188,7 +188,7 @@ func TestEnsureBot(t *testing.T) {
botID, err := p.EnsureBot(testbot, plugin.ProfileImagePath(testImage), plugin.IconImagePath(testImage))
assert.Equal(t, expectedBotID, botID)
assert.Nil(t, err)
assert.NoError(t, err)
})
t.Run("should find and update the bot with new bot details", func(t *testing.T) {
@@ -201,7 +201,7 @@ func TestEnsureBot(t *testing.T) {
testsDir, _ := fileutils.FindDir("tests")
testImage := filepath.Join(testsDir, "test.png")
imageBytes, err := ioutil.ReadFile(testImage)
assert.Nil(t, err)
assert.NoError(t, err)
api := setupAPI()
api.On("GetServerVersion").Return("5.10.0")
@@ -227,7 +227,7 @@ func TestEnsureBot(t *testing.T) {
botID, err := p.EnsureBot(updatedTestbot, plugin.ProfileImagePath(testImage), plugin.IconImagePath(testImage))
assert.Equal(t, expectedBotID, botID)
assert.Nil(t, err)
assert.NoError(t, err)
})
})
@@ -251,7 +251,7 @@ func TestEnsureBot(t *testing.T) {
botID, err := p.EnsureBot(testbot)
assert.Equal(t, expectedBotID, botID)
assert.Nil(t, err)
assert.NoError(t, err)
})
t.Run("should claim existing bot and return the ID", func(t *testing.T) {
@@ -273,7 +273,7 @@ func TestEnsureBot(t *testing.T) {
botID, err := p.EnsureBot(testbot)
assert.Equal(t, expectedBotID, botID)
assert.Nil(t, err)
assert.NoError(t, err)
})
t.Run("should return the non-bot account but log a message if user exists with the same name and is not a bot", func(t *testing.T) {
@@ -294,7 +294,7 @@ func TestEnsureBot(t *testing.T) {
botID, err := p.EnsureBot(testbot)
assert.Equal(t, expectedBotID, botID)
assert.Nil(t, err)
assert.NoError(t, err)
})
t.Run("should fail if create bot fails", func(t *testing.T) {
@@ -311,7 +311,7 @@ func TestEnsureBot(t *testing.T) {
botID, err := p.EnsureBot(testbot)
assert.Equal(t, "", botID)
assert.NotNil(t, err)
assert.Error(t, err)
})
t.Run("should create bot and set the bot profile image when specified", func(t *testing.T) {
@@ -321,7 +321,7 @@ func TestEnsureBot(t *testing.T) {
testsDir, _ := fileutils.FindDir("tests")
testImage := filepath.Join(testsDir, "test.png")
imageBytes, err := ioutil.ReadFile(testImage)
assert.Nil(t, err)
assert.NoError(t, err)
api.On("KVGet", plugin.BotUserKey).Return(nil, nil)
api.On("GetUserByUsername", testbot.Username).Return(nil, nil)
@@ -339,7 +339,7 @@ func TestEnsureBot(t *testing.T) {
botID, err := p.EnsureBot(testbot, plugin.ProfileImagePath(testImage))
assert.Equal(t, expectedBotID, botID)
assert.Nil(t, err)
assert.NoError(t, err)
})
t.Run("should create bot and set the bot icon image when specified", func(t *testing.T) {
@@ -349,7 +349,7 @@ func TestEnsureBot(t *testing.T) {
testsDir, _ := fileutils.FindDir("tests")
testImage := filepath.Join(testsDir, "test.png")
imageBytes, err := ioutil.ReadFile(testImage)
assert.Nil(t, err)
assert.NoError(t, err)
api.On("KVGet", plugin.BotUserKey).Return(nil, nil)
api.On("GetUserByUsername", testbot.Username).Return(nil, nil)
@@ -367,7 +367,7 @@ func TestEnsureBot(t *testing.T) {
botID, err := p.EnsureBot(testbot, plugin.IconImagePath(testImage))
assert.Equal(t, expectedBotID, botID)
assert.Nil(t, err)
assert.NoError(t, err)
})
t.Run("should create bot and set both the profile image and bot icon image when specified", func(t *testing.T) {
@@ -377,7 +377,7 @@ func TestEnsureBot(t *testing.T) {
testsDir, _ := fileutils.FindDir("tests")
testImage := filepath.Join(testsDir, "test.png")
imageBytes, err := ioutil.ReadFile(testImage)
assert.Nil(t, err)
assert.NoError(t, err)
api.On("KVGet", plugin.BotUserKey).Return(nil, nil)
api.On("GetUserByUsername", testbot.Username).Return(nil, nil)
@@ -396,7 +396,7 @@ func TestEnsureBot(t *testing.T) {
botID, err := p.EnsureBot(testbot, plugin.ProfileImagePath(testImage), plugin.IconImagePath(testImage))
assert.Equal(t, expectedBotID, botID)
assert.Nil(t, err)
assert.NoError(t, err)
})
})
}
@@ -518,7 +518,7 @@ func TestShouldProcessMessage(t *testing.T) {
shouldProcessMessage, err := p.ShouldProcessMessage(&model.Post{ChannelId: channelID, Props: model.StringInterface{"from_webhook": "true"}}, plugin.AllowBots())
assert.False(t, shouldProcessMessage)
assert.Nil(t, err)
assert.NoError(t, err)
})
t.Run("should process the message which have from_webhook with allow webhook plugin", func(t *testing.T) {
@@ -529,7 +529,7 @@ func TestShouldProcessMessage(t *testing.T) {
api.On("KVGet", plugin.BotUserKey).Return([]byte(expectedBotID), nil)
shouldProcessMessage, err := p.ShouldProcessMessage(&model.Post{ChannelId: channelID, Props: model.StringInterface{"from_webhook": "true"}}, plugin.AllowBots(), plugin.AllowWebhook())
assert.Nil(t, err)
assert.NoError(t, err)
assert.True(t, shouldProcessMessage)
})
@@ -542,7 +542,7 @@ func TestShouldProcessMessage(t *testing.T) {
api.On("KVGet", plugin.BotUserKey).Return([]byte(expectedBotID), nil)
shouldProcessMessage, err := p.ShouldProcessMessage(&model.Post{ChannelId: channelID}, plugin.AllowBots())
assert.Nil(t, err)
assert.NoError(t, err)
assert.True(t, shouldProcessMessage)
})
@@ -555,7 +555,7 @@ func TestShouldProcessMessage(t *testing.T) {
api.On("KVGet", plugin.BotUserKey).Return([]byte(expectedBotID), nil)
shouldProcessMessage, err := p.ShouldProcessMessage(&model.Post{ChannelId: channelID, Props: model.StringInterface{"from_webhook": "false"}}, plugin.AllowBots())
assert.Nil(t, err)
assert.NoError(t, err)
assert.True(t, shouldProcessMessage)
})