scenarios_test.go 898 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package testdata
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/grafana/grafana/pkg/components/simplejson"
  6. "github.com/grafana/grafana/pkg/tsdb"
  7. . "github.com/smartystreets/goconvey/convey"
  8. )
  9. func TestTestdataScenarios(t *testing.T) {
  10. Convey("random walk ", t, func() {
  11. if scenario, exist := ScenarioRegistry["random_walk"]; exist {
  12. Convey("Should start at the requested value", func() {
  13. req := &tsdb.TsdbQuery{
  14. TimeRange: tsdb.NewFakeTimeRange("5m", "now", time.Now()),
  15. Queries: []*tsdb.Query{
  16. {RefId: "A", IntervalMs: 100, MaxDataPoints: 10, Model: simplejson.New()},
  17. },
  18. }
  19. query := req.Queries[0]
  20. query.Model.Set("startValue", 1.234)
  21. result := scenario.Handler(req.Queries[0], req)
  22. points := result.Series[0].Points
  23. So(result.Series, ShouldNotBeNil)
  24. So(points[0][0].Float64, ShouldEqual, 1.234)
  25. })
  26. } else {
  27. t.Fail()
  28. }
  29. })
  30. }