| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- package setting
- import (
- "os"
- "path/filepath"
- "testing"
- . "github.com/smartystreets/goconvey/convey"
- )
- func TestLoadingSettings(t *testing.T) {
- HomePath, _ = filepath.Abs("../../")
- Convey("Testing loading settings from ini file", t, func() {
- Convey("Given the default ini files", func() {
- NewConfigContext(&CommandLineArgs{})
- So(AppName, ShouldEqual, "Grafana")
- So(AdminUser, ShouldEqual, "admin")
- })
- Convey("Should be able to override via environment variables", func() {
- os.Setenv("GF_SECURITY_ADMIN_USER", "superduper")
- NewConfigContext(&CommandLineArgs{})
- So(AdminUser, ShouldEqual, "superduper")
- So(DataPath, ShouldEqual, filepath.Join(HomePath, "data"))
- So(LogsPath, ShouldEqual, filepath.Join(DataPath, "log"))
- })
- Convey("Should get property map from command line args array", func() {
- props := getCommandLineProperties([]string{"cfg:test=value", "cfg:map.test=1"})
- So(len(props), ShouldEqual, 2)
- So(props["test"], ShouldEqual, "value")
- So(props["map.test"], ShouldEqual, "1")
- })
- Convey("Should be able to override via command line", func() {
- NewConfigContext(&CommandLineArgs{
- Args: []string{"cfg:paths.data=/tmp/data", "cfg:paths.logs=/tmp/logs"},
- })
- So(DataPath, ShouldEqual, "/tmp/data")
- So(LogsPath, ShouldEqual, "/tmp/logs")
- })
- Convey("Should be able to override defaults via command line", func() {
- NewConfigContext(&CommandLineArgs{
- Args: []string{
- "cfg:default.server.domain=test2",
- },
- Config: filepath.Join(HomePath, "tests/config-files/override.ini"),
- })
- So(Domain, ShouldEqual, "test2")
- })
- Convey("Defaults can be overriden in specified config file", func() {
- NewConfigContext(&CommandLineArgs{
- Args: []string{"cfg:default.paths.data=/tmp/data"},
- Config: filepath.Join(HomePath, "tests/config-files/override.ini"),
- })
- So(DataPath, ShouldEqual, "/tmp/override")
- })
- Convey("Command line overrides specified config file", func() {
- NewConfigContext(&CommandLineArgs{
- Args: []string{"cfg:paths.data=/tmp/data"},
- Config: filepath.Join(HomePath, "tests/config-files/override.ini"),
- })
- So(DataPath, ShouldEqual, "/tmp/data")
- })
- Convey("Can use environment variables in config values", func() {
- os.Setenv("GF_DATA_PATH", "/tmp/env_override")
- NewConfigContext(&CommandLineArgs{
- Args: []string{"cfg:paths.data=${GF_DATA_PATH}"},
- })
- So(DataPath, ShouldEqual, "/tmp/env_override")
- })
- })
- }
|