summaryrefslogtreecommitdiffstats
path: root/plugin/pluginenv/search_path_test.go
diff options
context:
space:
mode:
authorChris <ccbrown112@gmail.com>2017-08-16 17:23:38 -0500
committerGitHub <noreply@github.com>2017-08-16 17:23:38 -0500
commitf80d50adbddf55a043dfcab5b47d7c1e22749b7d (patch)
tree5deb606debb6322716c9cdcc6c58be4f68b74223 /plugin/pluginenv/search_path_test.go
parent4f85ed985d478ddf6692fa4f7d8d98d2a412d18c (diff)
downloadchat-f80d50adbddf55a043dfcab5b47d7c1e22749b7d.tar.gz
chat-f80d50adbddf55a043dfcab5b47d7c1e22749b7d.tar.bz2
chat-f80d50adbddf55a043dfcab5b47d7c1e22749b7d.zip
PLT-7407: Back-end plugin mechanism (#7177)
* begin backend plugin wip * flesh out rpcplugin. everything done except for minor supervisor stubs * done with basic plugin infrastructure * simplify tests * remove unused test lines
Diffstat (limited to 'plugin/pluginenv/search_path_test.go')
-rw-r--r--plugin/pluginenv/search_path_test.go62
1 files changed, 62 insertions, 0 deletions
diff --git a/plugin/pluginenv/search_path_test.go b/plugin/pluginenv/search_path_test.go
new file mode 100644
index 000000000..d9a18cf56
--- /dev/null
+++ b/plugin/pluginenv/search_path_test.go
@@ -0,0 +1,62 @@
+package pluginenv
+
+import (
+ "encoding/json"
+ "os"
+ "path/filepath"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+
+ "github.com/mattermost/platform/plugin"
+)
+
+func TestScanSearchPath(t *testing.T) {
+ dir := initTmpDir(t, map[string]string{
+ ".foo/plugin.json": `{"id": "foo"}`,
+ "foo/bar": "asdf",
+ "foo/plugin.json": `{"id": "foo"}`,
+ "bar/zxc": "qwer",
+ "baz/plugin.yaml": "id: baz",
+ "bad/plugin.json": "asd",
+ "qwe": "asd",
+ })
+ defer os.RemoveAll(dir)
+
+ plugins, err := ScanSearchPath(dir)
+ require.NoError(t, err)
+ assert.Len(t, plugins, 3)
+ assert.Contains(t, plugins, &plugin.BundleInfo{
+ Path: filepath.Join(dir, "foo"),
+ ManifestPath: filepath.Join(dir, "foo", "plugin.json"),
+ Manifest: &plugin.Manifest{
+ Id: "foo",
+ },
+ })
+ assert.Contains(t, plugins, &plugin.BundleInfo{
+ Path: filepath.Join(dir, "baz"),
+ ManifestPath: filepath.Join(dir, "baz", "plugin.yaml"),
+ Manifest: &plugin.Manifest{
+ Id: "baz",
+ },
+ })
+ foundError := false
+ for _, x := range plugins {
+ if x.ManifestError != nil {
+ assert.Equal(t, x.Path, filepath.Join(dir, "bad"))
+ assert.Equal(t, x.ManifestPath, filepath.Join(dir, "bad", "plugin.json"))
+ syntexError, ok := x.ManifestError.(*json.SyntaxError)
+ assert.True(t, ok)
+ assert.EqualValues(t, 1, syntexError.Offset)
+ foundError = true
+ }
+ }
+ assert.True(t, foundError)
+}
+
+func TestScanSearchPath_Error(t *testing.T) {
+ plugins, err := ScanSearchPath("not a valid path!")
+ assert.Nil(t, plugins)
+ assert.Error(t, err)
+}