summaryrefslogtreecommitdiffstats
path: root/app/apptestlib.go
diff options
context:
space:
mode:
authorJoramWilander <jwawilander@gmail.com>2018-07-10 15:01:43 -0400
committerJoramWilander <jwawilander@gmail.com>2018-07-10 15:01:43 -0400
commit6c7dc2d29ccac5f9925402f6be1a4c2a3c46c005 (patch)
tree5564a47257bf6e85aaef711980c5b0fcb4d07dcc /app/apptestlib.go
parentc042ffa460296587579aff54b157a5109e022f7e (diff)
parent1e1a5e5e85240f25c4faddcb24c5a29a915fe6e4 (diff)
downloadchat-6c7dc2d29ccac5f9925402f6be1a4c2a3c46c005.tar.gz
chat-6c7dc2d29ccac5f9925402f6be1a4c2a3c46c005.tar.bz2
chat-6c7dc2d29ccac5f9925402f6be1a4c2a3c46c005.zip
Merge branch 'plugins-2'
Diffstat (limited to 'app/apptestlib.go')
-rw-r--r--app/apptestlib.go80
1 files changed, 15 insertions, 65 deletions
diff --git a/app/apptestlib.go b/app/apptestlib.go
index 43d425e16..12b01c5e5 100644
--- a/app/apptestlib.go
+++ b/app/apptestlib.go
@@ -4,23 +4,21 @@
package app
import (
- "encoding/json"
"io"
"io/ioutil"
"os"
"path/filepath"
"time"
+ "testing"
+
"github.com/mattermost/mattermost-server/einterfaces"
"github.com/mattermost/mattermost-server/mlog"
"github.com/mattermost/mattermost-server/model"
- "github.com/mattermost/mattermost-server/plugin"
- "github.com/mattermost/mattermost-server/plugin/pluginenv"
"github.com/mattermost/mattermost-server/store"
"github.com/mattermost/mattermost-server/store/sqlstore"
"github.com/mattermost/mattermost-server/store/storetest"
"github.com/mattermost/mattermost-server/utils"
- "testing"
)
type TestHelper struct {
@@ -35,7 +33,6 @@ type TestHelper struct {
tempConfigPath string
tempWorkspace string
- pluginHooks map[string]plugin.Hooks
}
type persistentTestStore struct {
@@ -93,7 +90,6 @@ func setupTestHelper(enterprise bool) *TestHelper {
th := &TestHelper{
App: a,
- pluginHooks: make(map[string]plugin.Hooks),
tempConfigPath: tempConfig.Name(),
}
@@ -123,6 +119,19 @@ func setupTestHelper(enterprise bool) *TestHelper {
th.App.SetLicense(nil)
}
+ if th.tempWorkspace == "" {
+ dir, err := ioutil.TempDir("", "apptest")
+ if err != nil {
+ panic(err)
+ }
+ th.tempWorkspace = dir
+ }
+
+ pluginDir := filepath.Join(th.tempWorkspace, "plugins")
+ webappDir := filepath.Join(th.tempWorkspace, "webapp")
+
+ th.App.InitPlugins(pluginDir, webappDir)
+
return th
}
@@ -382,65 +391,6 @@ func (me *TestHelper) TearDown() {
}
}
-type mockPluginSupervisor struct {
- hooks plugin.Hooks
-}
-
-func (s *mockPluginSupervisor) Start(api plugin.API) error {
- return s.hooks.OnActivate(api)
-}
-
-func (s *mockPluginSupervisor) Wait() error {
- return nil
-}
-
-func (s *mockPluginSupervisor) Stop() error {
- return nil
-}
-
-func (s *mockPluginSupervisor) Hooks() plugin.Hooks {
- return s.hooks
-}
-
-func (me *TestHelper) InstallPlugin(manifest *model.Manifest, hooks plugin.Hooks) {
- if me.tempWorkspace == "" {
- dir, err := ioutil.TempDir("", "apptest")
- if err != nil {
- panic(err)
- }
- me.tempWorkspace = dir
- }
-
- manifestCopy := *manifest
- if manifestCopy.Backend == nil {
- manifestCopy.Backend = &model.ManifestBackend{}
- }
- manifestBytes, err := json.Marshal(&manifestCopy)
- if err != nil {
- panic(err)
- }
-
- pluginDir := filepath.Join(me.tempWorkspace, "plugins")
- webappDir := filepath.Join(me.tempWorkspace, "webapp")
-
- if err := os.MkdirAll(filepath.Join(pluginDir, manifest.Id), 0700); err != nil {
- panic(err)
- }
-
- if err := ioutil.WriteFile(filepath.Join(pluginDir, manifest.Id, "plugin.json"), manifestBytes, 0600); err != nil {
- panic(err)
- }
-
- me.App.InitPlugins(pluginDir, webappDir, func(bundle *model.BundleInfo) (plugin.Supervisor, error) {
- if hooks, ok := me.pluginHooks[bundle.Manifest.Id]; ok {
- return &mockPluginSupervisor{hooks}, nil
- }
- return pluginenv.DefaultSupervisorProvider(bundle)
- })
-
- me.pluginHooks[manifest.Id] = hooks
-}
-
func (me *TestHelper) ResetRoleMigration() {
if _, err := testStoreSqlSupplier.GetMaster().Exec("DELETE from Roles"); err != nil {
panic(err)