diff options
author | Chris <ccbrown112@gmail.com> | 2017-12-08 13:55:41 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-08 13:55:41 -0600 |
commit | 4c17bdff1bb871fb31520b7b547f584c53ed854f (patch) | |
tree | edf1e3295d6ff7d67281efc585b2e913b4efda3d /app/apptestlib.go | |
parent | 7ed1177a2b676aa4c93515268642c855cfe57a37 (diff) | |
download | chat-4c17bdff1bb871fb31520b7b547f584c53ed854f.tar.gz chat-4c17bdff1bb871fb31520b7b547f584c53ed854f.tar.bz2 chat-4c17bdff1bb871fb31520b7b547f584c53ed854f.zip |
Add plugin slash command support (#7941)
* add plugin slash command support
* remove unused string
* rebase
Diffstat (limited to 'app/apptestlib.go')
-rw-r--r-- | app/apptestlib.go | 73 |
1 files changed, 70 insertions, 3 deletions
diff --git a/app/apptestlib.go b/app/apptestlib.go index 63a064d7f..618ad809a 100644 --- a/app/apptestlib.go +++ b/app/apptestlib.go @@ -4,15 +4,21 @@ package app import ( + "encoding/json" + "io/ioutil" + "os" + "path/filepath" "time" + l4g "github.com/alecthomas/log4go" + "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" - - l4g "github.com/alecthomas/log4go" ) type TestHelper struct { @@ -22,6 +28,9 @@ type TestHelper struct { BasicUser2 *model.User BasicChannel *model.Channel BasicPost *model.Post + + tempWorkspace string + pluginHooks map[string]plugin.Hooks } type persistentTestStore struct { @@ -54,7 +63,8 @@ func setupTestHelper(enterprise bool) *TestHelper { } th := &TestHelper{ - App: New(options...), + App: New(options...), + pluginHooks: make(map[string]plugin.Hooks), } th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.MaxUsersPerTeam = 50 }) @@ -223,4 +233,61 @@ func (me *TestHelper) TearDown() { StopTestStore() panic(err) } + if me.tempWorkspace != "" { + os.RemoveAll(me.tempWorkspace) + } +} + +type mockPluginSupervisor struct { + hooks plugin.Hooks +} + +func (s *mockPluginSupervisor) Start(api plugin.API) error { + return s.hooks.OnActivate(api) +} + +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 + } + + pluginDir := filepath.Join(me.tempWorkspace, "plugins") + webappDir := filepath.Join(me.tempWorkspace, "webapp") + 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 + + manifestCopy := *manifest + if manifestCopy.Backend == nil { + manifestCopy.Backend = &model.ManifestBackend{} + } + manifestBytes, err := json.Marshal(&manifestCopy) + if err != nil { + panic(err) + } + + 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) + } } |