Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: George Robinson <[email protected]>
  • Loading branch information
grobinson-grafana committed Apr 12, 2024
1 parent 10dcf24 commit 8b530b8
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions notify/discord/discord_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func TestDiscordTemplating(t *testing.T) {

ctx := context.Background()
ctx = notify.WithGroupKey(ctx, "1")
ctx = notify.WithNow(ctx, time.Now())

ok, err := pd.Notify(ctx, []*types.Alert{
{
Expand Down
2 changes: 2 additions & 0 deletions notify/msteams/msteams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func TestMSTeamsTemplating(t *testing.T) {

ctx := context.Background()
ctx = notify.WithGroupKey(ctx, "1")
ctx = notify.WithNow(ctx, time.Now())

ok, err := pd.Notify(ctx, []*types.Alert{
{
Expand Down Expand Up @@ -175,6 +176,7 @@ func TestNotifier_Notify_WithReason(t *testing.T) {
}
ctx := context.Background()
ctx = notify.WithGroupKey(ctx, "1")
ctx = notify.WithNow(ctx, time.Now())

alert1 := &types.Alert{
Alert: model.Alert{
Expand Down
15 changes: 15 additions & 0 deletions notify/notify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ func TestDedupStage(t *testing.T) {

ctx = WithGroupKey(ctx, "1")

_, _, err = s.Exec(ctx, log.NewNopLogger())
require.EqualError(t, err, "now missing")
ctx = WithNow(ctx, time.Now())

_, _, err = s.Exec(ctx, log.NewNopLogger())
require.EqualError(t, err, "repeat interval missing")

Expand Down Expand Up @@ -404,6 +408,7 @@ func TestRetryStageWithError(t *testing.T) {

ctx := context.Background()
ctx = WithFiringAlerts(ctx, []uint64{0})
ctx = WithNow(ctx, time.Now())

// Notify with a recoverable error should retry and succeed.
resctx, res, err := r.Exec(ctx, log.NewNopLogger(), alerts...)
Expand Down Expand Up @@ -457,6 +462,7 @@ func TestRetryStageWithErrorCode(t *testing.T) {

ctx := context.Background()
ctx = WithFiringAlerts(ctx, []uint64{0})
ctx = WithNow(ctx, time.Now())

// Notify with a non-recoverable error.
resctx, _, err := r.Exec(ctx, log.NewNopLogger(), alerts...)
Expand Down Expand Up @@ -491,6 +497,7 @@ func TestRetryStageWithContextCanceled(t *testing.T) {
}

ctx = WithFiringAlerts(ctx, []uint64{0})
ctx = WithNow(ctx, time.Now())

// Notify with a non-recoverable error.
resctx, _, err := r.Exec(ctx, log.NewNopLogger(), alerts...)
Expand Down Expand Up @@ -529,6 +536,13 @@ func TestRetryStageNoResolved(t *testing.T) {
ctx := context.Background()

resctx, res, err := r.Exec(ctx, log.NewNopLogger(), alerts...)
require.EqualError(t, err, "now missing")
require.Nil(t, res)
require.NotNil(t, resctx)

ctx = WithNow(ctx, time.Now())

resctx, res, err = r.Exec(ctx, log.NewNopLogger(), alerts...)
require.EqualError(t, err, "firing alerts missing")
require.Nil(t, res)
require.NotNil(t, resctx)
Expand Down Expand Up @@ -579,6 +593,7 @@ func TestRetryStageSendResolved(t *testing.T) {

ctx := context.Background()
ctx = WithFiringAlerts(ctx, []uint64{0})
ctx = WithNow(ctx, time.Now())

resctx, res, err := r.Exec(ctx, log.NewNopLogger(), alerts...)
require.NoError(t, err)
Expand Down
2 changes: 2 additions & 0 deletions notify/opsgenie/opsgenie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ func TestOpsGenie(t *testing.T) {

ctx := context.Background()
ctx = notify.WithGroupKey(ctx, "1")
ctx = notify.WithNow(ctx, time.Now())

expectedURL, _ := url.Parse("https://opsgenie/apiv2/alerts")

Expand Down Expand Up @@ -279,6 +280,7 @@ func TestOpsGenieWithUpdate(t *testing.T) {
tmpl := test.CreateTmpl(t)
ctx := context.Background()
ctx = notify.WithGroupKey(ctx, "1")
ctx = notify.WithNow(ctx, time.Now())
opsGenieConfigWithUpdate := config.OpsGenieConfig{
Message: `{{ .CommonLabels.Message }}`,
Description: `{{ .CommonLabels.Description }}`,
Expand Down
2 changes: 2 additions & 0 deletions notify/pagerduty/pagerduty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ func TestPagerDutyTemplating(t *testing.T) {

ctx := context.Background()
ctx = notify.WithGroupKey(ctx, "1")
ctx = notify.WithNow(ctx, time.Now())

ok, err := pd.Notify(ctx, []*types.Alert{
{
Expand Down Expand Up @@ -483,6 +484,7 @@ func TestPagerDutyEmptySrcHref(t *testing.T) {

ctx := context.Background()
ctx = notify.WithGroupKey(ctx, "1")
ctx = notify.WithNow(ctx, time.Now())

_, err = pagerDuty.Notify(ctx, []*types.Alert{
{
Expand Down
1 change: 1 addition & 0 deletions notify/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func AssertNotifyLeaksNoSecret(ctx context.Context, t *testing.T, n notify.Notif
require.NotEmpty(t, secret)

ctx = notify.WithGroupKey(ctx, "1")
ctx = notify.WithNow(ctx, time.Now())
ok, err := n.Notify(ctx, []*types.Alert{
{
Alert: model.Alert{
Expand Down
2 changes: 2 additions & 0 deletions notify/victorops/victorops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func TestVictorOpsCustomFields(t *testing.T) {

ctx := context.Background()
ctx = notify.WithGroupKey(ctx, "1")
ctx = notify.WithNow(ctx, time.Now())

alert := &types.Alert{
Alert: model.Alert{
Expand Down Expand Up @@ -211,6 +212,7 @@ func TestVictorOpsTemplating(t *testing.T) {
require.NoError(t, err)
ctx := context.Background()
ctx = notify.WithGroupKey(ctx, "1")
ctx = notify.WithNow(ctx, time.Now())

_, err = vo.Notify(ctx, []*types.Alert{
{
Expand Down

0 comments on commit 8b530b8

Please sign in to comment.