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
8e1196e3
Unverified
Commit
8e1196e3
authored
Jan 01, 2021
by
Emil Hessman
Committed by
GitHub
Jan 01, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Chore: Rewrite models alert test to standard library (#30021)
parent
18bc6810
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
49 deletions
+47
-49
pkg/models/alert_test.go
+47
-49
No files found.
pkg/models/alert_test.go
View file @
8e1196e3
...
@@ -4,61 +4,59 @@ import (
...
@@ -4,61 +4,59 @@ import (
"testing"
"testing"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/components/simplejson"
.
"github.com/smartystreets/goconvey/convey"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
)
func
TestAlertingModelTest
(
t
*
testing
.
T
)
{
func
TestAlert_ContainsUpdates
(
t
*
testing
.
T
)
{
Convey
(
"Testing Alerting model"
,
t
,
func
()
{
settings
,
err
:=
simplejson
.
NewJson
([]
byte
(
`{ "field": "value" }`
))
json1
,
err
:=
simplejson
.
NewJson
([]
byte
(
`{ "field": "value" }`
))
require
.
NoError
(
t
,
err
)
So
(
err
,
ShouldBeNil
)
json2
,
err
:=
simplejson
.
NewJson
([]
byte
(
`{ "field": "value" }`
))
So
(
err
,
ShouldBeNil
)
rule
1
:=
&
Alert
{
alert
1
:=
&
Alert
{
Settings
:
json1
,
Settings
:
settings
,
Name
:
"Namn
"
,
Name
:
"Name
"
,
Message
:
"Message"
,
Message
:
"Message"
,
}
}
rule
2
:=
&
Alert
{
alert
2
:=
&
Alert
{
Settings
:
json2
,
Settings
:
settings
,
Name
:
"Namn
"
,
Name
:
"Name
"
,
Message
:
"Message"
,
Message
:
"Message"
,
}
}
Convey
(
"Testing AlertRule equals"
,
func
()
{
assert
.
False
(
t
,
alert1
.
ContainsUpdates
(
alert2
))
So
(
rule1
.
ContainsUpdates
(
rule2
),
ShouldBeFalse
)
})
Convey
(
"Changing the expression should contain update"
,
func
()
{
settingsUpdated
,
err
:=
simplejson
.
NewJson
([]
byte
(
`{ "field": "newValue" }`
))
json2
,
err
:=
simplejson
.
NewJson
([]
byte
(
`{ "field": "newValue" }`
))
require
.
NoError
(
t
,
err
)
So
(
err
,
ShouldBeNil
)
rule1
.
Settings
=
json2
So
(
rule1
.
ContainsUpdates
(
rule2
),
ShouldBeTrue
)
})
Convey
(
"Should parse alertRule tags correctly"
,
func
()
{
alert2
.
Settings
=
settingsUpdated
json2
,
err
:=
simplejson
.
NewJson
([]
byte
(
`{
"field": "value",
"alertRuleTags": {
"foo": "bar",
"waldo": "fred",
"tagMap": { "mapValue": "value" }
}
}`
))
So
(
err
,
ShouldBeNil
)
rule1
.
Settings
=
json2
expectedTags
:=
[]
*
Tag
{
{
Id
:
0
,
Key
:
"foo"
,
Value
:
"bar"
},
{
Id
:
0
,
Key
:
"waldo"
,
Value
:
"fred"
},
{
Id
:
0
,
Key
:
"tagMap"
,
Value
:
""
},
}
actualTags
:=
rule1
.
GetTagsFromSettings
()
So
(
len
(
actualTags
),
ShouldEqual
,
len
(
expectedTags
))
assert
.
True
(
t
,
alert1
.
ContainsUpdates
(
alert2
))
for
_
,
tag
:=
range
expectedTags
{
}
So
(
ContainsTag
(
actualTags
,
tag
),
ShouldBeTrue
)
}
func
TestAlert_GetTagsFromSettings
(
t
*
testing
.
T
)
{
})
settings
,
err
:=
simplejson
.
NewJson
([]
byte
(
`{
})
"field": "value",
"alertRuleTags": {
"foo": "bar",
"waldo": "fred",
"tagMap": { "mapValue": "value" }
}
}`
))
require
.
NoError
(
t
,
err
)
alert
:=
&
Alert
{
Settings
:
settings
,
Name
:
"Name"
,
Message
:
"Message"
,
}
expectedTags
:=
[]
*
Tag
{
{
Id
:
0
,
Key
:
"foo"
,
Value
:
"bar"
},
{
Id
:
0
,
Key
:
"waldo"
,
Value
:
"fred"
},
{
Id
:
0
,
Key
:
"tagMap"
,
Value
:
""
},
}
actualTags
:=
alert
.
GetTagsFromSettings
()
assert
.
ElementsMatch
(
t
,
actualTags
,
expectedTags
)
}
}
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