Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
Signed-off-by: Danny Kopping <[email protected]>
  • Loading branch information
dannykopping committed Aug 30, 2024
1 parent eaa0b11 commit 9b14103
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions notify/email/email_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,15 +665,17 @@ func TestEmailNoUsernameStillOk(t *testing.T) {
require.Nil(t, a)
}

// TestEmailRejected simulates the failure of an otherwise valid message submission which fails at a later point than
// was previously expected by the code.
func TestEmailRejected(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
t.Cleanup(cancel)

// Setup mock SMTP server which will reject
// Setup mock SMTP server which will reject at the DATA stage.
srv, l, err := mockSMTPServer(t)
require.NoError(t, err)
t.Cleanup(func() {
// We expect that the server has already been closed in the test
// We expect that the server has already been closed in the test.
require.ErrorIs(t, srv.Shutdown(ctx), smtp.ErrServerClosed)
})

Expand Down Expand Up @@ -707,6 +709,7 @@ func TestEmailRejected(t *testing.T) {
return true
}, time.Second*10, time.Millisecond*100, "mock SMTP server failed to start")

// Use mock SMTP server and prepare alert to be sent.
require.IsType(t, &net.TCPAddr{}, l.Addr())
addr := l.Addr().(*net.TCPAddr)
cfg := &config.EmailConfig{
Expand All @@ -721,7 +724,7 @@ func TestEmailRejected(t *testing.T) {

e := New(cfg, tmpl, log.NewNopLogger())

// Send the email.
// Send the alert to mock SMTP server.
retry, err := e.Notify(context.Background(), firingAlert)
require.ErrorContains(t, err, "501 5.5.4 Rejected!")
require.True(t, retry)
Expand Down

0 comments on commit 9b14103

Please sign in to comment.