grafana/pkg/setting/setting_plugins_test.go
Marcus Efraimsson 34266cd369
Backend Plugins: Plugin configuration using Grafana config (#23451)
Enables adding a section `plugin.<plugin id>` and key/value to
Grafana configuration file which will be converted and sent
as environment variables to the backend plugin.
Also sends some additional environment variables, Grafana
version (GF_VERSION), Grafana edition (GF_EDITION) and 
enterprise license path (GF_ENTERPRISE_LICENSE_PATH).

Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>

Fixes #21515,
2020-04-14 18:04:27 +02:00

44 lines
1.1 KiB
Go

package setting
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestPluginSettings(t *testing.T) {
cfg := NewCfg()
sec, err := cfg.Raw.NewSection("plugin")
require.NoError(t, err)
_, err = sec.NewKey("key", "value")
require.NoError(t, err)
sec, err = cfg.Raw.NewSection("plugin.plugin")
require.NoError(t, err)
_, err = sec.NewKey("key1", "value1")
require.NoError(t, err)
_, err = sec.NewKey("key2", "value2")
require.NoError(t, err)
sec, err = cfg.Raw.NewSection("plugin.plugin2")
require.NoError(t, err)
_, err = sec.NewKey("key3", "value3")
require.NoError(t, err)
_, err = sec.NewKey("key4", "value4")
require.NoError(t, err)
sec, err = cfg.Raw.NewSection("other")
require.NoError(t, err)
_, err = sec.NewKey("keySomething", "whatever")
require.NoError(t, err)
ps := extractPluginSettings(cfg.Raw.Sections())
require.Len(t, ps, 2)
require.Len(t, ps["plugin"], 2)
require.Equal(t, ps["plugin"]["key1"], "value1")
require.Equal(t, ps["plugin"]["key2"], "value2")
require.Len(t, ps["plugin2"], 2)
require.Equal(t, ps["plugin2"]["key3"], "value3")
require.Equal(t, ps["plugin2"]["key4"], "value4")
}