mirror of
https://github.com/grafana/grafana.git
synced 2025-09-28 13:34:27 +08:00
chore: avoid aliasing imports in services (#22499)
This commit is contained in:
@ -5,7 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
m "github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
@ -32,7 +32,7 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
|
||||
testDash := insertTestDashboard("dashboard with alerts", 1, 0, false, "alert")
|
||||
evalData, _ := simplejson.NewJson([]byte(`{"test": "test"}`))
|
||||
items := []*m.Alert{
|
||||
items := []*models.Alert{
|
||||
{
|
||||
PanelId: 1,
|
||||
DashboardId: testDash.Id,
|
||||
@ -45,7 +45,7 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
cmd := m.SaveAlertsCommand{
|
||||
cmd := models.SaveAlertsCommand{
|
||||
Alerts: items,
|
||||
DashboardId: testDash.Id,
|
||||
OrgId: 1,
|
||||
@ -60,9 +60,9 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
|
||||
Convey("Can set new states", func() {
|
||||
Convey("new state ok", func() {
|
||||
cmd := &m.SetAlertStateCommand{
|
||||
cmd := &models.SetAlertStateCommand{
|
||||
AlertId: 1,
|
||||
State: m.AlertStateOK,
|
||||
State: models.AlertStateOK,
|
||||
}
|
||||
|
||||
err = SetAlertState(cmd)
|
||||
@ -77,9 +77,9 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
Convey("cannot updated paused alert", func() {
|
||||
cmd := &m.SetAlertStateCommand{
|
||||
cmd := &models.SetAlertStateCommand{
|
||||
AlertId: 1,
|
||||
State: m.AlertStateOK,
|
||||
State: models.AlertStateOK,
|
||||
}
|
||||
|
||||
err = SetAlertState(cmd)
|
||||
@ -109,7 +109,7 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("Can read properties", func() {
|
||||
alertQuery := m.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, PanelId: 1, OrgId: 1, User: &m.SignedInUser{OrgRole: m.ROLE_ADMIN}}
|
||||
alertQuery := models.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, PanelId: 1, OrgId: 1, User: &models.SignedInUser{OrgRole: models.ROLE_ADMIN}}
|
||||
err2 := HandleAlertsQuery(&alertQuery)
|
||||
|
||||
alert := alertQuery.Result[0]
|
||||
@ -118,7 +118,7 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
So(alert.DashboardId, ShouldEqual, testDash.Id)
|
||||
So(alert.PanelId, ShouldEqual, 1)
|
||||
So(alert.Name, ShouldEqual, "Alerting title")
|
||||
So(alert.State, ShouldEqual, m.AlertStateUnknown)
|
||||
So(alert.State, ShouldEqual, models.AlertStateUnknown)
|
||||
So(alert.NewStateDate, ShouldNotBeNil)
|
||||
So(alert.EvalData, ShouldNotBeNil)
|
||||
So(alert.EvalData.Get("test").MustString(), ShouldEqual, "test")
|
||||
@ -129,8 +129,8 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("Viewer cannot read alerts", func() {
|
||||
viewerUser := &m.SignedInUser{OrgRole: m.ROLE_VIEWER, OrgId: 1}
|
||||
alertQuery := m.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, PanelId: 1, OrgId: 1, User: viewerUser}
|
||||
viewerUser := &models.SignedInUser{OrgRole: models.ROLE_VIEWER, OrgId: 1}
|
||||
alertQuery := models.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, PanelId: 1, OrgId: 1, User: viewerUser}
|
||||
err2 := HandleAlertsQuery(&alertQuery)
|
||||
|
||||
So(err2, ShouldBeNil)
|
||||
@ -141,7 +141,7 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
modifiedItems := items
|
||||
modifiedItems[0].Name = "Name"
|
||||
|
||||
modifiedCmd := m.SaveAlertsCommand{
|
||||
modifiedCmd := models.SaveAlertsCommand{
|
||||
DashboardId: testDash.Id,
|
||||
OrgId: 1,
|
||||
UserId: 1,
|
||||
@ -155,7 +155,7 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("Alerts should be updated", func() {
|
||||
query := m.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, OrgId: 1, User: &m.SignedInUser{OrgRole: m.ROLE_ADMIN}}
|
||||
query := models.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, OrgId: 1, User: &models.SignedInUser{OrgRole: models.ROLE_ADMIN}}
|
||||
err2 := HandleAlertsQuery(&query)
|
||||
|
||||
So(err2, ShouldBeNil)
|
||||
@ -163,7 +163,7 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
So(query.Result[0].Name, ShouldEqual, "Name")
|
||||
|
||||
Convey("Alert state should not be updated", func() {
|
||||
So(query.Result[0].State, ShouldEqual, m.AlertStateUnknown)
|
||||
So(query.Result[0].State, ShouldEqual, models.AlertStateUnknown)
|
||||
})
|
||||
})
|
||||
|
||||
@ -174,7 +174,7 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("Multiple alerts per dashboard", func() {
|
||||
multipleItems := []*m.Alert{
|
||||
multipleItems := []*models.Alert{
|
||||
{
|
||||
DashboardId: testDash.Id,
|
||||
PanelId: 1,
|
||||
@ -204,7 +204,7 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
Convey("Should save 3 dashboards", func() {
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
queryForDashboard := m.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, OrgId: 1, User: &m.SignedInUser{OrgRole: m.ROLE_ADMIN}}
|
||||
queryForDashboard := models.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, OrgId: 1, User: &models.SignedInUser{OrgRole: models.ROLE_ADMIN}}
|
||||
err2 := HandleAlertsQuery(&queryForDashboard)
|
||||
|
||||
So(err2, ShouldBeNil)
|
||||
@ -218,7 +218,7 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
err = SaveAlerts(&cmd)
|
||||
|
||||
Convey("should delete the missing alert", func() {
|
||||
query := m.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, OrgId: 1, User: &m.SignedInUser{OrgRole: m.ROLE_ADMIN}}
|
||||
query := models.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, OrgId: 1, User: &models.SignedInUser{OrgRole: models.ROLE_ADMIN}}
|
||||
err2 := HandleAlertsQuery(&query)
|
||||
So(err2, ShouldBeNil)
|
||||
So(len(query.Result), ShouldEqual, 2)
|
||||
@ -227,7 +227,7 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("When dashboard is removed", func() {
|
||||
items := []*m.Alert{
|
||||
items := []*models.Alert{
|
||||
{
|
||||
PanelId: 1,
|
||||
DashboardId: testDash.Id,
|
||||
@ -236,7 +236,7 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
cmd := m.SaveAlertsCommand{
|
||||
cmd := models.SaveAlertsCommand{
|
||||
Alerts: items,
|
||||
DashboardId: testDash.Id,
|
||||
OrgId: 1,
|
||||
@ -246,14 +246,14 @@ func TestAlertingDataAccess(t *testing.T) {
|
||||
err = SaveAlerts(&cmd)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = DeleteDashboard(&m.DeleteDashboardCommand{
|
||||
err = DeleteDashboard(&models.DeleteDashboardCommand{
|
||||
OrgId: 1,
|
||||
Id: testDash.Id,
|
||||
})
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
Convey("Alerts should be removed", func() {
|
||||
query := m.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, OrgId: 1, User: &m.SignedInUser{OrgRole: m.ROLE_ADMIN}}
|
||||
query := models.GetAlertsQuery{DashboardIDs: []int64{testDash.Id}, OrgId: 1, User: &models.SignedInUser{OrgRole: models.ROLE_ADMIN}}
|
||||
err2 := HandleAlertsQuery(&query)
|
||||
|
||||
So(testDash.Id, ShouldEqual, 1)
|
||||
@ -304,7 +304,7 @@ func TestPausingAlerts(t *testing.T) {
|
||||
})
|
||||
}
|
||||
func pauseAlert(orgId int64, alertId int64, pauseState bool) (int64, error) {
|
||||
cmd := &m.PauseAlertCommand{
|
||||
cmd := &models.PauseAlertCommand{
|
||||
OrgId: orgId,
|
||||
AlertIds: []int64{alertId},
|
||||
Paused: pauseState,
|
||||
@ -313,8 +313,8 @@ func pauseAlert(orgId int64, alertId int64, pauseState bool) (int64, error) {
|
||||
So(err, ShouldBeNil)
|
||||
return cmd.ResultCount, err
|
||||
}
|
||||
func insertTestAlert(title string, message string, orgId int64, dashId int64, settings *simplejson.Json) (*m.Alert, error) {
|
||||
items := []*m.Alert{
|
||||
func insertTestAlert(title string, message string, orgId int64, dashId int64, settings *simplejson.Json) (*models.Alert, error) {
|
||||
items := []*models.Alert{
|
||||
{
|
||||
PanelId: 1,
|
||||
DashboardId: dashId,
|
||||
@ -326,7 +326,7 @@ func insertTestAlert(title string, message string, orgId int64, dashId int64, se
|
||||
},
|
||||
}
|
||||
|
||||
cmd := m.SaveAlertsCommand{
|
||||
cmd := models.SaveAlertsCommand{
|
||||
Alerts: items,
|
||||
DashboardId: dashId,
|
||||
OrgId: orgId,
|
||||
@ -337,8 +337,8 @@ func insertTestAlert(title string, message string, orgId int64, dashId int64, se
|
||||
return cmd.Alerts[0], err
|
||||
}
|
||||
|
||||
func getAlertById(id int64) (*m.Alert, error) {
|
||||
q := &m.GetAlertByIdQuery{
|
||||
func getAlertById(id int64) (*models.Alert, error) {
|
||||
q := &models.GetAlertByIdQuery{
|
||||
Id: id,
|
||||
}
|
||||
err := GetAlertById(q)
|
||||
@ -347,7 +347,7 @@ func getAlertById(id int64) (*m.Alert, error) {
|
||||
}
|
||||
|
||||
func pauseAllAlerts(pauseState bool) error {
|
||||
cmd := &m.PauseAllAlertCommand{
|
||||
cmd := &models.PauseAllAlertCommand{
|
||||
Paused: pauseState,
|
||||
}
|
||||
err := PauseAllAlerts(cmd)
|
||||
|
Reference in New Issue
Block a user