mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 03:31:50 +08:00
setting: add tests for windows
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -9,6 +9,7 @@ awsconfig
|
|||||||
/public/vendor/npm
|
/public/vendor/npm
|
||||||
/tmp
|
/tmp
|
||||||
vendor/phantomjs/phantomjs
|
vendor/phantomjs/phantomjs
|
||||||
|
vendor/phantomjs/phantomjs.exe
|
||||||
|
|
||||||
docs/AWS_S3_BUCKET
|
docs/AWS_S3_BUCKET
|
||||||
docs/GIT_BRANCH
|
docs/GIT_BRANCH
|
||||||
|
@ -3,6 +3,7 @@ package setting
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "github.com/smartystreets/goconvey/convey"
|
. "github.com/smartystreets/goconvey/convey"
|
||||||
@ -52,13 +53,22 @@ func TestLoadingSettings(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Convey("Should be able to override via command line", func() {
|
Convey("Should be able to override via command line", func() {
|
||||||
NewConfigContext(&CommandLineArgs{
|
if runtime.GOOS == "windows" {
|
||||||
HomePath: "../../",
|
NewConfigContext(&CommandLineArgs{
|
||||||
Args: []string{"cfg:paths.data=/tmp/data", "cfg:paths.logs=/tmp/logs"},
|
HomePath: "../../",
|
||||||
})
|
Args: []string{`cfg:paths.data=c:\tmp\data`, `cfg:paths.logs=c:\tmp\logs`},
|
||||||
|
})
|
||||||
|
So(DataPath, ShouldEqual, `c:\tmp\data`)
|
||||||
|
So(LogsPath, ShouldEqual, `c:\tmp\logs`)
|
||||||
|
} else {
|
||||||
|
NewConfigContext(&CommandLineArgs{
|
||||||
|
HomePath: "../../",
|
||||||
|
Args: []string{"cfg:paths.data=/tmp/data", "cfg:paths.logs=/tmp/logs"},
|
||||||
|
})
|
||||||
|
|
||||||
So(DataPath, ShouldEqual, "/tmp/data")
|
So(DataPath, ShouldEqual, "/tmp/data")
|
||||||
So(LogsPath, ShouldEqual, "/tmp/logs")
|
So(LogsPath, ShouldEqual, "/tmp/logs")
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("Should be able to override defaults via command line", func() {
|
Convey("Should be able to override defaults via command line", func() {
|
||||||
@ -74,33 +84,63 @@ func TestLoadingSettings(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
Convey("Defaults can be overridden in specified config file", func() {
|
Convey("Defaults can be overridden in specified config file", func() {
|
||||||
NewConfigContext(&CommandLineArgs{
|
if runtime.GOOS == "windows" {
|
||||||
HomePath: "../../",
|
NewConfigContext(&CommandLineArgs{
|
||||||
Config: filepath.Join(HomePath, "tests/config-files/override.ini"),
|
HomePath: "../../",
|
||||||
Args: []string{"cfg:default.paths.data=/tmp/data"},
|
Config: filepath.Join(HomePath, "tests/config-files/override_windows.ini"),
|
||||||
})
|
Args: []string{`cfg:default.paths.data=c:\tmp\data`},
|
||||||
|
})
|
||||||
|
|
||||||
So(DataPath, ShouldEqual, "/tmp/override")
|
So(DataPath, ShouldEqual, `c:\tmp\override`)
|
||||||
|
} else {
|
||||||
|
NewConfigContext(&CommandLineArgs{
|
||||||
|
HomePath: "../../",
|
||||||
|
Config: filepath.Join(HomePath, "tests/config-files/override.ini"),
|
||||||
|
Args: []string{"cfg:default.paths.data=/tmp/data"},
|
||||||
|
})
|
||||||
|
|
||||||
|
So(DataPath, ShouldEqual, "/tmp/override")
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("Command line overrides specified config file", func() {
|
Convey("Command line overrides specified config file", func() {
|
||||||
NewConfigContext(&CommandLineArgs{
|
if runtime.GOOS == "windows" {
|
||||||
HomePath: "../../",
|
NewConfigContext(&CommandLineArgs{
|
||||||
Config: filepath.Join(HomePath, "tests/config-files/override.ini"),
|
HomePath: "../../",
|
||||||
Args: []string{"cfg:paths.data=/tmp/data"},
|
Config: filepath.Join(HomePath, "tests/config-files/override_windows.ini"),
|
||||||
})
|
Args: []string{`cfg:paths.data=c:\tmp\data`},
|
||||||
|
})
|
||||||
|
|
||||||
So(DataPath, ShouldEqual, "/tmp/data")
|
So(DataPath, ShouldEqual, `c:\tmp\data`)
|
||||||
|
} else {
|
||||||
|
NewConfigContext(&CommandLineArgs{
|
||||||
|
HomePath: "../../",
|
||||||
|
Config: filepath.Join(HomePath, "tests/config-files/override.ini"),
|
||||||
|
Args: []string{"cfg:paths.data=/tmp/data"},
|
||||||
|
})
|
||||||
|
|
||||||
|
So(DataPath, ShouldEqual, "/tmp/data")
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("Can use environment variables in config values", func() {
|
Convey("Can use environment variables in config values", func() {
|
||||||
os.Setenv("GF_DATA_PATH", "/tmp/env_override")
|
if runtime.GOOS == "windows" {
|
||||||
NewConfigContext(&CommandLineArgs{
|
os.Setenv("GF_DATA_PATH", `c:\tmp\env_override`)
|
||||||
HomePath: "../../",
|
NewConfigContext(&CommandLineArgs{
|
||||||
Args: []string{"cfg:paths.data=${GF_DATA_PATH}"},
|
HomePath: "../../",
|
||||||
})
|
Args: []string{"cfg:paths.data=${GF_DATA_PATH}"},
|
||||||
|
})
|
||||||
|
|
||||||
So(DataPath, ShouldEqual, "/tmp/env_override")
|
So(DataPath, ShouldEqual, `c:\tmp\env_override`)
|
||||||
|
} else {
|
||||||
|
os.Setenv("GF_DATA_PATH", "/tmp/env_override")
|
||||||
|
NewConfigContext(&CommandLineArgs{
|
||||||
|
HomePath: "../../",
|
||||||
|
Args: []string{"cfg:paths.data=${GF_DATA_PATH}"},
|
||||||
|
})
|
||||||
|
|
||||||
|
So(DataPath, ShouldEqual, "/tmp/env_override")
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("instance_name default to hostname even if hostname env is empty", func() {
|
Convey("instance_name default to hostname even if hostname env is empty", func() {
|
||||||
|
3
tests/config-files/override_windows.ini
Normal file
3
tests/config-files/override_windows.ini
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[paths]
|
||||||
|
data = c:\tmp\override
|
||||||
|
|
Reference in New Issue
Block a user