* Basic plugin context.

* Adding more useful fields to plugin context.

* Fix spelling

Co-Authored-By: crspeller <crspeller@gmail.com>

* Fixing location of context creation.
Этот коммит содержится в:
Christopher Speller
2018-12-05 10:46:08 -08:00
коммит произвёл GitHub
родитель de5440d979
Коммит aba194188f
13 изменённых файлов: 113 добавлений и 34 удалений

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

@@ -887,3 +887,62 @@ func TestErrorString(t *testing.T) {
require.Equal(t, expectedErr, cause)
})
}
func TestHookContext(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
// We don't actually have a session, we are faking it so just set something arbitrarily
th.App.Session.Id = model.NewId()
th.App.RequestId = model.NewId()
th.App.IpAddress = model.NewId()
th.App.AcceptLanguage = model.NewId()
th.App.UserAgent = model.NewId()
var mockAPI plugintest.API
mockAPI.On("LoadPluginConfiguration", mock.Anything).Return(nil)
mockAPI.On("LogDebug", th.App.Session.Id).Return(nil)
mockAPI.On("LogInfo", th.App.RequestId).Return(nil)
mockAPI.On("LogError", th.App.IpAddress).Return(nil)
mockAPI.On("LogWarn", th.App.AcceptLanguage).Return(nil)
mockAPI.On("DeleteTeam", th.App.UserAgent).Return(nil)
tearDown, _, _ := SetAppEnvironmentWithPlugins(t,
[]string{
`
package main
import (
"github.com/mattermost/mattermost-server/plugin"
"github.com/mattermost/mattermost-server/model"
)
type MyPlugin struct {
plugin.MattermostPlugin
}
func (p *MyPlugin) MessageHasBeenPosted(c *plugin.Context, post *model.Post) {
p.API.LogDebug(c.SessionId)
p.API.LogInfo(c.RequestId)
p.API.LogError(c.IpAddress)
p.API.LogWarn(c.AcceptLanguage)
p.API.DeleteTeam(c.UserAgent)
}
func main() {
plugin.ClientMain(&MyPlugin{})
}
`}, th.App, func(*model.Manifest) plugin.API { return &mockAPI })
defer tearDown()
post := &model.Post{
UserId: th.BasicUser.Id,
ChannelId: th.BasicChannel.Id,
Message: "not this",
CreateAt: model.GetMillis() - 10000,
}
_, err := th.App.CreatePost(post, th.BasicChannel, false)
if err != nil {
t.Fatal(err)
}
}