mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* chore(perf): Pre-allocate where possible (enable prealloc linter) Signed-off-by: Dave Henderson <dave.henderson@grafana.com> * fix TestAlertManagers_buildRedactedAMs Signed-off-by: Dave Henderson <dave.henderson@grafana.com> * prealloc a slice that appeared after rebase Signed-off-by: Dave Henderson <dave.henderson@grafana.com> --------- Signed-off-by: Dave Henderson <dave.henderson@grafana.com>
72 lines
1.8 KiB
Go
72 lines
1.8 KiB
Go
package sources
|
|
|
|
import (
|
|
"errors"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/grafana/grafana/pkg/plugins"
|
|
)
|
|
|
|
func TestDirAsLocalSources(t *testing.T) {
|
|
testdataDir := "../testdata"
|
|
|
|
tests := []struct {
|
|
name string
|
|
pluginsPath string
|
|
expected []*LocalSource
|
|
err error
|
|
}{
|
|
{
|
|
name: "Empty path returns an error",
|
|
pluginsPath: "",
|
|
expected: []*LocalSource{},
|
|
err: errors.New("plugins path not configured"),
|
|
},
|
|
{
|
|
name: "Directory with subdirectories",
|
|
pluginsPath: filepath.Join(testdataDir, "pluginRootWithDist"),
|
|
expected: []*LocalSource{
|
|
{
|
|
paths: []string{filepath.Join(testdataDir, "pluginRootWithDist", "datasource")},
|
|
class: plugins.ClassExternal,
|
|
},
|
|
{
|
|
paths: []string{filepath.Join(testdataDir, "pluginRootWithDist", "dist")},
|
|
class: plugins.ClassExternal,
|
|
},
|
|
{
|
|
paths: []string{filepath.Join(testdataDir, "pluginRootWithDist", "panel")},
|
|
class: plugins.ClassExternal,
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "Directory with no subdirectories",
|
|
pluginsPath: filepath.Join(testdataDir, "pluginRootWithDist", "datasource"),
|
|
expected: []*LocalSource{},
|
|
},
|
|
{
|
|
name: "Directory with a symlink to a directory",
|
|
pluginsPath: filepath.Join(testdataDir, "symbolic-plugin-dirs"),
|
|
expected: []*LocalSource{
|
|
{
|
|
paths: []string{filepath.Join(testdataDir, "symbolic-plugin-dirs", "plugin")},
|
|
class: plugins.ClassExternal,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := DirAsLocalSources(tt.pluginsPath, plugins.ClassExternal)
|
|
if tt.err != nil {
|
|
require.Errorf(t, err, tt.err.Error())
|
|
}
|
|
require.Equal(t, tt.expected, got)
|
|
})
|
|
}
|
|
}
|