|
@@ -1,13 +1,14 @@
|
|
|
package dashboards
|
|
package dashboards
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
- "github.com/grafana/grafana/pkg/bus"
|
|
|
|
|
- "github.com/grafana/grafana/pkg/models"
|
|
|
|
|
- "github.com/grafana/grafana/pkg/services/alerting"
|
|
|
|
|
"os"
|
|
"os"
|
|
|
"testing"
|
|
"testing"
|
|
|
"time"
|
|
"time"
|
|
|
|
|
|
|
|
|
|
+ "github.com/grafana/grafana/pkg/bus"
|
|
|
|
|
+ "github.com/grafana/grafana/pkg/models"
|
|
|
|
|
+ "github.com/grafana/grafana/pkg/services/dashboards"
|
|
|
|
|
+
|
|
|
"github.com/grafana/grafana/pkg/log"
|
|
"github.com/grafana/grafana/pkg/log"
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
|
)
|
|
)
|
|
@@ -26,9 +27,7 @@ func TestDashboardFileReader(t *testing.T) {
|
|
|
fakeRepo = &fakeDashboardRepo{}
|
|
fakeRepo = &fakeDashboardRepo{}
|
|
|
|
|
|
|
|
bus.AddHandler("test", mockGetDashboardQuery)
|
|
bus.AddHandler("test", mockGetDashboardQuery)
|
|
|
- bus.AddHandler("test", mockValidateDashboardAlertsCommand)
|
|
|
|
|
- bus.AddHandler("test", mockSaveDashboardCommand)
|
|
|
|
|
- bus.AddHandler("test", mockUpdateDashboardAlertsCommand)
|
|
|
|
|
|
|
+ dashboards.SetRepository(fakeRepo)
|
|
|
logger := log.New("test.logger")
|
|
logger := log.New("test.logger")
|
|
|
|
|
|
|
|
cfg := &DashboardsAsConfig{
|
|
cfg := &DashboardsAsConfig{
|
|
@@ -117,10 +116,15 @@ func TestDashboardFileReader(t *testing.T) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
type fakeDashboardRepo struct {
|
|
type fakeDashboardRepo struct {
|
|
|
- inserted []*models.SaveDashboardCommand
|
|
|
|
|
|
|
+ inserted []*dashboards.SaveDashboardItem
|
|
|
getDashboard []*models.Dashboard
|
|
getDashboard []*models.Dashboard
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func (repo *fakeDashboardRepo) SaveDashboard(json *dashboards.SaveDashboardItem) (*models.Dashboard, error) {
|
|
|
|
|
+ repo.inserted = append(repo.inserted, json)
|
|
|
|
|
+ return json.Dashboard, nil
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func mockGetDashboardQuery(cmd *models.GetDashboardQuery) error {
|
|
func mockGetDashboardQuery(cmd *models.GetDashboardQuery) error {
|
|
|
for _, d := range fakeRepo.getDashboard {
|
|
for _, d := range fakeRepo.getDashboard {
|
|
|
if d.Slug == cmd.Slug {
|
|
if d.Slug == cmd.Slug {
|
|
@@ -131,16 +135,3 @@ func mockGetDashboardQuery(cmd *models.GetDashboardQuery) error {
|
|
|
|
|
|
|
|
return models.ErrDashboardNotFound
|
|
return models.ErrDashboardNotFound
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-func mockValidateDashboardAlertsCommand(cmd *alerting.ValidateDashboardAlertsCommand) error {
|
|
|
|
|
- return nil
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-func mockSaveDashboardCommand(cmd *models.SaveDashboardCommand) error {
|
|
|
|
|
- fakeRepo.inserted = append(fakeRepo.inserted, cmd)
|
|
|
|
|
- return nil
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-func mockUpdateDashboardAlertsCommand(cmd *alerting.UpdateDashboardAlertsCommand) error {
|
|
|
|
|
- return nil
|
|
|
|
|
-}
|
|
|