-
Notifications
You must be signed in to change notification settings - Fork 218
/
amazon_ses_test.go
73 lines (63 loc) · 1.67 KB
/
amazon_ses_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package amazonses
import (
"context"
"errors"
"testing"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/ses"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
func TestAmazonSES_Send(t *testing.T) {
t.Parallel()
tests := []struct {
name string
receivers []string
subject string
message string
mockSetup func(*mocksesClient)
expectedError string
}{
{
name: "Successful send",
receivers: []string{"[email protected]"},
subject: "Test Subject",
message: "Test Message",
mockSetup: func(m *mocksesClient) {
m.On("SendEmail", mock.Anything, mock.AnythingOfType("*ses.SendEmailInput")).
Return(&ses.SendEmailOutput{}, nil)
},
expectedError: "",
},
{
name: "SES client error",
receivers: []string{"[email protected]"},
subject: "Test Subject",
message: "Test Message",
mockSetup: func(m *mocksesClient) {
m.On("SendEmail", mock.Anything, mock.AnythingOfType("*ses.SendEmailInput")).
Return(nil, errors.New("SES error"))
},
expectedError: "send mail using Amazon SES service: SES error",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
mockClient := new(mocksesClient)
tt.mockSetup(mockClient)
s := &AmazonSES{
client: mockClient,
senderAddress: aws.String("[email protected]"),
receiverAddresses: tt.receivers,
}
err := s.Send(context.Background(), tt.subject, tt.message)
if tt.expectedError != "" {
require.EqualError(t, err, tt.expectedError)
} else {
require.NoError(t, err)
}
mockClient.AssertExpectations(t)
})
}
}