mirror of
https://github.com/mattermost/mattermost.git
synced 2026-02-03 20:40:00 -05:00
* MM-21626,MM-21627 - Plugin API/Hooks Prometheus instrumentation * Updated einterface mocks * Fixed supervisor tests * ignoring golint errors for plugin metrics wrappers * Making golangci happy * Using variadic form when generating wrapper code * Removed artificial delay * Removed comments from tests * Renaming plugin wrappers to api/hooks_timer_layer * updating vendor dir and mod files * Recording plugin api/hook responses in prometheus * Updated einterfaces-mocks * Updating go sum * Updating go sum * Fixing conflicts * More conflicts fixing Co-authored-by: mattermod <mattermod@users.noreply.github.com>
95 lines
2.7 KiB
Go
95 lines
2.7 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package plugin
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/mattermost/mattermost-server/v5/mlog"
|
|
"github.com/mattermost/mattermost-server/v5/model"
|
|
"github.com/mattermost/mattermost-server/v5/utils"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestSupervisor(t *testing.T) {
|
|
for name, f := range map[string]func(*testing.T){
|
|
"Supervisor_InvalidExecutablePath": testSupervisorInvalidExecutablePath,
|
|
"Supervisor_NonExistentExecutablePath": testSupervisorNonExistentExecutablePath,
|
|
"Supervisor_StartTimeout": testSupervisorStartTimeout,
|
|
} {
|
|
t.Run(name, f)
|
|
}
|
|
}
|
|
|
|
func testSupervisorInvalidExecutablePath(t *testing.T) {
|
|
dir, err := ioutil.TempDir("", "")
|
|
require.NoError(t, err)
|
|
defer os.RemoveAll(dir)
|
|
|
|
ioutil.WriteFile(filepath.Join(dir, "plugin.json"), []byte(`{"id": "foo", "backend": {"executable": "/foo/../../backend.exe"}}`), 0600)
|
|
|
|
bundle := model.BundleInfoForPath(dir)
|
|
log := mlog.NewLogger(&mlog.LoggerConfiguration{
|
|
EnableConsole: true,
|
|
ConsoleJson: true,
|
|
ConsoleLevel: "error",
|
|
EnableFile: false,
|
|
})
|
|
supervisor, err := newSupervisor(bundle, nil, log, nil)
|
|
assert.Nil(t, supervisor)
|
|
assert.Error(t, err)
|
|
}
|
|
|
|
func testSupervisorNonExistentExecutablePath(t *testing.T) {
|
|
dir, err := ioutil.TempDir("", "")
|
|
require.NoError(t, err)
|
|
defer os.RemoveAll(dir)
|
|
|
|
ioutil.WriteFile(filepath.Join(dir, "plugin.json"), []byte(`{"id": "foo", "backend": {"executable": "thisfileshouldnotexist"}}`), 0600)
|
|
|
|
bundle := model.BundleInfoForPath(dir)
|
|
log := mlog.NewLogger(&mlog.LoggerConfiguration{
|
|
EnableConsole: true,
|
|
ConsoleJson: true,
|
|
ConsoleLevel: "error",
|
|
EnableFile: false,
|
|
})
|
|
supervisor, err := newSupervisor(bundle, nil, log, nil)
|
|
require.Error(t, err)
|
|
require.Nil(t, supervisor)
|
|
}
|
|
|
|
// If plugin development goes really wrong, let's make sure plugin activation won't block forever.
|
|
func testSupervisorStartTimeout(t *testing.T) {
|
|
dir, err := ioutil.TempDir("", "")
|
|
require.NoError(t, err)
|
|
defer os.RemoveAll(dir)
|
|
|
|
backend := filepath.Join(dir, "backend.exe")
|
|
utils.CompileGo(t, `
|
|
package main
|
|
|
|
func main() {
|
|
for {
|
|
}
|
|
}
|
|
`, backend)
|
|
|
|
ioutil.WriteFile(filepath.Join(dir, "plugin.json"), []byte(`{"id": "foo", "backend": {"executable": "backend.exe"}}`), 0600)
|
|
|
|
bundle := model.BundleInfoForPath(dir)
|
|
log := mlog.NewLogger(&mlog.LoggerConfiguration{
|
|
EnableConsole: true,
|
|
ConsoleJson: true,
|
|
ConsoleLevel: "error",
|
|
EnableFile: false,
|
|
})
|
|
supervisor, err := newSupervisor(bundle, nil, log, nil)
|
|
require.Error(t, err)
|
|
require.Nil(t, supervisor)
|
|
}
|