From 8973b48f96d7bf67178ff1aeb06e653fee61897e Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Mon, 19 Jun 2017 15:36:08 +0200 Subject: [PATCH] setting: add tests for windows --- .gitignore | 1 + pkg/setting/setting_test.go | 88 ++++++++++++++++++------- tests/config-files/override_windows.ini | 3 + 3 files changed, 68 insertions(+), 24 deletions(-) create mode 100644 tests/config-files/override_windows.ini diff --git a/.gitignore b/.gitignore index 5d3c506ca7a..08cfb7a2931 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ awsconfig /public/vendor/npm /tmp vendor/phantomjs/phantomjs +vendor/phantomjs/phantomjs.exe docs/AWS_S3_BUCKET docs/GIT_BRANCH diff --git a/pkg/setting/setting_test.go b/pkg/setting/setting_test.go index b213c2795af..640a1648340 100644 --- a/pkg/setting/setting_test.go +++ b/pkg/setting/setting_test.go @@ -3,6 +3,7 @@ package setting import ( "os" "path/filepath" + "runtime" "testing" . "github.com/smartystreets/goconvey/convey" @@ -52,13 +53,22 @@ func TestLoadingSettings(t *testing.T) { }) Convey("Should be able to override via command line", func() { - NewConfigContext(&CommandLineArgs{ - HomePath: "../../", - Args: []string{"cfg:paths.data=/tmp/data", "cfg:paths.logs=/tmp/logs"}, - }) + if runtime.GOOS == "windows" { + NewConfigContext(&CommandLineArgs{ + 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(LogsPath, ShouldEqual, "/tmp/logs") + So(DataPath, ShouldEqual, "/tmp/data") + So(LogsPath, ShouldEqual, "/tmp/logs") + } }) 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() { - NewConfigContext(&CommandLineArgs{ - HomePath: "../../", - Config: filepath.Join(HomePath, "tests/config-files/override.ini"), - Args: []string{"cfg:default.paths.data=/tmp/data"}, - }) + if runtime.GOOS == "windows" { + NewConfigContext(&CommandLineArgs{ + HomePath: "../../", + 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() { - NewConfigContext(&CommandLineArgs{ - HomePath: "../../", - Config: filepath.Join(HomePath, "tests/config-files/override.ini"), - Args: []string{"cfg:paths.data=/tmp/data"}, - }) + if runtime.GOOS == "windows" { + NewConfigContext(&CommandLineArgs{ + HomePath: "../../", + 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() { - os.Setenv("GF_DATA_PATH", "/tmp/env_override") - NewConfigContext(&CommandLineArgs{ - HomePath: "../../", - Args: []string{"cfg:paths.data=${GF_DATA_PATH}"}, - }) + if runtime.GOOS == "windows" { + os.Setenv("GF_DATA_PATH", `c:\tmp\env_override`) + NewConfigContext(&CommandLineArgs{ + 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() { diff --git a/tests/config-files/override_windows.ini b/tests/config-files/override_windows.ini new file mode 100644 index 00000000000..c0219afc8c8 --- /dev/null +++ b/tests/config-files/override_windows.ini @@ -0,0 +1,3 @@ +[paths] +data = c:\tmp\override +