2015-02-12 04:55:55 -06:00
|
|
|
package setting
|
|
|
|
|
|
|
|
import (
|
2015-02-12 06:31:41 -06:00
|
|
|
"os"
|
2015-02-12 04:55:55 -06:00
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestLoadingSettings(t *testing.T) {
|
|
|
|
|
|
|
|
Convey("Testing loading settings from ini file", t, func() {
|
|
|
|
|
|
|
|
Convey("Given the default ini files", func() {
|
2015-04-12 02:15:49 -05:00
|
|
|
NewConfigContext(&CommandLineArgs{HomePath: "../../"})
|
2015-02-12 04:55:55 -06:00
|
|
|
|
|
|
|
So(AppName, ShouldEqual, "Grafana")
|
2015-02-12 06:31:41 -06:00
|
|
|
So(AdminUser, ShouldEqual, "admin")
|
2015-02-12 04:55:55 -06:00
|
|
|
})
|
2015-02-12 06:31:41 -06:00
|
|
|
|
|
|
|
Convey("Should be able to override via environment variables", func() {
|
|
|
|
os.Setenv("GF_SECURITY_ADMIN_USER", "superduper")
|
2015-04-12 02:15:49 -05:00
|
|
|
NewConfigContext(&CommandLineArgs{HomePath: "../../"})
|
2015-02-12 06:31:41 -06:00
|
|
|
|
|
|
|
So(AdminUser, ShouldEqual, "superduper")
|
2015-04-09 05:16:59 -05:00
|
|
|
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{
|
2015-04-12 02:15:49 -05:00
|
|
|
HomePath: "../../",
|
|
|
|
Args: []string{"cfg:paths.data=/tmp/data", "cfg:paths.logs=/tmp/logs"},
|
2015-04-09 05:16:59 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
So(DataPath, ShouldEqual, "/tmp/data")
|
|
|
|
So(LogsPath, ShouldEqual, "/tmp/logs")
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Should be able to override defaults via command line", func() {
|
|
|
|
NewConfigContext(&CommandLineArgs{
|
2015-04-12 02:15:49 -05:00
|
|
|
HomePath: "../../",
|
2015-04-10 03:58:32 -05:00
|
|
|
Args: []string{
|
|
|
|
"cfg:default.server.domain=test2",
|
|
|
|
},
|
|
|
|
Config: filepath.Join(HomePath, "tests/config-files/override.ini"),
|
2015-04-09 05:16:59 -05:00
|
|
|
})
|
|
|
|
|
2015-04-10 03:58:32 -05:00
|
|
|
So(Domain, ShouldEqual, "test2")
|
2015-04-09 05:16:59 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Defaults can be overriden in specified config file", func() {
|
|
|
|
NewConfigContext(&CommandLineArgs{
|
2015-04-12 02:15:49 -05:00
|
|
|
HomePath: "../../",
|
|
|
|
Config: filepath.Join(HomePath, "tests/config-files/override.ini"),
|
|
|
|
Args: []string{"cfg:default.paths.data=/tmp/data"},
|
2015-04-09 05:16:59 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
So(DataPath, ShouldEqual, "/tmp/override")
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Command line overrides specified config file", func() {
|
|
|
|
NewConfigContext(&CommandLineArgs{
|
2015-04-12 02:15:49 -05:00
|
|
|
HomePath: "../../",
|
|
|
|
Config: filepath.Join(HomePath, "tests/config-files/override.ini"),
|
|
|
|
Args: []string{"cfg:paths.data=/tmp/data"},
|
2015-04-09 05:16:59 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
So(DataPath, ShouldEqual, "/tmp/data")
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Can use environment variables in config values", func() {
|
|
|
|
os.Setenv("GF_DATA_PATH", "/tmp/env_override")
|
|
|
|
NewConfigContext(&CommandLineArgs{
|
2015-04-12 02:15:49 -05:00
|
|
|
HomePath: "../../",
|
|
|
|
Args: []string{"cfg:paths.data=${GF_DATA_PATH}"},
|
2015-04-09 05:16:59 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
So(DataPath, ShouldEqual, "/tmp/env_override")
|
2015-02-12 06:31:41 -06:00
|
|
|
})
|
|
|
|
|
2015-02-12 04:55:55 -06:00
|
|
|
})
|
|
|
|
}
|