grafana/pkg/services/pluginsintegration/pluginconfig/config_test.go
Will Browne 5edd96ae77
Plugins: Refactor plugin config into separate env var and request scoped services (#83261)
* seperate services for env + req

* merge with main

* fix tests

* undo changes to golden file

* fix linter

* remove unused fields

* split out new config struct

* provide config

* undo go mod changes

* more renaming

* fix tests

* undo bra.toml changes

* update go.work.sum

* undo changes

* trigger

* apply PR feedback
2024-02-27 12:38:02 +01:00

39 lines
875 B
Go

package pluginconfig
import (
"testing"
"gopkg.in/ini.v1"
"github.com/grafana/grafana/pkg/setting"
"github.com/stretchr/testify/require"
)
func TestPluginSettings(t *testing.T) {
raw, err := ini.Load([]byte(`
[plugins]
test_key = 123
[plugin.test-datasource]
foo = 5m
bar = something
[plugin.secret-plugin]
secret_key = secret
normal_key = not a secret`))
require.NoError(t, err)
cfg := &setting.Cfg{Raw: raw}
settings := &setting.OSSImpl{Cfg: cfg}
ps := extractPluginSettings(settings)
require.Len(t, ps, 2)
require.Len(t, ps["test-datasource"], 2)
require.Equal(t, ps["test-datasource"]["foo"], "5m")
require.Equal(t, ps["test-datasource"]["bar"], "something")
require.Len(t, ps["secret-plugin"], 2)
require.Equal(t, ps["secret-plugin"]["secret_key"], "secret")
require.Equal(t, ps["secret-plugin"]["normal_key"], "not a secret")
}