summaryrefslogtreecommitdiffstats
path: root/app/plugin_test.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2018-06-25 12:33:13 -0700
committerGitHub <noreply@github.com>2018-06-25 12:33:13 -0700
commit1e5c432e1029601a664454388ae366ef69618d62 (patch)
treecb9e8bfb66640ac3b29c934bb2c3202d25aeb368 /app/plugin_test.go
parentecefa6cdd1e7376046bbec82c1b47f7756fea646 (diff)
downloadchat-1e5c432e1029601a664454388ae366ef69618d62.tar.gz
chat-1e5c432e1029601a664454388ae366ef69618d62.tar.bz2
chat-1e5c432e1029601a664454388ae366ef69618d62.zip
MM-10702 Moving plugins to use hashicorp go-plugin. (#8978)
* Moving plugins to use hashicorp go-plugin. * Tweaks from feedback.
Diffstat (limited to 'app/plugin_test.go')
-rw-r--r--app/plugin_test.go153
1 files changed, 1 insertions, 152 deletions
diff --git a/app/plugin_test.go b/app/plugin_test.go
index db5954d4d..b0b6e9c1b 100644
--- a/app/plugin_test.go
+++ b/app/plugin_test.go
@@ -4,19 +4,14 @@
package app
import (
- "errors"
"net/http"
"net/http/httptest"
"testing"
- "time"
"github.com/gorilla/mux"
+ "github.com/mattermost/mattermost-server/model"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
-
- "github.com/mattermost/mattermost-server/model"
- "github.com/mattermost/mattermost-server/plugin"
- "github.com/mattermost/mattermost-server/plugin/plugintest"
)
func TestPluginKeyValueStore(t *testing.T) {
@@ -103,152 +98,6 @@ func TestHandlePluginRequest(t *testing.T) {
router.ServeHTTP(nil, r)
}
-type testPlugin struct {
- plugintest.Hooks
-}
-
-func (p *testPlugin) OnConfigurationChange() error {
- return nil
-}
-
-func (p *testPlugin) OnDeactivate() error {
- return nil
-}
-
-type pluginCommandTestPlugin struct {
- testPlugin
-
- TeamId string
-}
-
-func (p *pluginCommandTestPlugin) OnActivate(api plugin.API) error {
- if err := api.RegisterCommand(&model.Command{
- Trigger: "foo",
- TeamId: p.TeamId,
- }); err != nil {
- return err
- }
- if err := api.RegisterCommand(&model.Command{
- Trigger: "foo2",
- TeamId: p.TeamId,
- }); err != nil {
- return err
- }
- return api.UnregisterCommand(p.TeamId, "foo2")
-}
-
-func (p *pluginCommandTestPlugin) ExecuteCommand(args *model.CommandArgs) (*model.CommandResponse, *model.AppError) {
- if args.Command == "/foo" {
- return &model.CommandResponse{
- Text: "bar",
- }, nil
- }
- return nil, model.NewAppError("ExecuteCommand", "this is an error", nil, "", http.StatusBadRequest)
-}
-
-func TestPluginCommands(t *testing.T) {
- th := Setup().InitBasic()
- defer th.TearDown()
-
- th.InstallPlugin(&model.Manifest{
- Id: "foo",
- }, &pluginCommandTestPlugin{
- TeamId: th.BasicTeam.Id,
- })
-
- require.Nil(t, th.App.EnablePlugin("foo"))
-
- // Ideally, we would wait for the websocket activation event instead of just sleeping.
- time.Sleep(500 * time.Millisecond)
-
- pluginStatuses, err := th.App.GetPluginStatuses()
- require.Nil(t, err)
- found := false
- for _, pluginStatus := range pluginStatuses {
- if pluginStatus.PluginId == "foo" {
- require.Equal(t, model.PluginStateRunning, pluginStatus.State)
- found = true
- }
- }
- require.True(t, found, "failed to find plugin foo in plugin statuses")
-
- resp, err := th.App.ExecuteCommand(&model.CommandArgs{
- Command: "/foo2",
- TeamId: th.BasicTeam.Id,
- UserId: th.BasicUser.Id,
- ChannelId: th.BasicChannel.Id,
- })
- require.NotNil(t, err)
- assert.Equal(t, http.StatusNotFound, err.StatusCode)
-
- resp, err = th.App.ExecuteCommand(&model.CommandArgs{
- Command: "/foo",
- TeamId: th.BasicTeam.Id,
- UserId: th.BasicUser.Id,
- ChannelId: th.BasicChannel.Id,
- })
- require.Nil(t, err)
- assert.Equal(t, "bar", resp.Text)
-
- resp, err = th.App.ExecuteCommand(&model.CommandArgs{
- Command: "/foo baz",
- TeamId: th.BasicTeam.Id,
- UserId: th.BasicUser.Id,
- ChannelId: th.BasicChannel.Id,
- })
- require.NotNil(t, err)
- require.Equal(t, "this is an error", err.Message)
- assert.Nil(t, resp)
-
- require.Nil(t, th.App.RemovePlugin("foo"))
-
- resp, err = th.App.ExecuteCommand(&model.CommandArgs{
- Command: "/foo",
- TeamId: th.BasicTeam.Id,
- UserId: th.BasicUser.Id,
- ChannelId: th.BasicChannel.Id,
- })
- require.NotNil(t, err)
- assert.Equal(t, http.StatusNotFound, err.StatusCode)
-}
-
-type pluginBadActivation struct {
- testPlugin
-}
-
-func (p *pluginBadActivation) OnActivate(api plugin.API) error {
- return errors.New("won't activate for some reason")
-}
-
-func TestPluginBadActivation(t *testing.T) {
- th := Setup().InitBasic()
- defer th.TearDown()
-
- th.InstallPlugin(&model.Manifest{
- Id: "foo",
- }, &pluginBadActivation{})
-
- t.Run("EnablePlugin bad activation", func(t *testing.T) {
- err := th.App.EnablePlugin("foo")
- assert.Nil(t, err)
-
- // Ideally, we would wait for the websocket activation event instead of just
- // sleeping.
- time.Sleep(500 * time.Millisecond)
-
- pluginStatuses, err := th.App.GetPluginStatuses()
- require.Nil(t, err)
- found := false
- for _, pluginStatus := range pluginStatuses {
- if pluginStatus.PluginId == "foo" {
- require.Equal(t, model.PluginStateFailedToStart, pluginStatus.State)
- found = true
- }
- }
- require.True(t, found, "failed to find plugin foo in plugin statuses")
- })
-}
-
func TestGetPluginStatusesDisabled(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()