2016-03-10 12:57:48 -06:00
|
|
|
package plugins
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/bus"
|
2016-07-08 11:21:25 -05:00
|
|
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
2016-03-10 12:57:48 -06:00
|
|
|
m "github.com/grafana/grafana/pkg/models"
|
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
|
|
"gopkg.in/ini.v1"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPluginDashboards(t *testing.T) {
|
|
|
|
|
|
|
|
Convey("When asking plugin dashboard info", t, func() {
|
|
|
|
setting.Cfg = ini.Empty()
|
2016-03-11 05:39:10 -06:00
|
|
|
sec, _ := setting.Cfg.NewSection("plugin.test-app")
|
|
|
|
sec.NewKey("path", "../../tests/test-app")
|
2016-03-10 12:57:48 -06:00
|
|
|
err := Init()
|
|
|
|
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
bus.AddHandler("test", func(query *m.GetDashboardQuery) error {
|
|
|
|
if query.Slug == "nginx-connections" {
|
|
|
|
dash := m.NewDashboard("Nginx Connections")
|
2016-03-11 17:13:06 -06:00
|
|
|
dash.Data.Set("revision", "1.1")
|
2016-03-10 12:57:48 -06:00
|
|
|
query.Result = dash
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return m.ErrDashboardNotFound
|
|
|
|
})
|
|
|
|
|
2016-07-08 11:21:25 -05:00
|
|
|
bus.AddHandler("test", func(query *m.GetDashboardsByPluginIdQuery) error {
|
|
|
|
var data = simplejson.New()
|
|
|
|
data.Set("title", "Nginx Connections")
|
|
|
|
data.Set("revision", 22)
|
|
|
|
|
|
|
|
query.Result = []*m.Dashboard{
|
|
|
|
&m.Dashboard{
|
|
|
|
Slug: "nginx-connections",
|
|
|
|
Data: data,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
2016-03-11 05:39:10 -06:00
|
|
|
dashboards, err := GetPluginDashboards(1, "test-app")
|
2016-03-10 12:57:48 -06:00
|
|
|
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
Convey("should return 2 dashboarrd", func() {
|
|
|
|
So(len(dashboards), ShouldEqual, 2)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("should include installed version info", func() {
|
|
|
|
So(dashboards[0].Title, ShouldEqual, "Nginx Connections")
|
2016-07-08 11:21:25 -05:00
|
|
|
So(dashboards[0].Revision, ShouldEqual, 25)
|
|
|
|
So(dashboards[0].ImportedRevision, ShouldEqual, 22)
|
|
|
|
So(dashboards[0].ImportedUri, ShouldEqual, "db/nginx-connections")
|
2016-03-10 12:57:48 -06:00
|
|
|
|
2016-07-08 11:21:25 -05:00
|
|
|
So(dashboards[1].Revision, ShouldEqual, 2)
|
|
|
|
So(dashboards[1].ImportedRevision, ShouldEqual, 0)
|
2016-03-10 12:57:48 -06:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|