diff --git a/.golangci.yml b/.golangci.yml index 51bd8e4aaa..3b44f5f19f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -17,6 +17,7 @@ linters: enable: - deadcode - gofmt + - golint - gosimple - govet - ineffassign @@ -34,3 +35,8 @@ issues: # add more as required. - unused text: "RedisSupplier|LocalCacheSupplier|Enterprise" + + - linters: + # ignore golint error for a lot of packages for now + - golint + path: "api4|app|cmd|config|einterface|enterprise|imports|jobs|manualtesting|migrations|mlog|model|testlib|services|store|utils|web|wsapi|plugin/api.go|plugin/context.go|plugin/client.go|plugin/client_rpc.go|plugin/environment.go|plugin/health_check.go|plugin/hooks.go|plugin/supervisor.go|plugin/valid.go" diff --git a/Makefile b/Makefile index e750d97072..d9af7106e8 100644 --- a/Makefile +++ b/Makefile @@ -202,10 +202,7 @@ check-licenses: ## Checks license status. check-prereqs: ## Checks prerequisite software status. ./scripts/prereq-check.sh -check-style: golangci-lint plugin-checker check-licenses check-plugin-golint ## Runs golangci against all packages and also ensures plugin package golint compliant - -check-plugin-golint: # Checks if golint returns any uncompliant code for any file that starts with plugin/helpers - @! golint ./plugin/ | grep plugin/helpers +check-style: golangci-lint plugin-checker check-licenses ## Runs golangci against all packages test-te-race: ## Checks for race conditions in the team edition. @echo Testing TE race conditions diff --git a/plugin/example_help_test.go b/plugin/example_help_test.go index e224df6f46..883d6f0eb5 100644 --- a/plugin/example_help_test.go +++ b/plugin/example_help_test.go @@ -19,8 +19,8 @@ type configuration struct { TeamName string ChannelName string - // channelId is resolved when the public configuration fields above change - channelId string + // channelID is resolved when the public configuration fields above change + channelID string } type HelpPlugin struct { @@ -78,7 +78,7 @@ func (p *HelpPlugin) OnConfigurationChange() error { return errors.Wrapf(err, "failed to find channel %s", configuration.ChannelName) } - configuration.channelId = channel.Id + configuration.channelID = channel.Id p.setConfiguration(configuration) @@ -89,7 +89,7 @@ func (p *HelpPlugin) MessageHasBeenPosted(c *plugin.Context, post *model.Post) { configuration := p.getConfiguration() // Ignore posts not in the configured channel - if post.ChannelId != configuration.channelId { + if post.ChannelId != configuration.channelID { return } @@ -104,7 +104,7 @@ func (p *HelpPlugin) MessageHasBeenPosted(c *plugin.Context, post *model.Post) { } p.API.SendEphemeralPost(post.UserId, &model.Post{ - ChannelId: configuration.channelId, + ChannelId: configuration.channelID, Message: "You asked for help? Checkout https://about.mattermost.com/help/", Props: map[string]interface{}{ "sent_by_plugin": true, diff --git a/plugin/health_check_test.go b/plugin/health_check_test.go index aeafe57be8..32cb3277a4 100644 --- a/plugin/health_check_test.go +++ b/plugin/health_check_test.go @@ -18,14 +18,14 @@ import ( func TestPluginHealthCheck(t *testing.T) { for name, f := range map[string]func(*testing.T){ - "PluginHealthCheck_Success": testPluginHealthCheck_Success, - "PluginHealthCheck_Panic": testPluginHealthCheck_Panic, + "PluginHealthCheck_Success": testPluginHealthCheckSuccess, + "PluginHealthCheck_Panic": testPluginHealthCheckPanic, } { t.Run(name, f) } } -func testPluginHealthCheck_Success(t *testing.T) { +func testPluginHealthCheckSuccess(t *testing.T) { dir, err := ioutil.TempDir("", "") require.NoError(t, err) defer os.RemoveAll(dir) @@ -66,7 +66,7 @@ func testPluginHealthCheck_Success(t *testing.T) { require.Nil(t, err) } -func testPluginHealthCheck_Panic(t *testing.T) { +func testPluginHealthCheckPanic(t *testing.T) { dir, err := ioutil.TempDir("", "") require.NoError(t, err) defer os.RemoveAll(dir) diff --git a/plugin/helpers_bots.go b/plugin/helpers_bots.go index 0450105d26..208b5d9e0b 100644 --- a/plugin/helpers_bots.go +++ b/plugin/helpers_bots.go @@ -123,13 +123,13 @@ func (p *HelpersImpl) ShouldProcessMessage(post *model.Post, options ...ShouldPr option(messageProcessOptions) } - botIdBytes, kvGetErr := p.API.KVGet(BOT_USER_KEY) + botIDBytes, kvGetErr := p.API.KVGet(BOT_USER_KEY) if kvGetErr != nil { return false, errors.Wrap(kvGetErr, "failed to get bot") } - if botIdBytes != nil { - if post.UserId == string(botIdBytes) { + if botIDBytes != nil { + if post.UserId == string(botIDBytes) { return false, nil } } @@ -157,13 +157,13 @@ func (p *HelpersImpl) ShouldProcessMessage(post *model.Post, options ...ShouldPr return false, nil } - if botIdBytes != nil && messageProcessOptions.OnlyBotDMs { + if botIDBytes != nil && messageProcessOptions.OnlyBotDMs { channel, appErr := p.API.GetChannel(post.ChannelId) if appErr != nil { return false, errors.Wrap(appErr, "unable to get channel") } - if !model.IsBotDMChannel(channel, string(botIdBytes)) { + if !model.IsBotDMChannel(channel, string(botIDBytes)) { return false, nil } } diff --git a/plugin/helpers_bots_test.go b/plugin/helpers_bots_test.go index 693f96d515..db9200f50b 100644 --- a/plugin/helpers_bots_test.go +++ b/plugin/helpers_bots_test.go @@ -48,8 +48,8 @@ func TestEnsureBot(t *testing.T) { p := &plugin.HelpersImpl{} p.API = api - botId, err := p.EnsureBot(nil) - assert.Equal(t, "", botId) + botID, err := p.EnsureBot(nil) + assert.Equal(t, "", botID) assert.NotNil(t, err) }) t.Run("bad username", func(t *testing.T) { @@ -58,29 +58,29 @@ func TestEnsureBot(t *testing.T) { p := &plugin.HelpersImpl{} p.API = api - botId, err := p.EnsureBot(&model.Bot{ + botID, err := p.EnsureBot(&model.Bot{ Username: "", }) - assert.Equal(t, "", botId) + assert.Equal(t, "", botID) assert.NotNil(t, err) }) }) t.Run("if bot already exists", func(t *testing.T) { t.Run("should find and return the existing bot ID", func(t *testing.T) { - expectedBotId := model.NewId() + expectedBotID := model.NewId() api := setupAPI() api.On("GetServerVersion").Return("5.10.0") - api.On("KVGet", plugin.BOT_USER_KEY).Return([]byte(expectedBotId), nil) + api.On("KVGet", plugin.BOT_USER_KEY).Return([]byte(expectedBotID), nil) defer api.AssertExpectations(t) p := &plugin.HelpersImpl{} p.API = api - botId, err := p.EnsureBot(testbot) + botID, err := p.EnsureBot(testbot) - assert.Equal(t, expectedBotId, botId) + assert.Equal(t, expectedBotID, botID) assert.Nil(t, err) }) @@ -93,23 +93,23 @@ func TestEnsureBot(t *testing.T) { p := &plugin.HelpersImpl{} p.API = api - botId, err := p.EnsureBot(testbot) + botID, err := p.EnsureBot(testbot) - assert.Equal(t, "", botId) + assert.Equal(t, "", botID) assert.NotNil(t, err) }) t.Run("should set the bot profile image when specified", func(t *testing.T) { - expectedBotId := model.NewId() + expectedBotID := model.NewId() api := setupAPI() testsDir, _ := fileutils.FindDir("tests") 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.BOT_USER_KEY).Return([]byte(expectedBotID), nil) api.On("GetBundlePath").Return("", nil) - api.On("SetProfileImage", expectedBotId, imageBytes).Return(nil) + api.On("SetProfileImage", expectedBotID, imageBytes).Return(nil) api.On("GetServerVersion").Return("5.10.0") defer api.AssertExpectations(t) @@ -118,13 +118,13 @@ func TestEnsureBot(t *testing.T) { assert.Nil(t, err) - botId, err := p.EnsureBot(testbot, plugin.ProfileImagePath(testImage)) - assert.Equal(t, expectedBotId, botId) + botID, err := p.EnsureBot(testbot, plugin.ProfileImagePath(testImage)) + assert.Equal(t, expectedBotID, botID) assert.Nil(t, err) }) t.Run("should set the bot icon image when specified", func(t *testing.T) { - expectedBotId := model.NewId() + expectedBotID := model.NewId() api := setupAPI() testsDir, _ := fileutils.FindDir("tests") @@ -132,22 +132,22 @@ 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.BOT_USER_KEY).Return([]byte(expectedBotID), nil) api.On("GetBundlePath").Return("", nil) - api.On("SetBotIconImage", expectedBotId, imageBytes).Return(nil) + api.On("SetBotIconImage", expectedBotID, imageBytes).Return(nil) api.On("GetServerVersion").Return("5.10.0") defer api.AssertExpectations(t) p := &plugin.HelpersImpl{} p.API = api - botId, err := p.EnsureBot(testbot, plugin.IconImagePath(testImage)) - assert.Equal(t, expectedBotId, botId) + botID, err := p.EnsureBot(testbot, plugin.IconImagePath(testImage)) + assert.Equal(t, expectedBotID, botID) assert.Nil(t, err) }) t.Run("should set both the profile image and bot icon image when specified", func(t *testing.T) { - expectedBotId := model.NewId() + expectedBotID := model.NewId() api := setupAPI() testsDir, _ := fileutils.FindDir("tests") @@ -155,74 +155,74 @@ 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.BOT_USER_KEY).Return([]byte(expectedBotID), nil) api.On("GetBundlePath").Return("", nil) - api.On("SetProfileImage", expectedBotId, imageBytes).Return(nil) - api.On("SetBotIconImage", expectedBotId, imageBytes).Return(nil) + api.On("SetProfileImage", expectedBotID, imageBytes).Return(nil) + api.On("SetBotIconImage", expectedBotID, imageBytes).Return(nil) api.On("GetServerVersion").Return("5.10.0") defer api.AssertExpectations(t) p := &plugin.HelpersImpl{} p.API = api - botId, err := p.EnsureBot(testbot, plugin.ProfileImagePath(testImage), plugin.IconImagePath(testImage)) - assert.Equal(t, expectedBotId, botId) + botID, err := p.EnsureBot(testbot, plugin.ProfileImagePath(testImage), plugin.IconImagePath(testImage)) + assert.Equal(t, expectedBotID, botID) assert.Nil(t, err) }) }) t.Run("if bot doesn't exist", func(t *testing.T) { t.Run("should create the bot and return the ID", func(t *testing.T) { - expectedBotId := model.NewId() + expectedBotID := model.NewId() api := setupAPI() api.On("GetServerVersion").Return("5.10.0") api.On("KVGet", plugin.BOT_USER_KEY).Return(nil, nil) api.On("GetUserByUsername", testbot.Username).Return(nil, nil) api.On("CreateBot", testbot).Return(&model.Bot{ - UserId: expectedBotId, + UserId: expectedBotID, }, nil) - api.On("KVSet", plugin.BOT_USER_KEY, []byte(expectedBotId)).Return(nil) + api.On("KVSet", plugin.BOT_USER_KEY, []byte(expectedBotID)).Return(nil) defer api.AssertExpectations(t) p := &plugin.HelpersImpl{} p.API = api - botId, err := p.EnsureBot(testbot) + botID, err := p.EnsureBot(testbot) - assert.Equal(t, expectedBotId, botId) + assert.Equal(t, expectedBotID, botID) assert.Nil(t, err) }) t.Run("should claim existing bot and return the ID", func(t *testing.T) { - expectedBotId := model.NewId() + expectedBotID := model.NewId() api := setupAPI() api.On("GetServerVersion").Return("5.10.0") api.On("KVGet", plugin.BOT_USER_KEY).Return(nil, nil) api.On("GetUserByUsername", testbot.Username).Return(&model.User{ - Id: expectedBotId, + Id: expectedBotID, IsBot: true, }, nil) - api.On("KVSet", plugin.BOT_USER_KEY, []byte(expectedBotId)).Return(nil) + api.On("KVSet", plugin.BOT_USER_KEY, []byte(expectedBotID)).Return(nil) defer api.AssertExpectations(t) p := &plugin.HelpersImpl{} p.API = api - botId, err := p.EnsureBot(testbot) + botID, err := p.EnsureBot(testbot) - assert.Equal(t, expectedBotId, botId) + assert.Equal(t, expectedBotID, botID) assert.Nil(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) { - expectedBotId := model.NewId() + expectedBotID := model.NewId() api := setupAPI() api.On("GetServerVersion").Return("5.10.0") api.On("KVGet", plugin.BOT_USER_KEY).Return(nil, nil) api.On("GetUserByUsername", testbot.Username).Return(&model.User{ - Id: expectedBotId, + Id: expectedBotID, IsBot: false, }, nil) api.On("LogError", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return() @@ -231,9 +231,9 @@ func TestEnsureBot(t *testing.T) { p := &plugin.HelpersImpl{} p.API = api - botId, err := p.EnsureBot(testbot) + botID, err := p.EnsureBot(testbot) - assert.Equal(t, expectedBotId, botId) + assert.Equal(t, expectedBotID, botID) assert.Nil(t, err) }) @@ -248,14 +248,14 @@ func TestEnsureBot(t *testing.T) { p := &plugin.HelpersImpl{} p.API = api - botId, err := p.EnsureBot(testbot) + botID, err := p.EnsureBot(testbot) - assert.Equal(t, "", botId) + assert.Equal(t, "", botID) assert.NotNil(t, err) }) t.Run("should create bot and set the bot profile image when specified", func(t *testing.T) { - expectedBotId := model.NewId() + expectedBotID := model.NewId() api := setupAPI() testsDir, _ := fileutils.FindDir("tests") @@ -266,24 +266,24 @@ func TestEnsureBot(t *testing.T) { api.On("KVGet", plugin.BOT_USER_KEY).Return(nil, nil) api.On("GetUserByUsername", testbot.Username).Return(nil, nil) api.On("CreateBot", testbot).Return(&model.Bot{ - UserId: expectedBotId, + UserId: expectedBotID, }, nil) - api.On("KVSet", plugin.BOT_USER_KEY, []byte(expectedBotId)).Return(nil) + api.On("KVSet", plugin.BOT_USER_KEY, []byte(expectedBotID)).Return(nil) api.On("GetBundlePath").Return("", nil) - api.On("SetProfileImage", expectedBotId, imageBytes).Return(nil) + api.On("SetProfileImage", expectedBotID, imageBytes).Return(nil) api.On("GetServerVersion").Return("5.10.0") defer api.AssertExpectations(t) p := &plugin.HelpersImpl{} p.API = api - botId, err := p.EnsureBot(testbot, plugin.ProfileImagePath(testImage)) - assert.Equal(t, expectedBotId, botId) + botID, err := p.EnsureBot(testbot, plugin.ProfileImagePath(testImage)) + assert.Equal(t, expectedBotID, botID) assert.Nil(t, err) }) t.Run("should create bot and set the bot icon image when specified", func(t *testing.T) { - expectedBotId := model.NewId() + expectedBotID := model.NewId() api := setupAPI() testsDir, _ := fileutils.FindDir("tests") @@ -294,24 +294,24 @@ func TestEnsureBot(t *testing.T) { api.On("KVGet", plugin.BOT_USER_KEY).Return(nil, nil) api.On("GetUserByUsername", testbot.Username).Return(nil, nil) api.On("CreateBot", testbot).Return(&model.Bot{ - UserId: expectedBotId, + UserId: expectedBotID, }, nil) - api.On("KVSet", plugin.BOT_USER_KEY, []byte(expectedBotId)).Return(nil) + api.On("KVSet", plugin.BOT_USER_KEY, []byte(expectedBotID)).Return(nil) api.On("GetBundlePath").Return("", nil) - api.On("SetBotIconImage", expectedBotId, imageBytes).Return(nil) + api.On("SetBotIconImage", expectedBotID, imageBytes).Return(nil) api.On("GetServerVersion").Return("5.10.0") defer api.AssertExpectations(t) p := &plugin.HelpersImpl{} p.API = api - botId, err := p.EnsureBot(testbot, plugin.IconImagePath(testImage)) - assert.Equal(t, expectedBotId, botId) + botID, err := p.EnsureBot(testbot, plugin.IconImagePath(testImage)) + assert.Equal(t, expectedBotID, botID) assert.Nil(t, err) }) t.Run("should create bot and set both the profile image and bot icon image when specified", func(t *testing.T) { - expectedBotId := model.NewId() + expectedBotID := model.NewId() api := setupAPI() testsDir, _ := fileutils.FindDir("tests") @@ -322,20 +322,20 @@ func TestEnsureBot(t *testing.T) { api.On("KVGet", plugin.BOT_USER_KEY).Return(nil, nil) api.On("GetUserByUsername", testbot.Username).Return(nil, nil) api.On("CreateBot", testbot).Return(&model.Bot{ - UserId: expectedBotId, + UserId: expectedBotID, }, nil) - api.On("KVSet", plugin.BOT_USER_KEY, []byte(expectedBotId)).Return(nil) + api.On("KVSet", plugin.BOT_USER_KEY, []byte(expectedBotID)).Return(nil) api.On("GetBundlePath").Return("", nil) - api.On("SetProfileImage", expectedBotId, imageBytes).Return(nil) - api.On("SetBotIconImage", expectedBotId, imageBytes).Return(nil) + api.On("SetProfileImage", expectedBotID, imageBytes).Return(nil) + api.On("SetBotIconImage", expectedBotID, imageBytes).Return(nil) api.On("GetServerVersion").Return("5.10.0") defer api.AssertExpectations(t) p := &plugin.HelpersImpl{} p.API = api - botId, err := p.EnsureBot(testbot, plugin.ProfileImagePath(testImage), plugin.IconImagePath(testImage)) - assert.Equal(t, expectedBotId, botId) + botID, err := p.EnsureBot(testbot, plugin.ProfileImagePath(testImage), plugin.IconImagePath(testImage)) + assert.Equal(t, expectedBotID, botID) assert.Nil(t, err) }) }) @@ -343,7 +343,7 @@ func TestEnsureBot(t *testing.T) { func TestShouldProcessMessage(t *testing.T) { p := &plugin.HelpersImpl{} - expectedBotId := model.NewId() + expectedBotID := model.NewId() setupAPI := func() *plugintest.API { return &plugintest.API{} @@ -351,9 +351,9 @@ 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.BOT_USER_KEY).Return([]byte(expectedBotID), nil) p.API = api - shouldProcessMessage, _ := p.ShouldProcessMessage(&model.Post{Type: model.POST_HEADER_CHANGE, UserId: expectedBotId}, plugin.AllowSystemMessages(), plugin.AllowBots()) + shouldProcessMessage, _ := p.ShouldProcessMessage(&model.Post{Type: model.POST_HEADER_CHANGE, UserId: expectedBotID}, plugin.AllowSystemMessages(), plugin.AllowBots()) assert.False(t, shouldProcessMessage) }) @@ -369,7 +369,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.BOT_USER_KEY).Return([]byte(expectedBotID), nil) shouldProcessMessage, _ := p.ShouldProcessMessage(&model.Post{ChannelId: channelID}, plugin.AllowSystemMessages(), plugin.AllowBots(), plugin.FilterChannelIDs([]string{"another-channel-id"})) @@ -382,7 +382,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.BOT_USER_KEY).Return([]byte(expectedBotID), nil) shouldProcessMessage, _ := p.ShouldProcessMessage(&model.Post{UserId: userID, ChannelId: channelID}, plugin.AllowSystemMessages(), plugin.FilterUserIDs([]string{"another-user-id"})) @@ -394,12 +394,12 @@ func TestShouldProcessMessage(t *testing.T) { userID := "user-id" channelID := "1" channel := model.Channel{ - Name: "user1__" + expectedBotId, + Name: "user1__" + expectedBotID, Type: model.CHANNEL_OPEN, } api := setupAPI() api.On("GetChannel", channelID).Return(&channel, nil) - api.On("KVGet", plugin.BOT_USER_KEY).Return([]byte(expectedBotId), nil) + api.On("KVGet", plugin.BOT_USER_KEY).Return([]byte(expectedBotID), nil) p.API = api shouldProcessMessage, _ := p.ShouldProcessMessage(&model.Post{UserId: userID, ChannelId: channelID}, plugin.AllowSystemMessages(), plugin.AllowBots(), plugin.OnlyBotDMs()) @@ -410,7 +410,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.BOT_USER_KEY).Return([]byte(expectedBotID), nil) p.API = api shouldProcessMessage, _ := p.ShouldProcessMessage(&model.Post{UserId: "1", Type: model.POST_HEADER_CHANGE, ChannelId: channelID}, @@ -435,11 +435,11 @@ func TestShouldProcessMessage(t *testing.T) { channelID := "1" api := setupAPI() channel := model.Channel{ - Name: "user1__" + expectedBotId, + Name: "user1__" + expectedBotID, 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.BOT_USER_KEY).Return([]byte(expectedBotID), nil) p.API = api shouldProcessMessage, _ := p.ShouldProcessMessage(&model.Post{UserId: "1", Type: model.POST_HEADER_CHANGE, ChannelId: channelID}, diff --git a/plugin/http.go b/plugin/http.go index d7b9956f7d..e2ed27315d 100644 --- a/plugin/http.go +++ b/plugin/http.go @@ -83,8 +83,8 @@ func (w *httpResponseWriterRPCClient) WriteHeader(statusCode int) { w.client.Call("Plugin.WriteHeader", statusCode, nil) } -func (h *httpResponseWriterRPCClient) Close() error { - return h.client.Close() +func (w *httpResponseWriterRPCClient) Close() error { + return w.client.Close() } func connectHTTPResponseWriter(conn io.ReadWriteCloser) *httpResponseWriterRPCClient { diff --git a/plugin/interface_generator/main.go b/plugin/interface_generator/main.go index 2dcc7cbe02..2c90cea73c 100644 --- a/plugin/interface_generator/main.go +++ b/plugin/interface_generator/main.go @@ -84,18 +84,18 @@ func FieldListToEncodedErrors(structPrefix string, fieldList *ast.FieldList, fil } if typeNameBuffer.String() != "error" { - nextLetter += 1 + nextLetter++ continue } name := "" if len(field.Names) == 0 { name = string(nextLetter) - nextLetter += 1 + nextLetter++ } else { for range field.Names { name += string(nextLetter) - nextLetter += 1 + nextLetter++ } } @@ -125,11 +125,11 @@ func FieldListDestruct(structPrefix string, fieldList *ast.FieldList, fileset *t } if len(field.Names) == 0 { result = append(result, structPrefix+string(nextLetter)+suffix) - nextLetter += 1 + nextLetter++ } else { for range field.Names { result = append(result, structPrefix+string(nextLetter)+suffix) - nextLetter += 1 + nextLetter++ } } } @@ -155,11 +155,11 @@ func FieldListToStructList(fieldList *ast.FieldList, fileset *token.FileSet) str } if len(field.Names) == 0 { result = append(result, string(nextLetter)+" "+typeName) - nextLetter += 1 + nextLetter++ } else { for range field.Names { result = append(result, string(nextLetter)+" "+typeName) - nextLetter += 1 + nextLetter++ } } } diff --git a/plugin/plugintest/example_hello_user_test.go b/plugin/plugintest/example_hello_user_test.go index 4d198e75a3..30362b6c59 100644 --- a/plugin/plugintest/example_hello_user_test.go +++ b/plugin/plugintest/example_hello_user_test.go @@ -23,8 +23,8 @@ type HelloUserPlugin struct { } func (p *HelloUserPlugin) ServeHTTP(context *plugin.Context, w http.ResponseWriter, r *http.Request) { - userId := r.Header.Get("Mattermost-User-Id") - user, err := p.API.GetUser(userId) + userID := r.Header.Get("Mattermost-User-Id") + user, err := p.API.GetUser(userID) if err != nil { w.WriteHeader(http.StatusBadRequest) p.API.LogError(err.Error()) diff --git a/plugin/scheduler/scheduler.go b/plugin/scheduler/scheduler.go index a483cf91c1..45c57251e5 100644 --- a/plugin/scheduler/scheduler.go +++ b/plugin/scheduler/scheduler.go @@ -41,9 +41,10 @@ func (scheduler *Scheduler) NextScheduleTime(cfg *model.Config, now time.Time, p func (scheduler *Scheduler) ScheduleJob(cfg *model.Config, pendingJobs bool, lastSuccessfulJob *model.Job) (*model.Job, *model.AppError) { mlog.Debug("Scheduling Job", mlog.String("scheduler", scheduler.Name())) - if job, err := scheduler.App.Srv.Jobs.CreateJob(model.JOB_TYPE_PLUGINS, nil); err != nil { + job, err := scheduler.App.Srv.Jobs.CreateJob(model.JOB_TYPE_PLUGINS, nil) + if err != nil { return nil, err - } else { - return job, nil } + + return job, nil } diff --git a/plugin/scheduler/worker.go b/plugin/scheduler/worker.go index cce5faa8e1..99e769d19e 100644 --- a/plugin/scheduler/worker.go +++ b/plugin/scheduler/worker.go @@ -73,16 +73,14 @@ func (worker *Worker) DoJob(job *model.Job) { return } - err := worker.app.DeleteAllExpiredPluginKeys() - if err == nil { - mlog.Info("Worker: Job is complete", mlog.String("worker", worker.name), mlog.String("job_id", job.Id)) - worker.setJobSuccess(job) - return - } else { + if err := worker.app.DeleteAllExpiredPluginKeys(); err != nil { mlog.Error("Worker: Failed to delete expired keys", mlog.String("worker", worker.name), mlog.String("job_id", job.Id), mlog.String("error", err.Error())) worker.setJobError(job, err) return } + + mlog.Info("Worker: Job is complete", mlog.String("worker", worker.name), mlog.String("job_id", job.Id)) + worker.setJobSuccess(job) } func (worker *Worker) setJobSuccess(job *model.Job) { diff --git a/plugin/supervisor_test.go b/plugin/supervisor_test.go index b2c65805f3..8a0547a700 100644 --- a/plugin/supervisor_test.go +++ b/plugin/supervisor_test.go @@ -18,15 +18,15 @@ import ( func TestSupervisor(t *testing.T) { for name, f := range map[string]func(*testing.T){ - "Supervisor_InvalidExecutablePath": testSupervisor_InvalidExecutablePath, - "Supervisor_NonExistentExecutablePath": testSupervisor_NonExistentExecutablePath, - "Supervisor_StartTimeout": testSupervisor_StartTimeout, + "Supervisor_InvalidExecutablePath": testSupervisorInvalidExecutablePath, + "Supervisor_NonExistentExecutablePath": testSupervisorNonExistentExecutablePath, + "Supervisor_StartTimeout": testSupervisorStartTimeout, } { t.Run(name, f) } } -func testSupervisor_InvalidExecutablePath(t *testing.T) { +func testSupervisorInvalidExecutablePath(t *testing.T) { dir, err := ioutil.TempDir("", "") require.NoError(t, err) defer os.RemoveAll(dir) @@ -45,7 +45,7 @@ func testSupervisor_InvalidExecutablePath(t *testing.T) { assert.Error(t, err) } -func testSupervisor_NonExistentExecutablePath(t *testing.T) { +func testSupervisorNonExistentExecutablePath(t *testing.T) { dir, err := ioutil.TempDir("", "") require.NoError(t, err) defer os.RemoveAll(dir) @@ -65,7 +65,7 @@ func testSupervisor_NonExistentExecutablePath(t *testing.T) { } // If plugin development goes really wrong, let's make sure plugin activation won't block forever. -func testSupervisor_StartTimeout(t *testing.T) { +func testSupervisorStartTimeout(t *testing.T) { dir, err := ioutil.TempDir("", "") require.NoError(t, err) defer os.RemoveAll(dir)