mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
MM-11028 Adding some plugin tests. (#9103)
* Rearranging plugin mocks and moving some common test code out. * Adding tests. * Fixing tests after GoDoc cleanup changes.
This commit is contained in:
committed by
GitHub
parent
309a3dda60
commit
5a2d46c6cb
File diff suppressed because it is too large
Load Diff
@@ -13,13 +13,11 @@ import (
|
||||
"github.com/mattermost/mattermost-server/mlog"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestSupervisor(t *testing.T) {
|
||||
for name, f := range map[string]func(*testing.T){
|
||||
"Supervisor": testSupervisor,
|
||||
"Supervisor_InvalidExecutablePath": testSupervisor_InvalidExecutablePath,
|
||||
"Supervisor_NonExistentExecutablePath": testSupervisor_NonExistentExecutablePath,
|
||||
"Supervisor_StartTimeout": testSupervisor_StartTimeout,
|
||||
@@ -28,7 +26,7 @@ func TestSupervisor(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func CompileGo(t *testing.T, sourceCode, outputPath string) {
|
||||
func compileGo(t *testing.T, sourceCode, outputPath string) {
|
||||
dir, err := ioutil.TempDir(".", "")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(dir)
|
||||
@@ -40,44 +38,6 @@ func CompileGo(t *testing.T, sourceCode, outputPath string) {
|
||||
require.NoError(t, cmd.Run())
|
||||
}
|
||||
|
||||
func testSupervisor(t *testing.T) {
|
||||
dir, err := ioutil.TempDir("", "")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
backend := filepath.Join(dir, "backend.exe")
|
||||
CompileGo(t, `
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattermost/mattermost-server/plugin"
|
||||
)
|
||||
|
||||
type MyPlugin struct {
|
||||
plugin.MattermostPlugin
|
||||
}
|
||||
|
||||
func main() {
|
||||
plugin.ClientMain(&MyPlugin{})
|
||||
}
|
||||
`, backend)
|
||||
|
||||
ioutil.WriteFile(filepath.Join(dir, "plugin.json"), []byte(`{"id": "foo", "backend": {"executable": "backend.exe"}}`), 0600)
|
||||
|
||||
bundle := model.BundleInfoForPath(dir)
|
||||
var api MockAPI
|
||||
api.On("LoadPluginConfiguration", mock.Anything).Return(nil)
|
||||
log := mlog.NewLogger(&mlog.LoggerConfiguration{
|
||||
EnableConsole: true,
|
||||
ConsoleJson: true,
|
||||
ConsoleLevel: "error",
|
||||
EnableFile: false,
|
||||
})
|
||||
supervisor, err := newSupervisor(bundle, log, &api)
|
||||
require.NoError(t, err)
|
||||
supervisor.Shutdown()
|
||||
}
|
||||
|
||||
func testSupervisor_InvalidExecutablePath(t *testing.T) {
|
||||
dir, err := ioutil.TempDir("", "")
|
||||
require.NoError(t, err)
|
||||
@@ -123,7 +83,7 @@ func testSupervisor_StartTimeout(t *testing.T) {
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
backend := filepath.Join(dir, "backend.exe")
|
||||
CompileGo(t, `
|
||||
compileGo(t, `
|
||||
package main
|
||||
|
||||
func main() {
|
||||
|
||||
Reference in New Issue
Block a user