mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 18:44:54 +08:00
Chore: Rewrite tsdb graphite test to standard library (#30088)
This commit is contained in:
@ -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"},
|
||||||
|
{"now-1M", "-1mon"},
|
||||||
|
}
|
||||||
|
|
||||||
Convey("formatting time range for now-1m", func() {
|
for _, tc := range testCases {
|
||||||
timeRange := formatTimeRange("now-1m")
|
t.Run(tc.input, func(t *testing.T) {
|
||||||
So(timeRange, ShouldEqual, "-1min")
|
tr := formatTimeRange(tc.input)
|
||||||
|
assert.Equal(t, tc.expected, tr)
|
||||||
})
|
})
|
||||||
|
}
|
||||||
Convey("formatting time range for now-1M", func() {
|
}
|
||||||
timeRange := formatTimeRange("now-1M")
|
|
||||||
So(timeRange, ShouldEqual, "-1mon")
|
func TestFixIntervalFormat(t *testing.T) {
|
||||||
})
|
testCases := []struct {
|
||||||
|
name string
|
||||||
Convey("fix interval format in query for 1m", func() {
|
target string
|
||||||
timeRange := fixIntervalFormat("aliasByNode(hitcount(averageSeries(app.grafana.*.dashboards.views.count), '1m'), 4)")
|
expected string
|
||||||
So(timeRange, ShouldEqual, "aliasByNode(hitcount(averageSeries(app.grafana.*.dashboards.views.count), '1min'), 4)")
|
}{
|
||||||
})
|
{
|
||||||
|
name: "should transform 1m to graphite unit (1min) when used as interval string",
|
||||||
Convey("fix interval format in query for 1M", func() {
|
target: "aliasByNode(hitcount(averageSeries(app.grafana.*.dashboards.views.count), '1m'), 4)",
|
||||||
timeRange := fixIntervalFormat("aliasByNode(hitcount(averageSeries(app.grafana.*.dashboards.views.count), '1M'), 4)")
|
expected: "aliasByNode(hitcount(averageSeries(app.grafana.*.dashboards.views.count), '1min'), 4)",
|
||||||
So(timeRange, ShouldEqual, "aliasByNode(hitcount(averageSeries(app.grafana.*.dashboards.views.count), '1mon'), 4)")
|
},
|
||||||
})
|
{
|
||||||
|
name: "should transform 1M to graphite unit (1mon) when used as interval string",
|
||||||
Convey("should not override query for 1M", func() {
|
target: "aliasByNode(hitcount(averageSeries(app.grafana.*.dashboards.views.count), '1M'), 4)",
|
||||||
timeRange := fixIntervalFormat("app.grafana.*.dashboards.views.1M.count")
|
expected: "aliasByNode(hitcount(averageSeries(app.grafana.*.dashboards.views.count), '1mon'), 4)",
|
||||||
So(timeRange, ShouldEqual, "app.grafana.*.dashboards.views.1M.count")
|
},
|
||||||
})
|
{
|
||||||
|
name: "should not transform 1m when not used as interval string",
|
||||||
Convey("should not override query for 1m", func() {
|
target: "app.grafana.*.dashboards.views.1m.count",
|
||||||
timeRange := fixIntervalFormat("app.grafana.*.dashboards.views.1m.count")
|
expected: "app.grafana.*.dashboards.views.1m.count",
|
||||||
So(timeRange, ShouldEqual, "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)
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user