2023-10-17 10:29:06 -05:00
|
|
|
package grafanaapiserver
|
|
|
|
|
|
|
|
import (
|
2023-10-23 13:42:10 -05:00
|
|
|
"net"
|
2023-10-17 10:29:06 -05:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2023-11-13 09:55:15 -06:00
|
|
|
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
2023-10-17 10:29:06 -05:00
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewConfig(t *testing.T) {
|
2023-11-13 09:55:15 -06:00
|
|
|
// nolint:staticcheck
|
|
|
|
cfg := setting.NewCfgWithFeatures(featuremgmt.WithFeatures(featuremgmt.FlagGrafanaAPIServer).IsEnabled)
|
2023-10-23 13:42:10 -05:00
|
|
|
cfg.Env = setting.Prod
|
2023-10-17 10:29:06 -05:00
|
|
|
cfg.DataPath = "/tmp/grafana"
|
2023-10-23 13:42:10 -05:00
|
|
|
cfg.HTTPAddr = "10.0.0.1"
|
2023-10-17 10:29:06 -05:00
|
|
|
cfg.HTTPPort = "4000"
|
|
|
|
cfg.AppURL = "http://test:4000"
|
|
|
|
|
|
|
|
section := cfg.Raw.Section("grafana-apiserver")
|
|
|
|
section.Key("log_level").SetValue("5")
|
|
|
|
section.Key("etcd_servers").SetValue("http://localhost:2379")
|
|
|
|
|
|
|
|
actual := newConfig(cfg)
|
|
|
|
|
|
|
|
expected := &config{
|
|
|
|
enabled: true,
|
2023-10-23 13:42:10 -05:00
|
|
|
devMode: false,
|
2023-10-27 15:39:27 -05:00
|
|
|
storageType: StorageTypeLegacy,
|
2023-10-17 10:29:06 -05:00
|
|
|
etcdServers: []string{"http://localhost:2379"},
|
2023-10-23 13:42:10 -05:00
|
|
|
apiURL: "http://test:4000",
|
|
|
|
ip: net.ParseIP("10.0.0.1"),
|
|
|
|
port: 4000,
|
|
|
|
host: "10.0.0.1:4000",
|
2023-10-17 10:29:06 -05:00
|
|
|
dataPath: "/tmp/grafana/grafana-apiserver",
|
|
|
|
logLevel: 5,
|
|
|
|
}
|
|
|
|
require.Equal(t, expected, actual)
|
|
|
|
}
|