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
69ac69b7
Unverified
Commit
69ac69b7
authored
Dec 03, 2020
by
Emil Hessman
Committed by
GitHub
Dec 03, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Chore: Rewrite tsdb testdatasource scenarios test to standard library (#29591)
Signed-off-by: Emil Hessman <emil@hessman.se>
parent
10539896
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
28 deletions
+24
-28
pkg/tsdb/testdatasource/scenarios_test.go
+24
-28
No files found.
pkg/tsdb/testdatasource/scenarios_test.go
View file @
69ac69b7
...
...
@@ -6,14 +6,14 @@ import (
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/tsdb"
.
"github.com/smartystreets/goconvey/convey
"
"github.com/stretchr/testify/require
"
)
func
TestTestdataScenarios
(
t
*
testing
.
T
)
{
Convey
(
"random walk "
,
t
,
func
(
)
{
t
.
Run
(
"random walk "
,
func
(
t
*
testing
.
T
)
{
scenario
:=
ScenarioRegistry
[
"random_walk"
]
Convey
(
"Should start at the requested value"
,
func
(
)
{
t
.
Run
(
"Should start at the requested value"
,
func
(
t
*
testing
.
T
)
{
req
:=
&
tsdb
.
TsdbQuery
{
TimeRange
:
tsdb
.
NewFakeTimeRange
(
"5m"
,
"now"
,
time
.
Now
()),
Queries
:
[]
*
tsdb
.
Query
{
...
...
@@ -24,17 +24,17 @@ func TestTestdataScenarios(t *testing.T) {
query
.
Model
.
Set
(
"startValue"
,
1.234
)
result
:=
scenario
.
Handler
(
req
.
Queries
[
0
],
req
)
points
:=
result
.
Series
[
0
]
.
Points
require
.
NotNil
(
t
,
result
.
Series
)
So
(
result
.
Series
,
ShouldNotBeNil
)
So
(
points
[
0
][
0
]
.
Float64
,
ShouldEqual
,
1.23
4
)
points
:=
result
.
Series
[
0
]
.
Points
require
.
Equal
(
t
,
1.234
,
points
[
0
][
0
]
.
Float6
4
)
})
})
Convey
(
"random walk table"
,
t
,
func
(
)
{
t
.
Run
(
"random walk table"
,
func
(
t
*
testing
.
T
)
{
scenario
:=
ScenarioRegistry
[
"random_walk_table"
]
Convey
(
"Should return a table that looks like value/min/max"
,
func
(
)
{
t
.
Run
(
"Should return a table that looks like value/min/max"
,
func
(
t
*
testing
.
T
)
{
req
:=
&
tsdb
.
TsdbQuery
{
TimeRange
:
tsdb
.
NewFakeTimeRange
(
"5m"
,
"now"
,
time
.
Now
()),
Queries
:
[]
*
tsdb
.
Query
{
...
...
@@ -45,18 +45,18 @@ func TestTestdataScenarios(t *testing.T) {
result
:=
scenario
.
Handler
(
req
.
Queries
[
0
],
req
)
table
:=
result
.
Tables
[
0
]
So
(
len
(
table
.
Rows
),
ShouldBeGreaterThan
,
50
)
require
.
Greater
(
t
,
len
(
table
.
Rows
)
,
50
)
for
_
,
row
:=
range
table
.
Rows
{
value
:=
row
[
1
]
min
:=
row
[
2
]
max
:=
row
[
3
]
So
(
min
,
ShouldBeLessTha
n
,
value
)
So
(
max
,
ShouldBeGreaterThan
,
value
)
require
.
Less
(
t
,
mi
n
,
value
)
require
.
Greater
(
t
,
max
,
value
)
}
})
Convey
(
"Should return a table with some nil values"
,
func
(
)
{
t
.
Run
(
"Should return a table with some nil values"
,
func
(
t
*
testing
.
T
)
{
req
:=
&
tsdb
.
TsdbQuery
{
TimeRange
:
tsdb
.
NewFakeTimeRange
(
"5m"
,
"now"
,
time
.
Now
()),
Queries
:
[]
*
tsdb
.
Query
{
...
...
@@ -73,7 +73,7 @@ func TestTestdataScenarios(t *testing.T) {
nil2
:=
false
nil3
:=
false
So
(
len
(
table
.
Rows
),
ShouldBeGreaterThan
,
50
)
require
.
Greater
(
t
,
len
(
table
.
Rows
)
,
50
)
for
_
,
row
:=
range
table
.
Rows
{
if
row
[
1
]
==
nil
{
nil1
=
true
...
...
@@ -86,41 +86,37 @@ func TestTestdataScenarios(t *testing.T) {
}
}
So
(
nil1
,
ShouldBeTrue
)
So
(
nil2
,
ShouldBeTrue
)
So
(
nil3
,
ShouldBeTrue
)
require
.
True
(
t
,
nil1
)
require
.
True
(
t
,
nil2
)
require
.
True
(
t
,
nil3
)
})
})
}
func
Test
To
Labels
(
t
*
testing
.
T
)
{
Convey
(
"read labels"
,
t
,
func
()
{
tags
:=
make
(
map
[
string
]
string
)
tags
[
"job"
]
=
"foo"
tags
[
"instance"
]
=
"bar"
func
Test
Parse
Labels
(
t
*
testing
.
T
)
{
expectedTags
:=
map
[
string
]
string
{
"job"
:
"foo"
,
"instance"
:
"bar"
,
}
query1
:=
tsdb
.
Query
{
Model
:
simplejson
.
NewFromAny
(
map
[
string
]
interface
{}{
"labels"
:
`{job="foo", instance="bar"}`
,
}),
}
So
(
parseLabels
(
&
query1
),
ShouldResemble
,
tags
)
require
.
Equal
(
t
,
expectedTags
,
parseLabels
(
&
query1
))
query2
:=
tsdb
.
Query
{
Model
:
simplejson
.
NewFromAny
(
map
[
string
]
interface
{}{
"labels"
:
`job=foo, instance=bar`
,
}),
}
So
(
parseLabels
(
&
query2
),
ShouldResemble
,
tags
)
require
.
Equal
(
t
,
expectedTags
,
parseLabels
(
&
query2
))
query3
:=
tsdb
.
Query
{
Model
:
simplejson
.
NewFromAny
(
map
[
string
]
interface
{}{
"labels"
:
`job = foo,instance = bar`
,
}),
}
So
(
parseLabels
(
&
query3
),
ShouldResemble
,
tags
)
})
require
.
Equal
(
t
,
expectedTags
,
parseLabels
(
&
query3
))
}
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