Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
8ba55096
Unverified
Commit
8ba55096
authored
Oct 22, 2019
by
Arve Knudsen
Committed by
GitHub
Oct 22, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pkg/setting: Check errors (#19838)
Check errors in pkg/setting.
parent
bb50fc59
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
15 deletions
+30
-15
pkg/setting/setting_session_test.go
+2
-1
pkg/setting/setting_test.go
+28
-14
No files found.
pkg/setting/setting_session_test.go
View file @
8ba55096
...
@@ -31,10 +31,11 @@ func TestSessionSettings(t *testing.T) {
...
@@ -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
)
...
...
pkg/setting/setting_test.go
View file @
8ba55096
...
@@ -52,7 +52,8 @@ func TestLoadingSettings(t *testing.T) {
...
@@ -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) {
...
@@ -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) {
...
@@ -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) {
...
@@ -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) {
...
@@ -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) {
...
@@ -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) {
...
@@ -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) {
...
@@ -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) {
...
@@ -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) {
...
@@ -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/"
)
})
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment