mattermost/plugin/environment_test.go
Agniva De Sarker e89b26e8f3
goimports (#16640)
* format using `goimports -local github.com/mattermost/mattermost-server/v5 -w`

* added goimports lint check to .golangci.yml

* format using `goimports -local github.com/mattermost/mattermost-server/v5 -w` for a corner case

* make app-layers, *-mocks and store-layers for ci check

Co-authored-by: Mahmudul Haque <mahmudulhaque@protonmail.com>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
2021-01-07 22:42:43 +05:30

72 lines
1.8 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/stretchr/testify/require"
"github.com/mattermost/mattermost-server/v5/model"
)
func TestAvaliablePlugins(t *testing.T) {
dir, err1 := ioutil.TempDir("", "mm-plugin-test")
require.NoError(t, err1)
t.Cleanup(func() {
os.RemoveAll(dir)
})
env := Environment{
pluginDir: dir,
}
t.Run("Should be able to load available plugins", func(t *testing.T) {
bundle1 := model.BundleInfo{
ManifestPath: "",
Manifest: &model.Manifest{
Id: "someid",
Version: "1",
},
}
err := os.Mkdir(filepath.Join(dir, "plugin1"), 0700)
require.NoError(t, err)
defer os.RemoveAll(filepath.Join(dir, "plugin1"))
path := filepath.Join(dir, "plugin1", "plugin.json")
err = ioutil.WriteFile(path, []byte(bundle1.Manifest.ToJson()), 0644)
require.NoError(t, err)
bundles, err := env.Available()
require.NoError(t, err)
require.Len(t, bundles, 1)
})
t.Run("Should not be able to load plugins without a valid manifest file", func(t *testing.T) {
err := os.Mkdir(filepath.Join(dir, "plugin2"), 0700)
require.NoError(t, err)
defer os.RemoveAll(filepath.Join(dir, "plugin2"))
path := filepath.Join(dir, "plugin2", "manifest.json")
err = ioutil.WriteFile(path, []byte("{}"), 0644)
require.NoError(t, err)
bundles, err := env.Available()
require.NoError(t, err)
require.Len(t, bundles, 0)
})
t.Run("Should not be able to load plugins without a manifest file", func(t *testing.T) {
err := os.Mkdir(filepath.Join(dir, "plugin3"), 0700)
require.NoError(t, err)
defer os.RemoveAll(filepath.Join(dir, "plugin3"))
bundles, err := env.Available()
require.NoError(t, err)
require.Len(t, bundles, 0)
})
}