Commit 874dc3d5 by Emil Hessman Committed by GitHub

Chore: Rewrite tsdb graphite test to standard library (#30088)

parent 87633c56
...@@ -3,44 +3,59 @@ package graphite ...@@ -3,44 +3,59 @@ package graphite
import ( import (
"testing" "testing"
. "github.com/smartystreets/goconvey/convey" "github.com/stretchr/testify/assert"
) )
func TestGraphiteFunctions(t *testing.T) { func TestFormatTimeRange(t *testing.T) {
Convey("Testing Graphite Functions", t, func() { testCases := []struct {
Convey("formatting time range for now", func() { input string
timeRange := formatTimeRange("now") expected string
So(timeRange, ShouldEqual, "now") }{
}) {"now", "now"},
{"now-1m", "-1min"},
Convey("formatting time range for now-1m", func() { {"now-1M", "-1mon"},
timeRange := formatTimeRange("now-1m") }
So(timeRange, ShouldEqual, "-1min")
}) for _, tc := range testCases {
t.Run(tc.input, func(t *testing.T) {
Convey("formatting time range for now-1M", func() { tr := formatTimeRange(tc.input)
timeRange := formatTimeRange("now-1M") assert.Equal(t, tc.expected, tr)
So(timeRange, ShouldEqual, "-1mon")
})
Convey("fix interval format in query for 1m", func() {
timeRange := fixIntervalFormat("aliasByNode(hitcount(averageSeries(app.grafana.*.dashboards.views.count), '1m'), 4)")
So(timeRange, ShouldEqual, "aliasByNode(hitcount(averageSeries(app.grafana.*.dashboards.views.count), '1min'), 4)")
})
Convey("fix interval format in query for 1M", func() {
timeRange := fixIntervalFormat("aliasByNode(hitcount(averageSeries(app.grafana.*.dashboards.views.count), '1M'), 4)")
So(timeRange, ShouldEqual, "aliasByNode(hitcount(averageSeries(app.grafana.*.dashboards.views.count), '1mon'), 4)")
})
Convey("should not override query for 1M", func() {
timeRange := fixIntervalFormat("app.grafana.*.dashboards.views.1M.count")
So(timeRange, ShouldEqual, "app.grafana.*.dashboards.views.1M.count")
}) })
}
}
Convey("should not override query for 1m", func() { func TestFixIntervalFormat(t *testing.T) {
timeRange := fixIntervalFormat("app.grafana.*.dashboards.views.1m.count") testCases := []struct {
So(timeRange, ShouldEqual, "app.grafana.*.dashboards.views.1m.count") name string
target string
expected string
}{
{
name: "should transform 1m to graphite unit (1min) when used as interval string",
target: "aliasByNode(hitcount(averageSeries(app.grafana.*.dashboards.views.count), '1m'), 4)",
expected: "aliasByNode(hitcount(averageSeries(app.grafana.*.dashboards.views.count), '1min'), 4)",
},
{
name: "should transform 1M to graphite unit (1mon) when used as interval string",
target: "aliasByNode(hitcount(averageSeries(app.grafana.*.dashboards.views.count), '1M'), 4)",
expected: "aliasByNode(hitcount(averageSeries(app.grafana.*.dashboards.views.count), '1mon'), 4)",
},
{
name: "should not transform 1m when not used as interval string",
target: "app.grafana.*.dashboards.views.1m.count",
expected: "app.grafana.*.dashboards.views.1m.count",
},
{
name: "should not transform 1M when not used as interval string",
target: "app.grafana.*.dashboards.views.1M.count",
expected: "app.grafana.*.dashboards.views.1M.count",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
tr := fixIntervalFormat(tc.target)
assert.Equal(t, tc.expected, tr)
}) })
}) }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment