dashboards_test.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. pm := &PluginManager{}
  17. err := pm.Init()
  18. So(err, ShouldBeNil)
  19. bus.AddHandler("test", func(query *m.GetDashboardQuery) error {
  20. if query.Slug == "nginx-connections" {
  21. dash := m.NewDashboard("Nginx Connections")
  22. dash.Data.Set("revision", "1.1")
  23. query.Result = dash
  24. return nil
  25. }
  26. return m.ErrDashboardNotFound
  27. })
  28. bus.AddHandler("test", func(query *m.GetDashboardsByPluginIdQuery) error {
  29. var data = simplejson.New()
  30. data.Set("title", "Nginx Connections")
  31. data.Set("revision", 22)
  32. query.Result = []*m.Dashboard{
  33. {Slug: "nginx-connections", Data: data},
  34. }
  35. return nil
  36. })
  37. dashboards, err := GetPluginDashboards(1, "test-app")
  38. So(err, ShouldBeNil)
  39. Convey("should return 2 dashboarrd", func() {
  40. So(len(dashboards), ShouldEqual, 2)
  41. })
  42. Convey("should include installed version info", func() {
  43. So(dashboards[0].Title, ShouldEqual, "Nginx Connections")
  44. So(dashboards[0].Revision, ShouldEqual, 25)
  45. So(dashboards[0].ImportedRevision, ShouldEqual, 22)
  46. So(dashboards[0].ImportedUri, ShouldEqual, "db/nginx-connections")
  47. So(dashboards[1].Revision, ShouldEqual, 2)
  48. So(dashboards[1].ImportedRevision, ShouldEqual, 0)
  49. })
  50. })
  51. }