[MM-14576] Add GetBundlePath method to Plugin API (#10466)

* Fix typo

* Add GetBundlePath method to Plugin API

* Change signature to GetBundlePath() (string, error)

* Add test
This commit is contained in:
Hanzei
2019-03-18 23:01:26 +01:00
committed by Jesse Hallam
parent 16a9489bbb
commit 030ba52b08
5 changed files with 111 additions and 6 deletions

View File

@@ -510,6 +510,47 @@ func TestPluginAPILoadPluginConfigurationDefaults(t *testing.T) {
assert.Equal(t, "override35true", ret)
}
func TestPluginAPIGetBundlePath(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
setupPluginApiTest(t,
`
package main
import (
"github.com/mattermost/mattermost-server/plugin"
"github.com/mattermost/mattermost-server/model"
)
type MyPlugin struct {
plugin.MattermostPlugin
}
func (p *MyPlugin) MessageWillBePosted(c *plugin.Context, post *model.Post) (*model.Post, string) {
bundlePath, err := p.API.GetBundlePath()
if err != nil {
return nil, err.Error() + "failed get bundle path"
}
return nil, bundlePath
}
func main() {
plugin.ClientMain(&MyPlugin{})
}
`, `{"id": "testplugin", "backend": {"executable": "backend.exe"}}`, "testplugin", th.App)
hooks, err := th.App.GetPluginsEnvironment().HooksForPlugin("testplugin")
require.Nil(t, err)
require.NotNil(t, hooks)
bundlePath, err := filepath.Abs(filepath.Join(*th.App.Config().PluginSettings.Directory, "testplugin"))
require.Nil(t, err)
_, errString := hooks.MessageWillBePosted(nil, nil)
assert.Equal(t, bundlePath, errString)
}
func TestPluginAPIGetProfileImage(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()