|
|
|
@@ -10,8 +10,10 @@ import (
|
|
|
|
|
"github.com/grafana/grafana/pkg/models"
|
|
|
|
|
"github.com/grafana/grafana/pkg/services/dashboards"
|
|
|
|
|
dashver "github.com/grafana/grafana/pkg/services/dashboardversion"
|
|
|
|
|
"github.com/grafana/grafana/pkg/services/org"
|
|
|
|
|
"github.com/grafana/grafana/pkg/services/sqlstore"
|
|
|
|
|
"github.com/grafana/grafana/pkg/services/sqlstore/db"
|
|
|
|
|
"github.com/grafana/grafana/pkg/services/user"
|
|
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
|
|
|
"github.com/grafana/grafana/pkg/util"
|
|
|
|
|
|
|
|
|
@@ -74,7 +76,7 @@ func TestIntegrationAlertingDataAccess(t *testing.T) {
|
|
|
|
|
setup(t)
|
|
|
|
|
|
|
|
|
|
// Get alert so we can use its ID in tests
|
|
|
|
|
alertQuery := models.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, PanelId: 1, OrgId: 1, User: &models.SignedInUser{OrgRole: models.ROLE_ADMIN}}
|
|
|
|
|
alertQuery := models.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, PanelId: 1, OrgId: 1, User: &user.SignedInUser{OrgRole: org.RoleAdmin}}
|
|
|
|
|
err2 := store.HandleAlertsQuery(context.Background(), &alertQuery)
|
|
|
|
|
require.Nil(t, err2)
|
|
|
|
|
|
|
|
|
@@ -131,7 +133,7 @@ func TestIntegrationAlertingDataAccess(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
t.Run("Can read properties", func(t *testing.T) {
|
|
|
|
|
setup(t)
|
|
|
|
|
alertQuery := models.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, PanelId: 1, OrgId: 1, User: &models.SignedInUser{OrgRole: models.ROLE_ADMIN}}
|
|
|
|
|
alertQuery := models.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, PanelId: 1, OrgId: 1, User: &user.SignedInUser{OrgRole: org.RoleAdmin}}
|
|
|
|
|
err2 := store.HandleAlertsQuery(context.Background(), &alertQuery)
|
|
|
|
|
|
|
|
|
|
alert := alertQuery.Result[0]
|
|
|
|
@@ -152,7 +154,7 @@ func TestIntegrationAlertingDataAccess(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
t.Run("Viewer can read alerts", func(t *testing.T) {
|
|
|
|
|
setup(t)
|
|
|
|
|
viewerUser := &models.SignedInUser{OrgRole: models.ROLE_VIEWER, OrgId: 1}
|
|
|
|
|
viewerUser := &user.SignedInUser{OrgRole: org.RoleViewer, OrgId: 1}
|
|
|
|
|
alertQuery := models.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, PanelId: 1, OrgId: 1, User: viewerUser}
|
|
|
|
|
err2 := store.HandleAlertsQuery(context.Background(), &alertQuery)
|
|
|
|
|
|
|
|
|
@@ -172,7 +174,7 @@ func TestIntegrationAlertingDataAccess(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("Alerts should be updated", func(t *testing.T) {
|
|
|
|
|
query := models.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, OrgId: 1, User: &models.SignedInUser{OrgRole: models.ROLE_ADMIN}}
|
|
|
|
|
query := models.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, OrgId: 1, User: &user.SignedInUser{OrgRole: org.RoleAdmin}}
|
|
|
|
|
err2 := store.HandleAlertsQuery(context.Background(), &query)
|
|
|
|
|
|
|
|
|
|
require.Nil(t, err2)
|
|
|
|
@@ -221,7 +223,7 @@ func TestIntegrationAlertingDataAccess(t *testing.T) {
|
|
|
|
|
t.Run("Should save 3 dashboards", func(t *testing.T) {
|
|
|
|
|
require.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
queryForDashboard := models.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, OrgId: 1, User: &models.SignedInUser{OrgRole: models.ROLE_ADMIN}}
|
|
|
|
|
queryForDashboard := models.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, OrgId: 1, User: &user.SignedInUser{OrgRole: org.RoleAdmin}}
|
|
|
|
|
err2 := store.HandleAlertsQuery(context.Background(), &queryForDashboard)
|
|
|
|
|
|
|
|
|
|
require.Nil(t, err2)
|
|
|
|
@@ -234,7 +236,7 @@ func TestIntegrationAlertingDataAccess(t *testing.T) {
|
|
|
|
|
err = store.SaveAlerts(context.Background(), testDash.Id, missingOneAlert)
|
|
|
|
|
|
|
|
|
|
t.Run("should delete the missing alert", func(t *testing.T) {
|
|
|
|
|
query := models.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, OrgId: 1, User: &models.SignedInUser{OrgRole: models.ROLE_ADMIN}}
|
|
|
|
|
query := models.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, OrgId: 1, User: &user.SignedInUser{OrgRole: org.RoleAdmin}}
|
|
|
|
|
err2 := store.HandleAlertsQuery(context.Background(), &query)
|
|
|
|
|
require.Nil(t, err2)
|
|
|
|
|
require.Equal(t, 2, len(query.Result))
|
|
|
|
@@ -264,7 +266,7 @@ func TestIntegrationAlertingDataAccess(t *testing.T) {
|
|
|
|
|
require.Nil(t, err)
|
|
|
|
|
|
|
|
|
|
t.Run("Alerts should be removed", func(t *testing.T) {
|
|
|
|
|
query := models.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, OrgId: 1, User: &models.SignedInUser{OrgRole: models.ROLE_ADMIN}}
|
|
|
|
|
query := models.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, OrgId: 1, User: &user.SignedInUser{OrgRole: org.RoleAdmin}}
|
|
|
|
|
err2 := store.HandleAlertsQuery(context.Background(), &query)
|
|
|
|
|
|
|
|
|
|
require.Nil(t, err2)
|
|
|
|
@@ -291,7 +293,7 @@ func TestIntegrationPausingAlerts(t *testing.T) {
|
|
|
|
|
stateDateAfterPause := stateDateBeforePause
|
|
|
|
|
|
|
|
|
|
// Get alert so we can use its ID in tests
|
|
|
|
|
alertQuery := models.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, PanelId: 1, OrgId: 1, User: &models.SignedInUser{OrgRole: models.ROLE_ADMIN}}
|
|
|
|
|
alertQuery := models.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, PanelId: 1, OrgId: 1, User: &user.SignedInUser{OrgRole: org.RoleAdmin}}
|
|
|
|
|
err2 := sqlStore.HandleAlertsQuery(context.Background(), &alertQuery)
|
|
|
|
|
require.Nil(t, err2)
|
|
|
|
|
|
|
|
|
|