mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(alerting): fixing failing unit tests
This commit is contained in:
@@ -15,12 +15,12 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
|
||||
var err error
|
||||
|
||||
Convey("Alert notifications should be empty", func() {
|
||||
cmd := &m.GetAlertNotificationQuery{
|
||||
OrgID: FakeOrgId,
|
||||
cmd := &m.GetAlertNotificationsQuery{
|
||||
OrgId: 2,
|
||||
Name: "email",
|
||||
}
|
||||
|
||||
err := AlertNotificationQuery(cmd)
|
||||
err := GetAlertNotifications(cmd)
|
||||
fmt.Printf("errror %v", err)
|
||||
So(err, ShouldBeNil)
|
||||
So(len(cmd.Result), ShouldEqual, 0)
|
||||
@@ -28,11 +28,10 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
|
||||
|
||||
Convey("Can save Alert Notification", func() {
|
||||
cmd := &m.CreateAlertNotificationCommand{
|
||||
Name: "ops",
|
||||
Type: "email",
|
||||
OrgID: 1,
|
||||
Settings: simplejson.New(),
|
||||
AlwaysExecute: true,
|
||||
Name: "ops",
|
||||
Type: "email",
|
||||
OrgId: 1,
|
||||
Settings: simplejson.New(),
|
||||
}
|
||||
|
||||
err = CreateAlertNotificationCommand(cmd)
|
||||
@@ -40,7 +39,6 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
|
||||
So(cmd.Result.Id, ShouldNotEqual, 0)
|
||||
So(cmd.Result.OrgId, ShouldNotEqual, 0)
|
||||
So(cmd.Result.Type, ShouldEqual, "email")
|
||||
So(cmd.Result.AlwaysExecute, ShouldEqual, true)
|
||||
|
||||
Convey("Cannot save Alert Notification with the same name", func() {
|
||||
err = CreateAlertNotificationCommand(cmd)
|
||||
@@ -49,12 +47,11 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
|
||||
|
||||
Convey("Can update alert notification", func() {
|
||||
newCmd := &m.UpdateAlertNotificationCommand{
|
||||
Name: "NewName",
|
||||
Type: "webhook",
|
||||
OrgID: cmd.Result.OrgId,
|
||||
Settings: simplejson.New(),
|
||||
Id: cmd.Result.Id,
|
||||
AlwaysExecute: true,
|
||||
Name: "NewName",
|
||||
Type: "webhook",
|
||||
OrgId: cmd.Result.OrgId,
|
||||
Settings: simplejson.New(),
|
||||
Id: cmd.Result.Id,
|
||||
}
|
||||
err := UpdateAlertNotification(newCmd)
|
||||
So(err, ShouldBeNil)
|
||||
@@ -63,49 +60,23 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
|
||||
})
|
||||
|
||||
Convey("Can search using an array of ids", func() {
|
||||
So(CreateAlertNotificationCommand(&m.CreateAlertNotificationCommand{
|
||||
Name: "nagios",
|
||||
Type: "webhook",
|
||||
OrgID: 1,
|
||||
Settings: simplejson.New(),
|
||||
AlwaysExecute: true,
|
||||
}), ShouldBeNil)
|
||||
cmd1 := m.CreateAlertNotificationCommand{Name: "nagios", Type: "webhook", OrgId: 1, Settings: simplejson.New()}
|
||||
cmd2 := m.CreateAlertNotificationCommand{Name: "slack", Type: "webhook", OrgId: 1, Settings: simplejson.New()}
|
||||
cmd3 := m.CreateAlertNotificationCommand{Name: "ops2", Type: "email", OrgId: 1, Settings: simplejson.New()}
|
||||
|
||||
So(CreateAlertNotificationCommand(&m.CreateAlertNotificationCommand{
|
||||
Name: "ops2",
|
||||
Type: "email",
|
||||
OrgID: 1,
|
||||
Settings: simplejson.New(),
|
||||
}), ShouldBeNil)
|
||||
|
||||
So(CreateAlertNotificationCommand(&m.CreateAlertNotificationCommand{
|
||||
Name: "slack",
|
||||
Type: "webhook",
|
||||
OrgID: 1,
|
||||
Settings: simplejson.New(),
|
||||
}), ShouldBeNil)
|
||||
So(CreateAlertNotificationCommand(&cmd1), ShouldBeNil)
|
||||
So(CreateAlertNotificationCommand(&cmd2), ShouldBeNil)
|
||||
So(CreateAlertNotificationCommand(&cmd3), ShouldBeNil)
|
||||
|
||||
Convey("search", func() {
|
||||
existingNotification := int64(2)
|
||||
missingThatSholdNotCauseerrors := int64(99)
|
||||
|
||||
query := &m.GetAlertNotificationQuery{
|
||||
Ids: []int64{existingNotification, missingThatSholdNotCauseerrors},
|
||||
OrgID: 1,
|
||||
IncludeAlwaysExecute: true,
|
||||
query := &m.GetAlertNotificationsQuery{
|
||||
Ids: []int64{cmd1.Result.Id, cmd2.Result.Id, 112341231},
|
||||
OrgId: 1,
|
||||
}
|
||||
|
||||
err := AlertNotificationQuery(query)
|
||||
err := GetAlertNotifications(query)
|
||||
So(err, ShouldBeNil)
|
||||
So(len(query.Result), ShouldEqual, 2)
|
||||
defaultNotifications := 0
|
||||
for _, not := range query.Result {
|
||||
if not.AlwaysExecute {
|
||||
defaultNotifications++
|
||||
}
|
||||
}
|
||||
|
||||
So(defaultNotifications, ShouldEqual, 1)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user