Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
qorus
prometheus
Commits
1c3e7b42
Commit
1c3e7b42
authored
Feb 05, 2021
by
misha
Browse files
Use strings.Builder for neater error formatting
Signed-off-by:
misha
<
DL-OTTCloudPlatform-Nova@bskyb.internal
>
parent
c2c5aeb1
Changes
2
Hide whitespace changes
Inline
Side-by-side
cmd/promtool/unittest.go
View file @
1c3e7b42
...
...
@@ -300,26 +300,29 @@ func (tg *testGroup) test(evalInterval time.Duration, groupOrderMap map[string]i
})
}
var
sb
strings
.
Builder
if
gotAlerts
.
Len
()
!=
expAlerts
.
Len
()
{
if
tg
.
TestGroupName
==
""
{
errs
=
append
(
errs
,
errors
.
Errorf
(
" alertname:%s, time:%s,
\n
exp:%#v,
\n
got:%#v"
,
testcase
.
Alertname
,
testcase
.
EvalTime
.
String
(),
expAlerts
.
String
(),
gotAlerts
.
String
()))
}
else
{
errs
=
append
(
errs
,
errors
.
Errorf
(
" name: %s,
\n
alertname:%s, time:%s,
\n
exp:%#v,
\n
got:%#v"
,
tg
.
TestGroupName
,
testcase
.
Alertname
,
testcase
.
EvalTime
.
String
(),
expAlerts
.
String
(),
gotAlerts
.
String
()))
if
tg
.
TestGroupName
!=
""
{
fmt
.
Fprintf
(
&
sb
,
" name: %s,
\n
"
,
tg
.
TestGroupName
)
}
fmt
.
Fprintf
(
&
sb
,
" alertname:%s, time:%s,
\n
"
,
testcase
.
Alertname
,
testcase
.
EvalTime
.
String
())
fmt
.
Fprintf
(
&
sb
,
" exp:%#v,
\n
"
,
expAlerts
.
String
())
fmt
.
Fprintf
(
&
sb
,
" got:%#v"
,
gotAlerts
.
String
())
errs
=
append
(
errs
,
errors
.
New
(
sb
.
String
()))
}
else
{
sort
.
Sort
(
gotAlerts
)
sort
.
Sort
(
expAlerts
)
if
!
reflect
.
DeepEqual
(
expAlerts
,
gotAlerts
)
{
if
tg
.
TestGroupName
==
""
{
errs
=
append
(
errs
,
errors
.
Errorf
(
" alertname:%s, time:%s,
\n
exp:%#v,
\n
got:%#v"
,
testcase
.
Alertname
,
testcase
.
EvalTime
.
String
(),
expAlerts
.
String
(),
gotAlerts
.
String
()))
}
else
{
errs
=
append
(
errs
,
errors
.
Errorf
(
" name: %s,
\n
alertname:%s, time:%s,
\n
exp:%#v,
\n
got:%#v"
,
tg
.
TestGroupName
,
testcase
.
Alertname
,
testcase
.
EvalTime
.
String
(),
expAlerts
.
String
(),
gotAlerts
.
String
()))
if
tg
.
TestGroupName
!=
""
{
fmt
.
Fprintf
(
&
sb
,
" name: %s,
\n
"
,
tg
.
TestGroupName
)
}
fmt
.
Fprintf
(
&
sb
,
" alertname:%s, time:%s,
\n
"
,
testcase
.
Alertname
,
testcase
.
EvalTime
.
String
())
fmt
.
Fprintf
(
&
sb
,
" exp:%#v,
\n
"
,
expAlerts
.
String
())
fmt
.
Fprintf
(
&
sb
,
" got:%#v"
,
gotAlerts
.
String
())
errs
=
append
(
errs
,
errors
.
New
(
sb
.
String
()))
}
}
}
...
...
docs/configuration/unit_testing_rules.md
View file @
1c3e7b42
...
...
@@ -44,6 +44,9 @@ interval: <duration>
input_series
:
[
- <series>
]
# Name of the test group
[
name
:
<string>
]
# Unit tests for the above data.
# Unit tests for alerting rules. We consider the alerting rules from the input file.
...
...
Write
Preview
Supports
Markdown
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