dashboards_test.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package plugins
  2. import (
  3. "testing"
  4. "github.com/grafana/grafana/pkg/bus"
  5. "github.com/grafana/grafana/pkg/components/simplejson"
  6. m "github.com/grafana/grafana/pkg/models"
  7. "github.com/grafana/grafana/pkg/setting"
  8. . "github.com/smartystreets/goconvey/convey"
  9. "gopkg.in/ini.v1"
  10. )
  11. func TestPluginDashboards(t *testing.T) {
  12. Convey("When asking plugin dashboard info", t, func() {
  13. setting.Cfg = ini.Empty()
  14. sec, _ := setting.Cfg.NewSection("plugin.test-app")
  15. sec.NewKey("path", "../../tests/test-app")
  16. err := Init()
  17. So(err, ShouldBeNil)
  18. bus.AddHandler("test", func(query *m.GetDashboardQuery) error {
  19. if query.Slug == "nginx-connections" {
  20. dash := m.NewDashboard("Nginx Connections")
  21. dash.Data.Set("revision", "1.1")
  22. query.Result = dash
  23. return nil
  24. }
  25. return m.ErrDashboardNotFound
  26. })
  27. bus.AddHandler("test", func(query *m.GetDashboardsByPluginIdQuery) error {
  28. var data = simplejson.New()
  29. data.Set("title", "Nginx Connections")
  30. data.Set("revision", 22)
  31. query.Result = []*m.Dashboard{
  32. {Slug: "nginx-connections", Data: data},
  33. }
  34. return nil
  35. })
  36. dashboards, err := GetPluginDashboards(1, "test-app")
  37. So(err, ShouldBeNil)
  38. Convey("should return 2 dashboarrd", func() {
  39. So(len(dashboards), ShouldEqual, 2)
  40. })
  41. Convey("should include installed version info", func() {
  42. So(dashboards[0].Title, ShouldEqual, "Nginx Connections")
  43. So(dashboards[0].Revision, ShouldEqual, 25)
  44. So(dashboards[0].ImportedRevision, ShouldEqual, 22)
  45. So(dashboards[0].ImportedUri, ShouldEqual, "db/nginx-connections")
  46. So(dashboards[1].Revision, ShouldEqual, 2)
  47. So(dashboards[1].ImportedRevision, ShouldEqual, 0)
  48. })
  49. })
  50. }