dashboards_test.go 1.3 KB

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