@@ -6,14 +6,14 @@ import (
6
6
7
7
"github.com/grafana/grafana/pkg/components/simplejson"
8
8
"github.com/grafana/grafana/pkg/tsdb"
9
- . "github.com/smartystreets/goconvey/convey "
9
+ "github.com/stretchr/testify/require "
10
10
)
11
11
12
12
func TestTestdataScenarios (t * testing.T ) {
13
- Convey ("random walk " , t , func () {
13
+ t . Run ("random walk " , func (t * testing. T ) {
14
14
scenario := ScenarioRegistry ["random_walk" ]
15
15
16
- Convey ("Should start at the requested value" , func () {
16
+ t . Run ("Should start at the requested value" , func (t * testing. T ) {
17
17
req := & tsdb.TsdbQuery {
18
18
TimeRange : tsdb .NewFakeTimeRange ("5m" , "now" , time .Now ()),
19
19
Queries : []* tsdb.Query {
@@ -24,17 +24,17 @@ func TestTestdataScenarios(t *testing.T) {
24
24
query .Model .Set ("startValue" , 1.234 )
25
25
26
26
result := scenario .Handler (req .Queries [0 ], req )
27
- points := result .Series [ 0 ]. Points
27
+ require . NotNil ( t , result .Series )
28
28
29
- So ( result .Series , ShouldNotBeNil )
30
- So ( points [0 ][0 ].Float64 , ShouldEqual , 1.234 )
29
+ points := result .Series [ 0 ]. Points
30
+ require . Equal ( t , 1.234 , points [0 ][0 ].Float64 )
31
31
})
32
32
})
33
33
34
- Convey ("random walk table" , t , func () {
34
+ t . Run ("random walk table" , func (t * testing. T ) {
35
35
scenario := ScenarioRegistry ["random_walk_table" ]
36
36
37
- Convey ("Should return a table that looks like value/min/max" , func () {
37
+ t . Run ("Should return a table that looks like value/min/max" , func (t * testing. T ) {
38
38
req := & tsdb.TsdbQuery {
39
39
TimeRange : tsdb .NewFakeTimeRange ("5m" , "now" , time .Now ()),
40
40
Queries : []* tsdb.Query {
@@ -45,18 +45,18 @@ func TestTestdataScenarios(t *testing.T) {
45
45
result := scenario .Handler (req .Queries [0 ], req )
46
46
table := result .Tables [0 ]
47
47
48
- So ( len (table .Rows ), ShouldBeGreaterThan , 50 )
48
+ require . Greater ( t , len (table .Rows ), 50 )
49
49
for _ , row := range table .Rows {
50
50
value := row [1 ]
51
51
min := row [2 ]
52
52
max := row [3 ]
53
53
54
- So ( min , ShouldBeLessThan , value )
55
- So ( max , ShouldBeGreaterThan , value )
54
+ require . Less ( t , min , value )
55
+ require . Greater ( t , max , value )
56
56
}
57
57
})
58
58
59
- Convey ("Should return a table with some nil values" , func () {
59
+ t . Run ("Should return a table with some nil values" , func (t * testing. T ) {
60
60
req := & tsdb.TsdbQuery {
61
61
TimeRange : tsdb .NewFakeTimeRange ("5m" , "now" , time .Now ()),
62
62
Queries : []* tsdb.Query {
@@ -73,7 +73,7 @@ func TestTestdataScenarios(t *testing.T) {
73
73
nil2 := false
74
74
nil3 := false
75
75
76
- So ( len (table .Rows ), ShouldBeGreaterThan , 50 )
76
+ require . Greater ( t , len (table .Rows ), 50 )
77
77
for _ , row := range table .Rows {
78
78
if row [1 ] == nil {
79
79
nil1 = true
@@ -86,41 +86,37 @@ func TestTestdataScenarios(t *testing.T) {
86
86
}
87
87
}
88
88
89
- So ( nil1 , ShouldBeTrue )
90
- So ( nil2 , ShouldBeTrue )
91
- So ( nil3 , ShouldBeTrue )
89
+ require . True ( t , nil1 )
90
+ require . True ( t , nil2 )
91
+ require . True ( t , nil3 )
92
92
})
93
93
})
94
94
}
95
95
96
- func TestToLabels (t * testing.T ) {
97
- Convey ("read labels" , t , func () {
98
- tags := make (map [string ]string )
99
- tags ["job" ] = "foo"
100
- tags ["instance" ] = "bar"
101
-
102
- query1 := tsdb.Query {
103
- Model : simplejson .NewFromAny (map [string ]interface {}{
104
- "labels" : `{job="foo", instance="bar"}` ,
105
- }),
106
- }
107
-
108
- So (parseLabels (& query1 ), ShouldResemble , tags )
109
-
110
- query2 := tsdb.Query {
111
- Model : simplejson .NewFromAny (map [string ]interface {}{
112
- "labels" : `job=foo, instance=bar` ,
113
- }),
114
- }
115
-
116
- So (parseLabels (& query2 ), ShouldResemble , tags )
117
-
118
- query3 := tsdb.Query {
119
- Model : simplejson .NewFromAny (map [string ]interface {}{
120
- "labels" : `job = foo,instance = bar` ,
121
- }),
122
- }
123
-
124
- So (parseLabels (& query3 ), ShouldResemble , tags )
125
- })
96
+ func TestParseLabels (t * testing.T ) {
97
+ expectedTags := map [string ]string {
98
+ "job" : "foo" ,
99
+ "instance" : "bar" ,
100
+ }
101
+
102
+ query1 := tsdb.Query {
103
+ Model : simplejson .NewFromAny (map [string ]interface {}{
104
+ "labels" : `{job="foo", instance="bar"}` ,
105
+ }),
106
+ }
107
+ require .Equal (t , expectedTags , parseLabels (& query1 ))
108
+
109
+ query2 := tsdb.Query {
110
+ Model : simplejson .NewFromAny (map [string ]interface {}{
111
+ "labels" : `job=foo, instance=bar` ,
112
+ }),
113
+ }
114
+ require .Equal (t , expectedTags , parseLabels (& query2 ))
115
+
116
+ query3 := tsdb.Query {
117
+ Model : simplejson .NewFromAny (map [string ]interface {}{
118
+ "labels" : `job = foo,instance = bar` ,
119
+ }),
120
+ }
121
+ require .Equal (t , expectedTags , parseLabels (& query3 ))
126
122
}
0 commit comments