2016-10-10 00:12:21 -05:00
|
|
|
package tsdb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestInterval(t *testing.T) {
|
|
|
|
Convey("Default interval ", t, func() {
|
2018-04-30 09:21:04 -05:00
|
|
|
cfg := setting.NewCfg()
|
|
|
|
cfg.Load(&setting.CommandLineArgs{
|
2016-10-10 00:12:21 -05:00
|
|
|
HomePath: "../../",
|
|
|
|
})
|
|
|
|
|
2017-11-15 04:22:00 -06:00
|
|
|
calculator := NewIntervalCalculator(&IntervalOptions{})
|
|
|
|
|
2016-10-10 00:12:21 -05:00
|
|
|
Convey("for 5min", func() {
|
|
|
|
tr := NewTimeRange("5m", "now")
|
|
|
|
|
2017-11-15 04:22:00 -06:00
|
|
|
interval := calculator.Calculate(tr, time.Millisecond*1)
|
2017-01-11 05:10:26 -06:00
|
|
|
So(interval.Text, ShouldEqual, "200ms")
|
2016-10-10 00:12:21 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
Convey("for 15min", func() {
|
|
|
|
tr := NewTimeRange("15m", "now")
|
|
|
|
|
2017-11-15 04:22:00 -06:00
|
|
|
interval := calculator.Calculate(tr, time.Millisecond*1)
|
2017-01-11 05:10:26 -06:00
|
|
|
So(interval.Text, ShouldEqual, "500ms")
|
2016-10-10 00:12:21 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
Convey("for 30min", func() {
|
|
|
|
tr := NewTimeRange("30m", "now")
|
|
|
|
|
2017-11-15 04:22:00 -06:00
|
|
|
interval := calculator.Calculate(tr, time.Millisecond*1)
|
2017-01-11 05:10:26 -06:00
|
|
|
So(interval.Text, ShouldEqual, "1s")
|
2016-10-10 00:12:21 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
Convey("for 1h", func() {
|
|
|
|
tr := NewTimeRange("1h", "now")
|
|
|
|
|
2017-11-15 04:22:00 -06:00
|
|
|
interval := calculator.Calculate(tr, time.Millisecond*1)
|
2017-01-11 05:10:26 -06:00
|
|
|
So(interval.Text, ShouldEqual, "2s")
|
2016-10-10 00:12:21 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Round interval", func() {
|
|
|
|
So(roundInterval(time.Millisecond*30), ShouldEqual, time.Millisecond*20)
|
|
|
|
So(roundInterval(time.Millisecond*45), ShouldEqual, time.Millisecond*50)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Format value", func() {
|
2019-02-11 06:27:08 -06:00
|
|
|
So(FormatDuration(time.Second*61), ShouldEqual, "1m")
|
|
|
|
So(FormatDuration(time.Millisecond*30), ShouldEqual, "30ms")
|
|
|
|
So(FormatDuration(time.Hour*23), ShouldEqual, "23h")
|
|
|
|
So(FormatDuration(time.Hour*24), ShouldEqual, "1d")
|
|
|
|
So(FormatDuration(time.Hour*24*367), ShouldEqual, "1y")
|
2016-10-10 00:12:21 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|