feat(alerting): make sure dashboard id exists

This commit is contained in:
bergquist
2016-04-20 09:38:44 +02:00
parent ca3ad7d17c
commit 7860a2a1b8
4 changed files with 9 additions and 7 deletions

View File

@@ -20,7 +20,6 @@ type Alert struct {
}
func (cmd *SaveDashboardCommand) GetAlertModels() *[]Alert {
dash := NewDashboardFromJson(cmd.Dashboard)
alerts := make([]Alert, 0)
for _, rowObj := range cmd.Dashboard.Get("rows").MustArray() {
@@ -31,7 +30,7 @@ func (cmd *SaveDashboardCommand) GetAlertModels() *[]Alert {
alerting := panel.Get("alerting")
alert := Alert{
DashboardId: dash.Id,
DashboardId: cmd.Result.Id,
PanelId: panel.Get("id").MustInt64(),
Id: alerting.Get("id").MustInt64(),
QueryRefId: alerting.Get("query_ref").MustString(),

View File

@@ -258,6 +258,9 @@ func TestAlertModel(t *testing.T) {
UserId: 1,
OrgId: 1,
Overwrite: true,
Result: &Dashboard{
Id: 1,
},
}
alerts := *cmd.GetAlertModels()
@@ -267,7 +270,7 @@ func TestAlertModel(t *testing.T) {
So(len(alerts), ShouldEqual, 1)
for _, v := range alerts {
So(v.DashboardId, ShouldNotEqual, 0)
So(v.DashboardId, ShouldEqual, 1)
So(v.PanelId, ShouldNotEqual, 0)
So(v.WarnLevel, ShouldEqual, 30)