Commit 8ba55096 by Arve Knudsen Committed by GitHub

pkg/setting: Check errors (#19838)

Check errors in pkg/setting.
parent bb50fc59
......@@ -31,10 +31,11 @@ func TestSessionSettings(t *testing.T) {
stub := &testLogger{}
cfg.Logger = stub
cfg.Load(&CommandLineArgs{
err := cfg.Load(&CommandLineArgs{
HomePath: homePath,
Config: filepath.Join(homePath, "pkg/setting/testdata/session.ini"),
})
So(err, ShouldBeNil)
So(stub.warnCalled, ShouldEqual, true)
So(len(stub.warnMessage), ShouldBeGreaterThan, 0)
......
......@@ -52,7 +52,8 @@ func TestLoadingSettings(t *testing.T) {
os.Setenv("GF_SECURITY_ADMIN_USER", "superduper")
cfg := NewCfg()
cfg.Load(&CommandLineArgs{HomePath: "../../"})
err := cfg.Load(&CommandLineArgs{HomePath: "../../"})
So(err, ShouldBeNil)
So(AdminUser, ShouldEqual, "superduper")
So(cfg.DataPath, ShouldEqual, filepath.Join(HomePath, "data"))
......@@ -63,7 +64,8 @@ func TestLoadingSettings(t *testing.T) {
os.Setenv("GF_SECURITY_ADMIN_PASSWORD", "supersecret")
cfg := NewCfg()
cfg.Load(&CommandLineArgs{HomePath: "../../"})
err := cfg.Load(&CommandLineArgs{HomePath: "../../"})
So(err, ShouldBeNil)
So(appliedEnvOverrides, ShouldContain, "GF_SECURITY_ADMIN_PASSWORD=*********")
})
......@@ -81,7 +83,8 @@ func TestLoadingSettings(t *testing.T) {
os.Setenv("GF_DATABASE_URL", "mysql://user:secret@localhost:3306/database")
cfg := NewCfg()
cfg.Load(&CommandLineArgs{HomePath: "../../"})
err := cfg.Load(&CommandLineArgs{HomePath: "../../"})
So(err, ShouldBeNil)
So(appliedEnvOverrides, ShouldContain, "GF_DATABASE_URL=mysql://user:-redacted-@localhost:3306/database")
})
......@@ -97,18 +100,20 @@ func TestLoadingSettings(t *testing.T) {
Convey("Should be able to override via command line", func() {
if runtime.GOOS == windows {
cfg := NewCfg()
cfg.Load(&CommandLineArgs{
err := cfg.Load(&CommandLineArgs{
HomePath: "../../",
Args: []string{`cfg:paths.data=c:\tmp\data`, `cfg:paths.logs=c:\tmp\logs`},
})
So(err, ShouldBeNil)
So(cfg.DataPath, ShouldEqual, `c:\tmp\data`)
So(cfg.LogsPath, ShouldEqual, `c:\tmp\logs`)
} else {
cfg := NewCfg()
cfg.Load(&CommandLineArgs{
err := cfg.Load(&CommandLineArgs{
HomePath: "../../",
Args: []string{"cfg:paths.data=/tmp/data", "cfg:paths.logs=/tmp/logs"},
})
So(err, ShouldBeNil)
So(cfg.DataPath, ShouldEqual, "/tmp/data")
So(cfg.LogsPath, ShouldEqual, "/tmp/logs")
......@@ -117,13 +122,14 @@ func TestLoadingSettings(t *testing.T) {
Convey("Should be able to override defaults via command line", func() {
cfg := NewCfg()
cfg.Load(&CommandLineArgs{
err := cfg.Load(&CommandLineArgs{
HomePath: "../../",
Args: []string{
"cfg:default.server.domain=test2",
},
Config: filepath.Join(HomePath, "pkg/setting/testdata/override.ini"),
})
So(err, ShouldBeNil)
So(Domain, ShouldEqual, "test2")
})
......@@ -131,20 +137,22 @@ func TestLoadingSettings(t *testing.T) {
Convey("Defaults can be overridden in specified config file", func() {
if runtime.GOOS == windows {
cfg := NewCfg()
cfg.Load(&CommandLineArgs{
err := cfg.Load(&CommandLineArgs{
HomePath: "../../",
Config: filepath.Join(HomePath, "pkg/setting/testdata/override_windows.ini"),
Args: []string{`cfg:default.paths.data=c:\tmp\data`},
})
So(err, ShouldBeNil)
So(cfg.DataPath, ShouldEqual, `c:\tmp\override`)
} else {
cfg := NewCfg()
cfg.Load(&CommandLineArgs{
err := cfg.Load(&CommandLineArgs{
HomePath: "../../",
Config: filepath.Join(HomePath, "pkg/setting/testdata/override.ini"),
Args: []string{"cfg:default.paths.data=/tmp/data"},
})
So(err, ShouldBeNil)
So(cfg.DataPath, ShouldEqual, "/tmp/override")
}
......@@ -153,20 +161,22 @@ func TestLoadingSettings(t *testing.T) {
Convey("Command line overrides specified config file", func() {
if runtime.GOOS == windows {
cfg := NewCfg()
cfg.Load(&CommandLineArgs{
err := cfg.Load(&CommandLineArgs{
HomePath: "../../",
Config: filepath.Join(HomePath, "pkg/setting/testdata/override_windows.ini"),
Args: []string{`cfg:paths.data=c:\tmp\data`},
})
So(err, ShouldBeNil)
So(cfg.DataPath, ShouldEqual, `c:\tmp\data`)
} else {
cfg := NewCfg()
cfg.Load(&CommandLineArgs{
err := cfg.Load(&CommandLineArgs{
HomePath: "../../",
Config: filepath.Join(HomePath, "pkg/setting/testdata/override.ini"),
Args: []string{"cfg:paths.data=/tmp/data"},
})
So(err, ShouldBeNil)
So(cfg.DataPath, ShouldEqual, "/tmp/data")
}
......@@ -176,19 +186,21 @@ func TestLoadingSettings(t *testing.T) {
if runtime.GOOS == windows {
os.Setenv("GF_DATA_PATH", `c:\tmp\env_override`)
cfg := NewCfg()
cfg.Load(&CommandLineArgs{
err := cfg.Load(&CommandLineArgs{
HomePath: "../../",
Args: []string{"cfg:paths.data=${GF_DATA_PATH}"},
})
So(err, ShouldBeNil)
So(cfg.DataPath, ShouldEqual, `c:\tmp\env_override`)
} else {
os.Setenv("GF_DATA_PATH", "/tmp/env_override")
cfg := NewCfg()
cfg.Load(&CommandLineArgs{
err := cfg.Load(&CommandLineArgs{
HomePath: "../../",
Args: []string{"cfg:paths.data=${GF_DATA_PATH}"},
})
So(err, ShouldBeNil)
So(cfg.DataPath, ShouldEqual, "/tmp/env_override")
}
......@@ -196,9 +208,10 @@ func TestLoadingSettings(t *testing.T) {
Convey("instance_name default to hostname even if hostname env is empty", func() {
cfg := NewCfg()
cfg.Load(&CommandLineArgs{
err := cfg.Load(&CommandLineArgs{
HomePath: "../../",
})
So(err, ShouldBeNil)
hostname, _ := os.Hostname()
So(InstanceName, ShouldEqual, hostname)
......@@ -206,10 +219,11 @@ func TestLoadingSettings(t *testing.T) {
Convey("Reading callback_url should add trailing slash", func() {
cfg := NewCfg()
cfg.Load(&CommandLineArgs{
err := cfg.Load(&CommandLineArgs{
HomePath: "../../",
Args: []string{"cfg:rendering.callback_url=http://myserver/renderer"},
})
So(err, ShouldBeNil)
So(cfg.RendererCallbackUrl, ShouldEqual, "http://myserver/renderer/")
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment