Skip to content

Commit 69ac69b

Browse files
authored
Chore: Rewrite tsdb testdatasource scenarios test to standard library (grafana#29591)
Signed-off-by: Emil Hessman <[email protected]>
1 parent 1053989 commit 69ac69b

File tree

1 file changed

+42
-46
lines changed

1 file changed

+42
-46
lines changed

pkg/tsdb/testdatasource/scenarios_test.go

+42-46
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import (
66

77
"github.com/grafana/grafana/pkg/components/simplejson"
88
"github.com/grafana/grafana/pkg/tsdb"
9-
. "github.com/smartystreets/goconvey/convey"
9+
"github.com/stretchr/testify/require"
1010
)
1111

1212
func TestTestdataScenarios(t *testing.T) {
13-
Convey("random walk ", t, func() {
13+
t.Run("random walk ", func(t *testing.T) {
1414
scenario := ScenarioRegistry["random_walk"]
1515

16-
Convey("Should start at the requested value", func() {
16+
t.Run("Should start at the requested value", func(t *testing.T) {
1717
req := &tsdb.TsdbQuery{
1818
TimeRange: tsdb.NewFakeTimeRange("5m", "now", time.Now()),
1919
Queries: []*tsdb.Query{
@@ -24,17 +24,17 @@ func TestTestdataScenarios(t *testing.T) {
2424
query.Model.Set("startValue", 1.234)
2525

2626
result := scenario.Handler(req.Queries[0], req)
27-
points := result.Series[0].Points
27+
require.NotNil(t, result.Series)
2828

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)
3131
})
3232
})
3333

34-
Convey("random walk table", t, func() {
34+
t.Run("random walk table", func(t *testing.T) {
3535
scenario := ScenarioRegistry["random_walk_table"]
3636

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) {
3838
req := &tsdb.TsdbQuery{
3939
TimeRange: tsdb.NewFakeTimeRange("5m", "now", time.Now()),
4040
Queries: []*tsdb.Query{
@@ -45,18 +45,18 @@ func TestTestdataScenarios(t *testing.T) {
4545
result := scenario.Handler(req.Queries[0], req)
4646
table := result.Tables[0]
4747

48-
So(len(table.Rows), ShouldBeGreaterThan, 50)
48+
require.Greater(t, len(table.Rows), 50)
4949
for _, row := range table.Rows {
5050
value := row[1]
5151
min := row[2]
5252
max := row[3]
5353

54-
So(min, ShouldBeLessThan, value)
55-
So(max, ShouldBeGreaterThan, value)
54+
require.Less(t, min, value)
55+
require.Greater(t, max, value)
5656
}
5757
})
5858

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) {
6060
req := &tsdb.TsdbQuery{
6161
TimeRange: tsdb.NewFakeTimeRange("5m", "now", time.Now()),
6262
Queries: []*tsdb.Query{
@@ -73,7 +73,7 @@ func TestTestdataScenarios(t *testing.T) {
7373
nil2 := false
7474
nil3 := false
7575

76-
So(len(table.Rows), ShouldBeGreaterThan, 50)
76+
require.Greater(t, len(table.Rows), 50)
7777
for _, row := range table.Rows {
7878
if row[1] == nil {
7979
nil1 = true
@@ -86,41 +86,37 @@ func TestTestdataScenarios(t *testing.T) {
8686
}
8787
}
8888

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)
9292
})
9393
})
9494
}
9595

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))
126122
}

0 commit comments

Comments
 (0)