MM-31063: Change constants to use CamelCase (#16608)
* MM-31063: Change constants to use CamelCase * store package * change allcaps to camel case (#16615) * New tools.mod Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
8b6ac5f5d2
Коммит
c1dd23a3c8
@@ -8,8 +8,8 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
INTERNAL_KEY_PREFIX = "mmi_"
|
||||
BOT_USER_KEY = INTERNAL_KEY_PREFIX + "botid"
|
||||
InternalKeyPrefix = "mmi_"
|
||||
BotUserKey = InternalKeyPrefix + "botid"
|
||||
)
|
||||
|
||||
// Starts the serving of a Mattermost plugin over net/rpc. gRPC is not yet supported.
|
||||
|
||||
@@ -504,7 +504,7 @@ func newRegisteredPlugin(bundle *model.BundleInfo) registeredPlugin {
|
||||
func (env *Environment) InitPluginHealthCheckJob(enable bool) {
|
||||
// Config is set to enable. No job exists, start a new job.
|
||||
if enable && env.pluginHealthCheckJob == nil {
|
||||
mlog.Debug("Enabling plugin health check job", mlog.Duration("interval_s", HEALTH_CHECK_INTERVAL))
|
||||
mlog.Debug("Enabling plugin health check job", mlog.Duration("interval_s", HealthCheckInterval))
|
||||
|
||||
job := newPluginHealthCheckJob(env)
|
||||
env.pluginHealthCheckJob = job
|
||||
|
||||
@@ -12,10 +12,10 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
HEALTH_CHECK_INTERVAL = 30 * time.Second // How often the health check should run
|
||||
HEALTH_CHECK_DEACTIVATION_WINDOW = 60 * time.Minute // How long we wait for num fails to occur before deactivating the plugin
|
||||
HEALTH_CHECK_PING_FAIL_LIMIT = 3 // How many times we call RPC ping in a row before it is considered a failure
|
||||
HEALTH_CHECK_NUM_RESTARTS_LIMIT = 3 // How many times we restart a plugin before we deactivate it
|
||||
HealthCheckInterval = 30 * time.Second // How often the health check should run
|
||||
HealthCheckDeactivationWindow = 60 * time.Minute // How long we wait for num fails to occur before deactivating the plugin
|
||||
HealthCheckPingFailLimit = 3 // How many times we call RPC ping in a row before it is considered a failure
|
||||
HealthCheckNumRestartsLimit = 3 // How many times we restart a plugin before we deactivate it
|
||||
)
|
||||
|
||||
type PluginHealthCheckJob struct {
|
||||
@@ -31,7 +31,7 @@ func (job *PluginHealthCheckJob) run() {
|
||||
mlog.Debug("Plugin health check job starting.")
|
||||
defer close(job.cancelled)
|
||||
|
||||
ticker := time.NewTicker(HEALTH_CHECK_INTERVAL)
|
||||
ticker := time.NewTicker(HealthCheckInterval)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
@@ -103,21 +103,21 @@ func (job *PluginHealthCheckJob) Cancel() {
|
||||
<-job.cancelled
|
||||
}
|
||||
|
||||
// shouldDeactivatePlugin determines if a plugin needs to be deactivated after the plugin has failed (HEALTH_CHECK_NUM_RESTARTS_LIMIT) times,
|
||||
// within the configured time window (HEALTH_CHECK_DEACTIVATION_WINDOW).
|
||||
// shouldDeactivatePlugin determines if a plugin needs to be deactivated after the plugin has failed (HealthCheckNumRestartsLimit) times,
|
||||
// within the configured time window (HealthCheckDeactivationWindow).
|
||||
func shouldDeactivatePlugin(failedTimestamps []time.Time) bool {
|
||||
if len(failedTimestamps) < HEALTH_CHECK_NUM_RESTARTS_LIMIT {
|
||||
if len(failedTimestamps) < HealthCheckNumRestartsLimit {
|
||||
return false
|
||||
}
|
||||
|
||||
index := len(failedTimestamps) - HEALTH_CHECK_NUM_RESTARTS_LIMIT
|
||||
return time.Since(failedTimestamps[index]) <= HEALTH_CHECK_DEACTIVATION_WINDOW
|
||||
index := len(failedTimestamps) - HealthCheckNumRestartsLimit
|
||||
return time.Since(failedTimestamps[index]) <= HealthCheckDeactivationWindow
|
||||
}
|
||||
|
||||
// removeStaleTimestamps only keeps the last HEALTH_CHECK_NUM_RESTARTS_LIMIT items in timestamps.
|
||||
// removeStaleTimestamps only keeps the last HealthCheckNumRestartsLimit items in timestamps.
|
||||
func removeStaleTimestamps(timestamps []time.Time) []time.Time {
|
||||
if len(timestamps) > HEALTH_CHECK_NUM_RESTARTS_LIMIT {
|
||||
timestamps = timestamps[len(timestamps)-HEALTH_CHECK_NUM_RESTARTS_LIMIT:]
|
||||
if len(timestamps) > HealthCheckNumRestartsLimit {
|
||||
timestamps = timestamps[len(timestamps)-HealthCheckNumRestartsLimit:]
|
||||
}
|
||||
|
||||
return timestamps
|
||||
|
||||
@@ -129,8 +129,8 @@ func TestShouldDeactivatePlugin(t *testing.T) {
|
||||
|
||||
// Failures are recent enough to restart
|
||||
ftime = []time.Time{}
|
||||
ftime = append(ftime, now.Add(-HEALTH_CHECK_DEACTIVATION_WINDOW/10*2))
|
||||
ftime = append(ftime, now.Add(-HEALTH_CHECK_DEACTIVATION_WINDOW/10))
|
||||
ftime = append(ftime, now.Add(-HealthCheckDeactivationWindow/10*2))
|
||||
ftime = append(ftime, now.Add(-HealthCheckDeactivationWindow/10))
|
||||
ftime = append(ftime, now)
|
||||
|
||||
result = shouldDeactivatePlugin(ftime)
|
||||
@@ -138,8 +138,8 @@ func TestShouldDeactivatePlugin(t *testing.T) {
|
||||
|
||||
// Failures are too spaced out to warrant a restart
|
||||
ftime = []time.Time{}
|
||||
ftime = append(ftime, now.Add(-HEALTH_CHECK_DEACTIVATION_WINDOW*2))
|
||||
ftime = append(ftime, now.Add(-HEALTH_CHECK_DEACTIVATION_WINDOW*1))
|
||||
ftime = append(ftime, now.Add(-HealthCheckDeactivationWindow*2))
|
||||
ftime = append(ftime, now.Add(-HealthCheckDeactivationWindow*1))
|
||||
ftime = append(ftime, now)
|
||||
|
||||
result = shouldDeactivatePlugin(ftime)
|
||||
@@ -147,7 +147,7 @@ func TestShouldDeactivatePlugin(t *testing.T) {
|
||||
|
||||
// Not enough failures are present to warrant a restart
|
||||
ftime = []time.Time{}
|
||||
ftime = append(ftime, now.Add(-HEALTH_CHECK_DEACTIVATION_WINDOW/10))
|
||||
ftime = append(ftime, now.Add(-HealthCheckDeactivationWindow/10))
|
||||
ftime = append(ftime, now)
|
||||
|
||||
result = shouldDeactivatePlugin(ftime)
|
||||
|
||||
@@ -133,7 +133,7 @@ func (p *HelpersImpl) ShouldProcessMessage(post *model.Post, options ...ShouldPr
|
||||
option(messageProcessOptions)
|
||||
}
|
||||
|
||||
botIDBytes, kvGetErr := p.API.KVGet(BOT_USER_KEY)
|
||||
botIDBytes, kvGetErr := p.API.KVGet(BotUserKey)
|
||||
if kvGetErr != nil {
|
||||
return false, errors.Wrap(kvGetErr, "failed to get bot")
|
||||
}
|
||||
@@ -212,7 +212,7 @@ func (p *HelpersImpl) ensureBot(bot *model.Bot) (retBotID string, retErr error)
|
||||
var botIDBytes []byte
|
||||
|
||||
err = utils.ProgressiveRetry(func() error {
|
||||
botIDBytes, err = p.API.KVGet(BOT_USER_KEY)
|
||||
botIDBytes, err = p.API.KVGet(BotUserKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -226,7 +226,7 @@ func (p *HelpersImpl) ensureBot(bot *model.Bot) (retBotID string, retErr error)
|
||||
}
|
||||
}()
|
||||
|
||||
botIDBytes, kvGetErr := p.API.KVGet(BOT_USER_KEY)
|
||||
botIDBytes, kvGetErr := p.API.KVGet(BotUserKey)
|
||||
if kvGetErr != nil {
|
||||
return "", errors.Wrap(kvGetErr, "failed to get bot")
|
||||
}
|
||||
@@ -252,7 +252,7 @@ func (p *HelpersImpl) ensureBot(bot *model.Bot) (retBotID string, retErr error)
|
||||
// Check for an existing bot user with that username. If one exists, then use that.
|
||||
if user, userGetErr := p.API.GetUserByUsername(bot.Username); userGetErr == nil && user != nil {
|
||||
if user.IsBot {
|
||||
if kvSetErr := p.API.KVSet(BOT_USER_KEY, []byte(user.Id)); kvSetErr != nil {
|
||||
if kvSetErr := p.API.KVSet(BotUserKey, []byte(user.Id)); kvSetErr != nil {
|
||||
p.API.LogWarn("Failed to set claimed bot user id.", "userid", user.Id, "err", kvSetErr)
|
||||
}
|
||||
} else {
|
||||
@@ -267,7 +267,7 @@ func (p *HelpersImpl) ensureBot(bot *model.Bot) (retBotID string, retErr error)
|
||||
return "", errors.Wrap(createBotErr, "failed to create bot")
|
||||
}
|
||||
|
||||
if kvSetErr := p.API.KVSet(BOT_USER_KEY, []byte(createdBot.UserId)); kvSetErr != nil {
|
||||
if kvSetErr := p.API.KVSet(BotUserKey, []byte(createdBot.UserId)); kvSetErr != nil {
|
||||
p.API.LogWarn("Failed to set created bot user id.", "userid", createdBot.UserId, "err", kvSetErr)
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ func TestEnsureBot(t *testing.T) {
|
||||
|
||||
api := setupAPI()
|
||||
api.On("GetServerVersion").Return("5.10.0")
|
||||
api.On("KVGet", plugin.BOT_USER_KEY).Return([]byte(expectedBotID), nil)
|
||||
api.On("KVGet", plugin.BotUserKey).Return([]byte(expectedBotID), nil)
|
||||
api.On("PatchBot", expectedBotID, &model.BotPatch{
|
||||
Username: &testbot.Username,
|
||||
DisplayName: &testbot.DisplayName,
|
||||
@@ -92,7 +92,7 @@ func TestEnsureBot(t *testing.T) {
|
||||
t.Run("should return an error if unable to get bot", func(t *testing.T) {
|
||||
api := setupAPI()
|
||||
api.On("GetServerVersion").Return("5.10.0")
|
||||
api.On("KVGet", plugin.BOT_USER_KEY).Return(nil, &model.AppError{})
|
||||
api.On("KVGet", plugin.BotUserKey).Return(nil, &model.AppError{})
|
||||
defer api.AssertExpectations(t)
|
||||
|
||||
p := &plugin.HelpersImpl{}
|
||||
@@ -112,7 +112,7 @@ func TestEnsureBot(t *testing.T) {
|
||||
testImage := filepath.Join(testsDir, "test.png")
|
||||
imageBytes, err := ioutil.ReadFile(testImage)
|
||||
|
||||
api.On("KVGet", plugin.BOT_USER_KEY).Return([]byte(expectedBotID), nil)
|
||||
api.On("KVGet", plugin.BotUserKey).Return([]byte(expectedBotID), nil)
|
||||
api.On("GetBundlePath").Return("", nil)
|
||||
api.On("SetProfileImage", expectedBotID, imageBytes).Return(nil)
|
||||
api.On("GetServerVersion").Return("5.10.0")
|
||||
@@ -142,7 +142,7 @@ func TestEnsureBot(t *testing.T) {
|
||||
imageBytes, err := ioutil.ReadFile(testImage)
|
||||
assert.Nil(t, err)
|
||||
|
||||
api.On("KVGet", plugin.BOT_USER_KEY).Return([]byte(expectedBotID), nil)
|
||||
api.On("KVGet", plugin.BotUserKey).Return([]byte(expectedBotID), nil)
|
||||
api.On("GetBundlePath").Return("", nil)
|
||||
api.On("SetBotIconImage", expectedBotID, imageBytes).Return(nil)
|
||||
api.On("GetServerVersion").Return("5.10.0")
|
||||
@@ -170,7 +170,7 @@ func TestEnsureBot(t *testing.T) {
|
||||
imageBytes, err := ioutil.ReadFile(testImage)
|
||||
assert.Nil(t, err)
|
||||
|
||||
api.On("KVGet", plugin.BOT_USER_KEY).Return([]byte(expectedBotID), nil)
|
||||
api.On("KVGet", plugin.BotUserKey).Return([]byte(expectedBotID), nil)
|
||||
api.On("GetBundlePath").Return("", nil)
|
||||
api.On("SetProfileImage", expectedBotID, imageBytes).Return(nil)
|
||||
api.On("SetBotIconImage", expectedBotID, imageBytes).Return(nil)
|
||||
@@ -204,7 +204,7 @@ func TestEnsureBot(t *testing.T) {
|
||||
|
||||
api := setupAPI()
|
||||
api.On("GetServerVersion").Return("5.10.0")
|
||||
api.On("KVGet", plugin.BOT_USER_KEY).Return([]byte(expectedBotID), nil)
|
||||
api.On("KVGet", plugin.BotUserKey).Return([]byte(expectedBotID), nil)
|
||||
api.On("GetBundlePath").Return("", nil)
|
||||
api.On("SetProfileImage", expectedBotID, imageBytes).Return(nil)
|
||||
api.On("SetBotIconImage", expectedBotID, imageBytes).Return(nil)
|
||||
@@ -236,12 +236,12 @@ func TestEnsureBot(t *testing.T) {
|
||||
|
||||
api := setupAPI()
|
||||
api.On("GetServerVersion").Return("5.10.0")
|
||||
api.On("KVGet", plugin.BOT_USER_KEY).Return(nil, nil)
|
||||
api.On("KVGet", plugin.BotUserKey).Return(nil, nil)
|
||||
api.On("GetUserByUsername", testbot.Username).Return(nil, nil)
|
||||
api.On("CreateBot", testbot).Return(&model.Bot{
|
||||
UserId: expectedBotID,
|
||||
}, nil)
|
||||
api.On("KVSet", plugin.BOT_USER_KEY, []byte(expectedBotID)).Return(nil)
|
||||
api.On("KVSet", plugin.BotUserKey, []byte(expectedBotID)).Return(nil)
|
||||
defer api.AssertExpectations(t)
|
||||
|
||||
p := &plugin.HelpersImpl{}
|
||||
@@ -258,12 +258,12 @@ func TestEnsureBot(t *testing.T) {
|
||||
|
||||
api := setupAPI()
|
||||
api.On("GetServerVersion").Return("5.10.0")
|
||||
api.On("KVGet", plugin.BOT_USER_KEY).Return(nil, nil)
|
||||
api.On("KVGet", plugin.BotUserKey).Return(nil, nil)
|
||||
api.On("GetUserByUsername", testbot.Username).Return(&model.User{
|
||||
Id: expectedBotID,
|
||||
IsBot: true,
|
||||
}, nil)
|
||||
api.On("KVSet", plugin.BOT_USER_KEY, []byte(expectedBotID)).Return(nil)
|
||||
api.On("KVSet", plugin.BotUserKey, []byte(expectedBotID)).Return(nil)
|
||||
defer api.AssertExpectations(t)
|
||||
|
||||
p := &plugin.HelpersImpl{}
|
||||
@@ -279,7 +279,7 @@ func TestEnsureBot(t *testing.T) {
|
||||
expectedBotID := model.NewId()
|
||||
api := setupAPI()
|
||||
api.On("GetServerVersion").Return("5.10.0")
|
||||
api.On("KVGet", plugin.BOT_USER_KEY).Return(nil, nil)
|
||||
api.On("KVGet", plugin.BotUserKey).Return(nil, nil)
|
||||
api.On("GetUserByUsername", testbot.Username).Return(&model.User{
|
||||
Id: expectedBotID,
|
||||
IsBot: false,
|
||||
@@ -299,7 +299,7 @@ func TestEnsureBot(t *testing.T) {
|
||||
t.Run("should fail if create bot fails", func(t *testing.T) {
|
||||
api := setupAPI()
|
||||
api.On("GetServerVersion").Return("5.10.0")
|
||||
api.On("KVGet", plugin.BOT_USER_KEY).Return(nil, nil)
|
||||
api.On("KVGet", plugin.BotUserKey).Return(nil, nil)
|
||||
api.On("GetUserByUsername", testbot.Username).Return(nil, nil)
|
||||
api.On("CreateBot", testbot).Return(nil, &model.AppError{})
|
||||
defer api.AssertExpectations(t)
|
||||
@@ -322,12 +322,12 @@ func TestEnsureBot(t *testing.T) {
|
||||
imageBytes, err := ioutil.ReadFile(testImage)
|
||||
assert.Nil(t, err)
|
||||
|
||||
api.On("KVGet", plugin.BOT_USER_KEY).Return(nil, nil)
|
||||
api.On("KVGet", plugin.BotUserKey).Return(nil, nil)
|
||||
api.On("GetUserByUsername", testbot.Username).Return(nil, nil)
|
||||
api.On("CreateBot", testbot).Return(&model.Bot{
|
||||
UserId: expectedBotID,
|
||||
}, nil)
|
||||
api.On("KVSet", plugin.BOT_USER_KEY, []byte(expectedBotID)).Return(nil)
|
||||
api.On("KVSet", plugin.BotUserKey, []byte(expectedBotID)).Return(nil)
|
||||
api.On("GetBundlePath").Return("", nil)
|
||||
api.On("SetProfileImage", expectedBotID, imageBytes).Return(nil)
|
||||
api.On("GetServerVersion").Return("5.10.0")
|
||||
@@ -350,12 +350,12 @@ func TestEnsureBot(t *testing.T) {
|
||||
imageBytes, err := ioutil.ReadFile(testImage)
|
||||
assert.Nil(t, err)
|
||||
|
||||
api.On("KVGet", plugin.BOT_USER_KEY).Return(nil, nil)
|
||||
api.On("KVGet", plugin.BotUserKey).Return(nil, nil)
|
||||
api.On("GetUserByUsername", testbot.Username).Return(nil, nil)
|
||||
api.On("CreateBot", testbot).Return(&model.Bot{
|
||||
UserId: expectedBotID,
|
||||
}, nil)
|
||||
api.On("KVSet", plugin.BOT_USER_KEY, []byte(expectedBotID)).Return(nil)
|
||||
api.On("KVSet", plugin.BotUserKey, []byte(expectedBotID)).Return(nil)
|
||||
api.On("GetBundlePath").Return("", nil)
|
||||
api.On("SetBotIconImage", expectedBotID, imageBytes).Return(nil)
|
||||
api.On("GetServerVersion").Return("5.10.0")
|
||||
@@ -378,12 +378,12 @@ func TestEnsureBot(t *testing.T) {
|
||||
imageBytes, err := ioutil.ReadFile(testImage)
|
||||
assert.Nil(t, err)
|
||||
|
||||
api.On("KVGet", plugin.BOT_USER_KEY).Return(nil, nil)
|
||||
api.On("KVGet", plugin.BotUserKey).Return(nil, nil)
|
||||
api.On("GetUserByUsername", testbot.Username).Return(nil, nil)
|
||||
api.On("CreateBot", testbot).Return(&model.Bot{
|
||||
UserId: expectedBotID,
|
||||
}, nil)
|
||||
api.On("KVSet", plugin.BOT_USER_KEY, []byte(expectedBotID)).Return(nil)
|
||||
api.On("KVSet", plugin.BotUserKey, []byte(expectedBotID)).Return(nil)
|
||||
api.On("GetBundlePath").Return("", nil)
|
||||
api.On("SetProfileImage", expectedBotID, imageBytes).Return(nil)
|
||||
api.On("SetBotIconImage", expectedBotID, imageBytes).Return(nil)
|
||||
@@ -410,7 +410,7 @@ func TestShouldProcessMessage(t *testing.T) {
|
||||
|
||||
t.Run("should not respond to itself", func(t *testing.T) {
|
||||
api := setupAPI()
|
||||
api.On("KVGet", plugin.BOT_USER_KEY).Return([]byte(expectedBotID), nil)
|
||||
api.On("KVGet", plugin.BotUserKey).Return([]byte(expectedBotID), nil)
|
||||
p.API = api
|
||||
shouldProcessMessage, _ := p.ShouldProcessMessage(&model.Post{Type: model.POST_HEADER_CHANGE, UserId: expectedBotID}, plugin.AllowSystemMessages(), plugin.AllowBots())
|
||||
|
||||
@@ -428,7 +428,7 @@ func TestShouldProcessMessage(t *testing.T) {
|
||||
api := setupAPI()
|
||||
api.On("GetChannel", channelID).Return(&model.Channel{Id: channelID, Type: model.CHANNEL_GROUP}, nil)
|
||||
p.API = api
|
||||
api.On("KVGet", plugin.BOT_USER_KEY).Return([]byte(expectedBotID), nil)
|
||||
api.On("KVGet", plugin.BotUserKey).Return([]byte(expectedBotID), nil)
|
||||
|
||||
shouldProcessMessage, _ := p.ShouldProcessMessage(&model.Post{ChannelId: channelID}, plugin.AllowSystemMessages(), plugin.AllowBots(), plugin.FilterChannelIDs([]string{"another-channel-id"}))
|
||||
|
||||
@@ -441,7 +441,7 @@ func TestShouldProcessMessage(t *testing.T) {
|
||||
api := setupAPI()
|
||||
p.API = api
|
||||
api.On("GetUser", userID).Return(&model.User{IsBot: true}, nil)
|
||||
api.On("KVGet", plugin.BOT_USER_KEY).Return([]byte(expectedBotID), nil)
|
||||
api.On("KVGet", plugin.BotUserKey).Return([]byte(expectedBotID), nil)
|
||||
|
||||
shouldProcessMessage, _ := p.ShouldProcessMessage(&model.Post{UserId: userID, ChannelId: channelID},
|
||||
plugin.AllowSystemMessages(), plugin.FilterUserIDs([]string{"another-user-id"}))
|
||||
@@ -458,7 +458,7 @@ func TestShouldProcessMessage(t *testing.T) {
|
||||
}
|
||||
api := setupAPI()
|
||||
api.On("GetChannel", channelID).Return(&channel, nil)
|
||||
api.On("KVGet", plugin.BOT_USER_KEY).Return([]byte(expectedBotID), nil)
|
||||
api.On("KVGet", plugin.BotUserKey).Return([]byte(expectedBotID), nil)
|
||||
p.API = api
|
||||
|
||||
shouldProcessMessage, _ := p.ShouldProcessMessage(&model.Post{UserId: userID, ChannelId: channelID}, plugin.AllowSystemMessages(), plugin.AllowBots(), plugin.OnlyBotDMs())
|
||||
@@ -469,7 +469,7 @@ func TestShouldProcessMessage(t *testing.T) {
|
||||
t.Run("should process the message", func(t *testing.T) {
|
||||
channelID := "1"
|
||||
api := setupAPI()
|
||||
api.On("KVGet", plugin.BOT_USER_KEY).Return([]byte(expectedBotID), nil)
|
||||
api.On("KVGet", plugin.BotUserKey).Return([]byte(expectedBotID), nil)
|
||||
p.API = api
|
||||
|
||||
shouldProcessMessage, _ := p.ShouldProcessMessage(&model.Post{UserId: "1", Type: model.POST_HEADER_CHANGE, ChannelId: channelID},
|
||||
@@ -481,7 +481,7 @@ func TestShouldProcessMessage(t *testing.T) {
|
||||
t.Run("should process the message for plugin without a bot", func(t *testing.T) {
|
||||
channelID := "1"
|
||||
api := setupAPI()
|
||||
api.On("KVGet", plugin.BOT_USER_KEY).Return(nil, nil)
|
||||
api.On("KVGet", plugin.BotUserKey).Return(nil, nil)
|
||||
p.API = api
|
||||
|
||||
shouldProcessMessage, _ := p.ShouldProcessMessage(&model.Post{UserId: "1", Type: model.POST_HEADER_CHANGE, ChannelId: channelID},
|
||||
@@ -498,7 +498,7 @@ func TestShouldProcessMessage(t *testing.T) {
|
||||
Type: model.CHANNEL_DIRECT,
|
||||
}
|
||||
api.On("GetChannel", channelID).Return(&channel, nil)
|
||||
api.On("KVGet", plugin.BOT_USER_KEY).Return([]byte(expectedBotID), nil)
|
||||
api.On("KVGet", plugin.BotUserKey).Return([]byte(expectedBotID), nil)
|
||||
p.API = api
|
||||
|
||||
shouldProcessMessage, _ := p.ShouldProcessMessage(&model.Post{UserId: "1", Type: model.POST_HEADER_CHANGE, ChannelId: channelID},
|
||||
@@ -512,7 +512,7 @@ func TestShouldProcessMessage(t *testing.T) {
|
||||
api := setupAPI()
|
||||
api.On("GetChannel", channelID).Return(&model.Channel{Id: channelID, Type: model.CHANNEL_GROUP}, nil)
|
||||
p.API = api
|
||||
api.On("KVGet", plugin.BOT_USER_KEY).Return([]byte(expectedBotID), nil)
|
||||
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())
|
||||
|
||||
@@ -525,7 +525,7 @@ func TestShouldProcessMessage(t *testing.T) {
|
||||
api := setupAPI()
|
||||
api.On("GetChannel", channelID).Return(&model.Channel{Id: channelID, Type: model.CHANNEL_GROUP}, nil)
|
||||
p.API = api
|
||||
api.On("KVGet", plugin.BOT_USER_KEY).Return([]byte(expectedBotID), nil)
|
||||
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)
|
||||
@@ -538,7 +538,7 @@ func TestShouldProcessMessage(t *testing.T) {
|
||||
api := setupAPI()
|
||||
api.On("GetChannel", channelID).Return(&model.Channel{Id: channelID, Type: model.CHANNEL_GROUP}, nil)
|
||||
p.API = api
|
||||
api.On("KVGet", plugin.BOT_USER_KEY).Return([]byte(expectedBotID), nil)
|
||||
api.On("KVGet", plugin.BotUserKey).Return([]byte(expectedBotID), nil)
|
||||
|
||||
shouldProcessMessage, err := p.ShouldProcessMessage(&model.Post{ChannelId: channelID}, plugin.AllowBots())
|
||||
assert.Nil(t, err)
|
||||
@@ -551,7 +551,7 @@ func TestShouldProcessMessage(t *testing.T) {
|
||||
api := setupAPI()
|
||||
api.On("GetChannel", channelID).Return(&model.Channel{Id: channelID, Type: model.CHANNEL_GROUP}, nil)
|
||||
p.API = api
|
||||
api.On("KVGet", plugin.BOT_USER_KEY).Return([]byte(expectedBotID), nil)
|
||||
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)
|
||||
|
||||
@@ -114,7 +114,7 @@ func (sup *supervisor) Hooks() Hooks {
|
||||
func (sup *supervisor) PerformHealthCheck() error {
|
||||
// No need for a lock here because Ping is read-locked.
|
||||
if pingErr := sup.Ping(); pingErr != nil {
|
||||
for pingFails := 1; pingFails < HEALTH_CHECK_PING_FAIL_LIMIT; pingFails++ {
|
||||
for pingFails := 1; pingFails < HealthCheckPingFailLimit; pingFails++ {
|
||||
pingErr = sup.Ping()
|
||||
if pingErr == nil {
|
||||
break
|
||||
|
||||
Ссылка в новой задаче
Block a user