|
@@ -8,27 +8,29 @@ import (
|
|
|
m "github.com/torkelo/grafana-pro/pkg/models"
|
|
m "github.com/torkelo/grafana-pro/pkg/models"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+func insertTestDashboard(title string, accountId int64, tags ...interface{}) *m.Dashboard {
|
|
|
|
|
+ cmd := m.SaveDashboardCommand{
|
|
|
|
|
+ AccountId: accountId,
|
|
|
|
|
+ Dashboard: map[string]interface{}{
|
|
|
|
|
+ "id": nil,
|
|
|
|
|
+ "title": title,
|
|
|
|
|
+ "tags": tags,
|
|
|
|
|
+ },
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ err := SaveDashboard(&cmd)
|
|
|
|
|
+ So(err, ShouldBeNil)
|
|
|
|
|
+
|
|
|
|
|
+ return cmd.Result
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func TestDashboardDataAccess(t *testing.T) {
|
|
func TestDashboardDataAccess(t *testing.T) {
|
|
|
|
|
|
|
|
Convey("Testing DB", t, func() {
|
|
Convey("Testing DB", t, func() {
|
|
|
InitTestDB(t)
|
|
InitTestDB(t)
|
|
|
|
|
|
|
|
Convey("Given saved dashboard", func() {
|
|
Convey("Given saved dashboard", func() {
|
|
|
- var savedDash *m.Dashboard
|
|
|
|
|
-
|
|
|
|
|
- cmd := m.SaveDashboardCommand{
|
|
|
|
|
- AccountId: 1,
|
|
|
|
|
- Dashboard: map[string]interface{}{
|
|
|
|
|
- "id": nil,
|
|
|
|
|
- "title": "test dash 23",
|
|
|
|
|
- "tags": []interface{}{"prod", "webapp"},
|
|
|
|
|
- },
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- err := SaveDashboard(&cmd)
|
|
|
|
|
- So(err, ShouldBeNil)
|
|
|
|
|
-
|
|
|
|
|
- savedDash = cmd.Result
|
|
|
|
|
|
|
+ savedDash := insertTestDashboard("test dash 23", 1, "prod", "webapp")
|
|
|
|
|
|
|
|
Convey("Should return dashboard model", func() {
|
|
Convey("Should return dashboard model", func() {
|
|
|
So(savedDash.Title, ShouldEqual, "test dash 23")
|
|
So(savedDash.Title, ShouldEqual, "test dash 23")
|
|
@@ -97,6 +99,28 @@ func TestDashboardDataAccess(t *testing.T) {
|
|
|
|
|
|
|
|
So(len(query.Result), ShouldEqual, 2)
|
|
So(len(query.Result), ShouldEqual, 2)
|
|
|
})
|
|
})
|
|
|
|
|
+
|
|
|
|
|
+ Convey("Given two dashboards, one is starred dashboard by user 10, other starred by user 1", func() {
|
|
|
|
|
+ starredDash := insertTestDashboard("starred dash", 1)
|
|
|
|
|
+ StarDashboard(&m.StarDashboardCommand{
|
|
|
|
|
+ DashboardId: starredDash.Id,
|
|
|
|
|
+ UserId: 10,
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ StarDashboard(&m.StarDashboardCommand{
|
|
|
|
|
+ DashboardId: savedDash.Id,
|
|
|
|
|
+ UserId: 1,
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ Convey("Should be able to search for starred dashboards", func() {
|
|
|
|
|
+ query := m.SearchDashboardsQuery{AccountId: 1, UserId: 10, IsStarred: true}
|
|
|
|
|
+ err := SearchDashboards(&query)
|
|
|
|
|
+
|
|
|
|
|
+ So(err, ShouldBeNil)
|
|
|
|
|
+ So(len(query.Result), ShouldEqual, 1)
|
|
|
|
|
+ So(query.Result[0].Title, ShouldEqual, "starred dash")
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|