diff --git a/pkg/services/sqlstore/alerting_test.go b/pkg/services/sqlstore/alerting_test.go index d4737cd38b5..1ab725b2076 100644 --- a/pkg/services/sqlstore/alerting_test.go +++ b/pkg/services/sqlstore/alerting_test.go @@ -128,21 +128,47 @@ func TestAlertingDataAccess(t *testing.T) { }) }) - /* - Convey("When dashboard is removed", func() { - DeleteDashboard(&m.DeleteDashboardCommand{ - OrgId: 1, - Slug: testDash.Slug, - }) + Convey("When dashboard is removed", func() { + items := []m.Alert{ + { + PanelId: 1, + DashboardId: testDash.Id, + Query: "Query", + QueryRefId: "A", + WarnLevel: "> 30", + CritLevel: "> 50", + Interval: "10", + Title: "Alerting title", + Description: "Alerting description", + QueryRange: "5m", + Aggregator: "avg", + }, + } - Convey("Alerts should be removed", func() { - alerts, err2 := GetAlertsByDashboardId(testDash.Id) + cmd := m.SaveAlertsCommand{ + Alerts: &items, + DashboardId: testDash.Id, + OrgId: 1, + UserId: 1, + } - So(testDash.Id, ShouldEqual, 1) - So(err2, ShouldBeNil) - So(len(alerts), ShouldEqual, 0) - }) + SaveAlerts(&cmd) + + DeleteDashboard(&m.DeleteDashboardCommand{ + OrgId: 1, + Slug: testDash.Slug, }) - */ + + /* Uncomment this once we know why inTransaction2 is failing in unit tests + + Convey("Alerts should be removed", func() { + alerts, err2 := GetAlertsByDashboardId(testDash.Id) + + So(testDash.Id, ShouldEqual, 1) + So(err2, ShouldBeNil) + So(len(alerts), ShouldEqual, 0) + }) + */ + }) }) } diff --git a/pkg/services/sqlstore/dashboard.go b/pkg/services/sqlstore/dashboard.go index a64094cb65e..08c343dc1e4 100644 --- a/pkg/services/sqlstore/dashboard.go +++ b/pkg/services/sqlstore/dashboard.go @@ -227,6 +227,7 @@ func DeleteDashboard(cmd *m.DeleteDashboardCommand) error { "DELETE FROM dashboard_tag WHERE dashboard_id = ? ", "DELETE FROM star WHERE dashboard_id = ? ", "DELETE FROM dashboard WHERE id = ?", + "DELETE FROM alert WHERE dashboard_id = ?", } for _, sql := range deletes {