mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
parent
bb50fc5965
commit
8ba5509614
@ -31,10 +31,11 @@ func TestSessionSettings(t *testing.T) {
|
|||||||
stub := &testLogger{}
|
stub := &testLogger{}
|
||||||
cfg.Logger = stub
|
cfg.Logger = stub
|
||||||
|
|
||||||
cfg.Load(&CommandLineArgs{
|
err := cfg.Load(&CommandLineArgs{
|
||||||
HomePath: homePath,
|
HomePath: homePath,
|
||||||
Config: filepath.Join(homePath, "pkg/setting/testdata/session.ini"),
|
Config: filepath.Join(homePath, "pkg/setting/testdata/session.ini"),
|
||||||
})
|
})
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
So(stub.warnCalled, ShouldEqual, true)
|
So(stub.warnCalled, ShouldEqual, true)
|
||||||
So(len(stub.warnMessage), ShouldBeGreaterThan, 0)
|
So(len(stub.warnMessage), ShouldBeGreaterThan, 0)
|
||||||
|
@ -52,7 +52,8 @@ func TestLoadingSettings(t *testing.T) {
|
|||||||
os.Setenv("GF_SECURITY_ADMIN_USER", "superduper")
|
os.Setenv("GF_SECURITY_ADMIN_USER", "superduper")
|
||||||
|
|
||||||
cfg := NewCfg()
|
cfg := NewCfg()
|
||||||
cfg.Load(&CommandLineArgs{HomePath: "../../"})
|
err := cfg.Load(&CommandLineArgs{HomePath: "../../"})
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
So(AdminUser, ShouldEqual, "superduper")
|
So(AdminUser, ShouldEqual, "superduper")
|
||||||
So(cfg.DataPath, ShouldEqual, filepath.Join(HomePath, "data"))
|
So(cfg.DataPath, ShouldEqual, filepath.Join(HomePath, "data"))
|
||||||
@ -63,7 +64,8 @@ func TestLoadingSettings(t *testing.T) {
|
|||||||
os.Setenv("GF_SECURITY_ADMIN_PASSWORD", "supersecret")
|
os.Setenv("GF_SECURITY_ADMIN_PASSWORD", "supersecret")
|
||||||
|
|
||||||
cfg := NewCfg()
|
cfg := NewCfg()
|
||||||
cfg.Load(&CommandLineArgs{HomePath: "../../"})
|
err := cfg.Load(&CommandLineArgs{HomePath: "../../"})
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
So(appliedEnvOverrides, ShouldContain, "GF_SECURITY_ADMIN_PASSWORD=*********")
|
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")
|
os.Setenv("GF_DATABASE_URL", "mysql://user:secret@localhost:3306/database")
|
||||||
|
|
||||||
cfg := NewCfg()
|
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")
|
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() {
|
Convey("Should be able to override via command line", func() {
|
||||||
if runtime.GOOS == windows {
|
if runtime.GOOS == windows {
|
||||||
cfg := NewCfg()
|
cfg := NewCfg()
|
||||||
cfg.Load(&CommandLineArgs{
|
err := cfg.Load(&CommandLineArgs{
|
||||||
HomePath: "../../",
|
HomePath: "../../",
|
||||||
Args: []string{`cfg:paths.data=c:\tmp\data`, `cfg:paths.logs=c:\tmp\logs`},
|
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.DataPath, ShouldEqual, `c:\tmp\data`)
|
||||||
So(cfg.LogsPath, ShouldEqual, `c:\tmp\logs`)
|
So(cfg.LogsPath, ShouldEqual, `c:\tmp\logs`)
|
||||||
} else {
|
} else {
|
||||||
cfg := NewCfg()
|
cfg := NewCfg()
|
||||||
cfg.Load(&CommandLineArgs{
|
err := cfg.Load(&CommandLineArgs{
|
||||||
HomePath: "../../",
|
HomePath: "../../",
|
||||||
Args: []string{"cfg:paths.data=/tmp/data", "cfg:paths.logs=/tmp/logs"},
|
Args: []string{"cfg:paths.data=/tmp/data", "cfg:paths.logs=/tmp/logs"},
|
||||||
})
|
})
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
So(cfg.DataPath, ShouldEqual, "/tmp/data")
|
So(cfg.DataPath, ShouldEqual, "/tmp/data")
|
||||||
So(cfg.LogsPath, ShouldEqual, "/tmp/logs")
|
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() {
|
Convey("Should be able to override defaults via command line", func() {
|
||||||
cfg := NewCfg()
|
cfg := NewCfg()
|
||||||
cfg.Load(&CommandLineArgs{
|
err := cfg.Load(&CommandLineArgs{
|
||||||
HomePath: "../../",
|
HomePath: "../../",
|
||||||
Args: []string{
|
Args: []string{
|
||||||
"cfg:default.server.domain=test2",
|
"cfg:default.server.domain=test2",
|
||||||
},
|
},
|
||||||
Config: filepath.Join(HomePath, "pkg/setting/testdata/override.ini"),
|
Config: filepath.Join(HomePath, "pkg/setting/testdata/override.ini"),
|
||||||
})
|
})
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
So(Domain, ShouldEqual, "test2")
|
So(Domain, ShouldEqual, "test2")
|
||||||
})
|
})
|
||||||
@ -131,20 +137,22 @@ 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() {
|
||||||
if runtime.GOOS == windows {
|
if runtime.GOOS == windows {
|
||||||
cfg := NewCfg()
|
cfg := NewCfg()
|
||||||
cfg.Load(&CommandLineArgs{
|
err := cfg.Load(&CommandLineArgs{
|
||||||
HomePath: "../../",
|
HomePath: "../../",
|
||||||
Config: filepath.Join(HomePath, "pkg/setting/testdata/override_windows.ini"),
|
Config: filepath.Join(HomePath, "pkg/setting/testdata/override_windows.ini"),
|
||||||
Args: []string{`cfg:default.paths.data=c:\tmp\data`},
|
Args: []string{`cfg:default.paths.data=c:\tmp\data`},
|
||||||
})
|
})
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
So(cfg.DataPath, ShouldEqual, `c:\tmp\override`)
|
So(cfg.DataPath, ShouldEqual, `c:\tmp\override`)
|
||||||
} else {
|
} else {
|
||||||
cfg := NewCfg()
|
cfg := NewCfg()
|
||||||
cfg.Load(&CommandLineArgs{
|
err := cfg.Load(&CommandLineArgs{
|
||||||
HomePath: "../../",
|
HomePath: "../../",
|
||||||
Config: filepath.Join(HomePath, "pkg/setting/testdata/override.ini"),
|
Config: filepath.Join(HomePath, "pkg/setting/testdata/override.ini"),
|
||||||
Args: []string{"cfg:default.paths.data=/tmp/data"},
|
Args: []string{"cfg:default.paths.data=/tmp/data"},
|
||||||
})
|
})
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
So(cfg.DataPath, ShouldEqual, "/tmp/override")
|
So(cfg.DataPath, ShouldEqual, "/tmp/override")
|
||||||
}
|
}
|
||||||
@ -153,20 +161,22 @@ func TestLoadingSettings(t *testing.T) {
|
|||||||
Convey("Command line overrides specified config file", func() {
|
Convey("Command line overrides specified config file", func() {
|
||||||
if runtime.GOOS == windows {
|
if runtime.GOOS == windows {
|
||||||
cfg := NewCfg()
|
cfg := NewCfg()
|
||||||
cfg.Load(&CommandLineArgs{
|
err := cfg.Load(&CommandLineArgs{
|
||||||
HomePath: "../../",
|
HomePath: "../../",
|
||||||
Config: filepath.Join(HomePath, "pkg/setting/testdata/override_windows.ini"),
|
Config: filepath.Join(HomePath, "pkg/setting/testdata/override_windows.ini"),
|
||||||
Args: []string{`cfg:paths.data=c:\tmp\data`},
|
Args: []string{`cfg:paths.data=c:\tmp\data`},
|
||||||
})
|
})
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
So(cfg.DataPath, ShouldEqual, `c:\tmp\data`)
|
So(cfg.DataPath, ShouldEqual, `c:\tmp\data`)
|
||||||
} else {
|
} else {
|
||||||
cfg := NewCfg()
|
cfg := NewCfg()
|
||||||
cfg.Load(&CommandLineArgs{
|
err := cfg.Load(&CommandLineArgs{
|
||||||
HomePath: "../../",
|
HomePath: "../../",
|
||||||
Config: filepath.Join(HomePath, "pkg/setting/testdata/override.ini"),
|
Config: filepath.Join(HomePath, "pkg/setting/testdata/override.ini"),
|
||||||
Args: []string{"cfg:paths.data=/tmp/data"},
|
Args: []string{"cfg:paths.data=/tmp/data"},
|
||||||
})
|
})
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
So(cfg.DataPath, ShouldEqual, "/tmp/data")
|
So(cfg.DataPath, ShouldEqual, "/tmp/data")
|
||||||
}
|
}
|
||||||
@ -176,19 +186,21 @@ func TestLoadingSettings(t *testing.T) {
|
|||||||
if runtime.GOOS == windows {
|
if runtime.GOOS == windows {
|
||||||
os.Setenv("GF_DATA_PATH", `c:\tmp\env_override`)
|
os.Setenv("GF_DATA_PATH", `c:\tmp\env_override`)
|
||||||
cfg := NewCfg()
|
cfg := NewCfg()
|
||||||
cfg.Load(&CommandLineArgs{
|
err := cfg.Load(&CommandLineArgs{
|
||||||
HomePath: "../../",
|
HomePath: "../../",
|
||||||
Args: []string{"cfg:paths.data=${GF_DATA_PATH}"},
|
Args: []string{"cfg:paths.data=${GF_DATA_PATH}"},
|
||||||
})
|
})
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
So(cfg.DataPath, ShouldEqual, `c:\tmp\env_override`)
|
So(cfg.DataPath, ShouldEqual, `c:\tmp\env_override`)
|
||||||
} else {
|
} else {
|
||||||
os.Setenv("GF_DATA_PATH", "/tmp/env_override")
|
os.Setenv("GF_DATA_PATH", "/tmp/env_override")
|
||||||
cfg := NewCfg()
|
cfg := NewCfg()
|
||||||
cfg.Load(&CommandLineArgs{
|
err := cfg.Load(&CommandLineArgs{
|
||||||
HomePath: "../../",
|
HomePath: "../../",
|
||||||
Args: []string{"cfg:paths.data=${GF_DATA_PATH}"},
|
Args: []string{"cfg:paths.data=${GF_DATA_PATH}"},
|
||||||
})
|
})
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
So(cfg.DataPath, ShouldEqual, "/tmp/env_override")
|
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() {
|
Convey("instance_name default to hostname even if hostname env is empty", func() {
|
||||||
cfg := NewCfg()
|
cfg := NewCfg()
|
||||||
cfg.Load(&CommandLineArgs{
|
err := cfg.Load(&CommandLineArgs{
|
||||||
HomePath: "../../",
|
HomePath: "../../",
|
||||||
})
|
})
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
hostname, _ := os.Hostname()
|
hostname, _ := os.Hostname()
|
||||||
So(InstanceName, ShouldEqual, hostname)
|
So(InstanceName, ShouldEqual, hostname)
|
||||||
@ -206,10 +219,11 @@ func TestLoadingSettings(t *testing.T) {
|
|||||||
|
|
||||||
Convey("Reading callback_url should add trailing slash", func() {
|
Convey("Reading callback_url should add trailing slash", func() {
|
||||||
cfg := NewCfg()
|
cfg := NewCfg()
|
||||||
cfg.Load(&CommandLineArgs{
|
err := cfg.Load(&CommandLineArgs{
|
||||||
HomePath: "../../",
|
HomePath: "../../",
|
||||||
Args: []string{"cfg:rendering.callback_url=http://myserver/renderer"},
|
Args: []string{"cfg:rendering.callback_url=http://myserver/renderer"},
|
||||||
})
|
})
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
So(cfg.RendererCallbackUrl, ShouldEqual, "http://myserver/renderer/")
|
So(cfg.RendererCallbackUrl, ShouldEqual, "http://myserver/renderer/")
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user