MM-10702 Moving plugins to use hashicorp go-plugin. (#8978)
* Moving plugins to use hashicorp go-plugin. * Tweaks from feedback.
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
ecefa6cdd1
Коммит
1e5c432e10
@@ -49,6 +49,7 @@ type TestHelper struct {
|
||||
|
||||
SystemAdminClient *model.Client4
|
||||
SystemAdminUser *model.User
|
||||
tempWorkspace string
|
||||
}
|
||||
|
||||
type persistentTestStore struct {
|
||||
@@ -137,6 +138,25 @@ func setupTestHelper(enterprise bool) *TestHelper {
|
||||
|
||||
th.Client = th.CreateClient()
|
||||
th.SystemAdminClient = th.CreateClient()
|
||||
|
||||
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.UpdateConfig(func(cfg *model.Config) {
|
||||
*cfg.PluginSettings.Directory = pluginDir
|
||||
*cfg.PluginSettings.ClientDirectory = webappDir
|
||||
})
|
||||
|
||||
th.App.InitPlugins(pluginDir, webappDir)
|
||||
|
||||
return th
|
||||
}
|
||||
|
||||
|
||||
@@ -24,11 +24,10 @@ func (api *API) InitPlugin() {
|
||||
api.BaseRoutes.Plugin.Handle("", api.ApiSessionRequired(removePlugin)).Methods("DELETE")
|
||||
|
||||
api.BaseRoutes.Plugins.Handle("/statuses", api.ApiSessionRequired(getPluginStatuses)).Methods("GET")
|
||||
api.BaseRoutes.Plugin.Handle("/activate", api.ApiSessionRequired(activatePlugin)).Methods("POST")
|
||||
api.BaseRoutes.Plugin.Handle("/deactivate", api.ApiSessionRequired(deactivatePlugin)).Methods("POST")
|
||||
api.BaseRoutes.Plugin.Handle("/enable", api.ApiSessionRequired(enablePlugin)).Methods("POST")
|
||||
api.BaseRoutes.Plugin.Handle("/disable", api.ApiSessionRequired(disablePlugin)).Methods("POST")
|
||||
|
||||
api.BaseRoutes.Plugins.Handle("/webapp", api.ApiHandler(getWebappPlugins)).Methods("GET")
|
||||
|
||||
}
|
||||
|
||||
func uploadPlugin(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
@@ -165,7 +164,7 @@ func getWebappPlugins(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte(model.ManifestListToJson(clientManifests)))
|
||||
}
|
||||
|
||||
func activatePlugin(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
func enablePlugin(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.RequirePluginId()
|
||||
if c.Err != nil {
|
||||
return
|
||||
@@ -189,7 +188,7 @@ func activatePlugin(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
ReturnStatusOK(w)
|
||||
}
|
||||
|
||||
func deactivatePlugin(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
func disablePlugin(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
c.RequirePluginId()
|
||||
if c.Err != nil {
|
||||
return
|
||||
|
||||
@@ -6,7 +6,6 @@ package api4
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
@@ -14,18 +13,9 @@ import (
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestPlugin(t *testing.T) {
|
||||
pluginDir, err := ioutil.TempDir("", "mm-plugin-test")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(pluginDir)
|
||||
|
||||
webappDir, err := ioutil.TempDir("", "mm-webapp-test")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(webappDir)
|
||||
|
||||
th := Setup().InitBasic().InitSystemAdmin()
|
||||
defer th.TearDown()
|
||||
|
||||
@@ -47,12 +37,6 @@ func TestPlugin(t *testing.T) {
|
||||
*cfg.PluginSettings.EnableUploads = true
|
||||
})
|
||||
|
||||
th.App.InitPlugins(pluginDir, webappDir, nil)
|
||||
defer func() {
|
||||
th.App.ShutDownPlugins()
|
||||
th.App.PluginEnv = nil
|
||||
}()
|
||||
|
||||
path, _ := utils.FindDir("tests")
|
||||
file, err := os.Open(filepath.Join(path, "testplugin.tar.gz"))
|
||||
if err != nil {
|
||||
@@ -109,7 +93,7 @@ func TestPlugin(t *testing.T) {
|
||||
assert.False(t, found)
|
||||
|
||||
// Successful activate
|
||||
ok, resp := th.SystemAdminClient.ActivatePlugin(manifest.Id)
|
||||
ok, resp := th.SystemAdminClient.EnablePlugin(manifest.Id)
|
||||
CheckNoError(t, resp)
|
||||
assert.True(t, ok)
|
||||
|
||||
@@ -126,12 +110,12 @@ func TestPlugin(t *testing.T) {
|
||||
assert.True(t, found)
|
||||
|
||||
// Activate error case
|
||||
ok, resp = th.SystemAdminClient.ActivatePlugin("junk")
|
||||
ok, resp = th.SystemAdminClient.EnablePlugin("junk")
|
||||
CheckBadRequestStatus(t, resp)
|
||||
assert.False(t, ok)
|
||||
|
||||
// Successful deactivate
|
||||
ok, resp = th.SystemAdminClient.DeactivatePlugin(manifest.Id)
|
||||
ok, resp = th.SystemAdminClient.DisablePlugin(manifest.Id)
|
||||
CheckNoError(t, resp)
|
||||
assert.True(t, ok)
|
||||
|
||||
@@ -148,7 +132,7 @@ func TestPlugin(t *testing.T) {
|
||||
assert.True(t, found)
|
||||
|
||||
// Deactivate error case
|
||||
ok, resp = th.SystemAdminClient.DeactivatePlugin("junk")
|
||||
ok, resp = th.SystemAdminClient.DisablePlugin("junk")
|
||||
CheckBadRequestStatus(t, resp)
|
||||
assert.False(t, ok)
|
||||
|
||||
@@ -162,7 +146,7 @@ func TestPlugin(t *testing.T) {
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
// Successful webapp get
|
||||
_, resp = th.SystemAdminClient.ActivatePlugin(manifest.Id)
|
||||
_, resp = th.SystemAdminClient.EnablePlugin(manifest.Id)
|
||||
CheckNoError(t, resp)
|
||||
|
||||
manifests, resp := th.Client.GetWebappPlugins()
|
||||
|
||||
Ссылка в новой задаче
Block a user