mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
* NewIA: Plugin nav config * progress * Progress * Things are working * Add monitoring node * Add alerts and incidents * added experiment with standalone page * Refactoring by adding a type for navtree root * First test working * More tests * more tests * Progress on richer config and sorting * Sort weight working * Path config * Improving logic for not including admin or cfg nodes, making it the last step so that enterprise can add admin nodes without having to worry about the section not existing * fixed index routes * removed file * Fixes * Fixing tests * Fixing more tests and adding support for weight config * Updates * Remove unused fake * More fixes * Minor tweak * Minor fix * Can now control position using sortweight even when existing items have no sortweight * Added tests for frontend standalone page logic * more tests * Remove unused fake and fixed lint issue * Moving reading settings to navtree impl package * remove nav_id setting prefix * Remove old test file * Fix trailing newline * Fixed bug with adding nil node * fixing lint issue * remove some code we have to rethink * move read settings to PrivideService and switch to util.SplitString
90 lines
3.0 KiB
Go
90 lines
3.0 KiB
Go
package plugins
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/grafana/grafana/pkg/infra/log"
|
|
"github.com/grafana/grafana/pkg/plugins"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
const (
|
|
incorrectSettings = "./testdata/test-configs/incorrect-settings"
|
|
brokenYaml = "./testdata/test-configs/broken-yaml"
|
|
emptyFolder = "./testdata/test-configs/empty_folder"
|
|
unknownApp = "./testdata/test-configs/unknown-app"
|
|
correctProperties = "./testdata/test-configs/correct-properties"
|
|
)
|
|
|
|
func TestConfigReader(t *testing.T) {
|
|
t.Run("Broken yaml should return error", func(t *testing.T) {
|
|
reader := newConfigReader(log.New("test logger"), nil)
|
|
_, err := reader.readConfig(context.Background(), brokenYaml)
|
|
require.Error(t, err)
|
|
})
|
|
|
|
t.Run("Skip invalid directory", func(t *testing.T) {
|
|
cfgProvider := newConfigReader(log.New("test logger"), nil)
|
|
cfg, err := cfgProvider.readConfig(context.Background(), emptyFolder)
|
|
require.NoError(t, err)
|
|
require.Len(t, cfg, 0)
|
|
})
|
|
|
|
t.Run("Unknown app plugin should return error", func(t *testing.T) {
|
|
cfgProvider := newConfigReader(log.New("test logger"), plugins.FakePluginStore{})
|
|
_, err := cfgProvider.readConfig(context.Background(), unknownApp)
|
|
require.Error(t, err)
|
|
require.Equal(t, "plugin not installed: \"nonexisting\"", err.Error())
|
|
})
|
|
|
|
t.Run("Read incorrect properties", func(t *testing.T) {
|
|
cfgProvider := newConfigReader(log.New("test logger"), nil)
|
|
_, err := cfgProvider.readConfig(context.Background(), incorrectSettings)
|
|
require.Error(t, err)
|
|
require.Equal(t, "app item 1 in configuration doesn't contain required field type", err.Error())
|
|
})
|
|
|
|
t.Run("Can read correct properties", func(t *testing.T) {
|
|
pm := plugins.FakePluginStore{
|
|
PluginList: []plugins.PluginDTO{
|
|
{JSONData: plugins.JSONData{ID: "test-plugin"}},
|
|
{JSONData: plugins.JSONData{ID: "test-plugin-2"}},
|
|
},
|
|
}
|
|
|
|
err := os.Setenv("ENABLE_PLUGIN_VAR", "test-plugin")
|
|
require.NoError(t, err)
|
|
t.Cleanup(func() {
|
|
_ = os.Unsetenv("ENABLE_PLUGIN_VAR")
|
|
})
|
|
|
|
cfgProvider := newConfigReader(log.New("test logger"), pm)
|
|
cfg, err := cfgProvider.readConfig(context.Background(), correctProperties)
|
|
require.NoError(t, err)
|
|
require.Len(t, cfg, 1)
|
|
|
|
testCases := []struct {
|
|
ExpectedPluginID string
|
|
ExpectedOrgID int64
|
|
ExpectedOrgName string
|
|
ExpectedEnabled bool
|
|
}{
|
|
{ExpectedPluginID: "test-plugin", ExpectedOrgID: 2, ExpectedOrgName: "", ExpectedEnabled: true},
|
|
{ExpectedPluginID: "test-plugin-2", ExpectedOrgID: 3, ExpectedOrgName: "", ExpectedEnabled: false},
|
|
{ExpectedPluginID: "test-plugin", ExpectedOrgID: 0, ExpectedOrgName: "Org 3", ExpectedEnabled: true},
|
|
{ExpectedPluginID: "test-plugin-2", ExpectedOrgID: 1, ExpectedOrgName: "", ExpectedEnabled: true},
|
|
}
|
|
|
|
for index, tc := range testCases {
|
|
app := cfg[0].Apps[index]
|
|
require.NotNil(t, app)
|
|
require.Equal(t, tc.ExpectedPluginID, app.PluginID)
|
|
require.Equal(t, tc.ExpectedOrgID, app.OrgID)
|
|
require.Equal(t, tc.ExpectedOrgName, app.OrgName)
|
|
require.Equal(t, tc.ExpectedEnabled, app.Enabled)
|
|
}
|
|
})
|
|
}
|