Skip to content
This repository was archived by the owner on Nov 28, 2024. It is now read-only.

Commit 7151d98

Browse files
committed
Test Send error message
This test is added to ensure consistent error messages as some users of the package are currently parsing it in order to extract the cause and index of errors in batches. Later commits fix this usability issue by exporting a new SendError type.
1 parent 63235f2 commit 7151d98

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

send_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package mail
22

33
import (
44
"bytes"
5+
"errors"
56
"io"
67
"reflect"
78
"testing"
@@ -50,6 +51,18 @@ func TestSend(t *testing.T) {
5051
}
5152
}
5253

54+
func TestSendError(t *testing.T) {
55+
s := &mockSendCloser{
56+
mockSender: func(_ string, _ []string, _ io.WriterTo) error {
57+
return errors.New("kaboom")
58+
},
59+
}
60+
wantErr := "gomail: could not send email 1: kaboom"
61+
if err := Send(s, getTestMessage()); err == nil || err.Error() != wantErr {
62+
t.Errorf("expected Send() error, got %q, want %q", err, wantErr)
63+
}
64+
}
65+
5366
func getTestMessage() *Message {
5467
m := NewMessage()
5568
m.SetHeader("From", testFrom)

0 commit comments

Comments
 (0)