forked from nikoksr/notify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamazon_ses_test.go
115 lines (91 loc) · 2.42 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package amazonses
import (
"context"
"testing"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/ses"
"github.com/aws/aws-sdk-go-v2/service/ses/types"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
)
func TestAmazonSES_New(t *testing.T) {
t.Parallel()
assert := require.New(t)
service, err := New("", "", "", "")
assert.NotNil(service)
assert.Nil(err)
}
func TestAmazonSES_AddReceivers(t *testing.T) {
t.Parallel()
assert := require.New(t)
service, err := New("", "", "", "")
assert.NotNil(service)
assert.Nil(err)
receivers := []string{"1", "2", "3", "4", "5"}
service.AddReceivers(receivers...)
assert.Equal(service.receiverAddresses, receivers)
a6 := "6"
receivers = append(receivers, a6)
service.AddReceivers(a6)
assert.Equal(service.receiverAddresses, receivers)
}
func TestAmazonSES_Send(t *testing.T) {
t.Parallel()
assert := require.New(t)
sender := "4"
service, err := New("1", "2", "3", sender)
assert.NotNil(service)
assert.Nil(err)
// Example payload
input := ses.SendEmailInput{
Source: &sender,
Destination: &types.Destination{
ToAddresses: []string{},
},
Message: &types.Message{
Body: &types.Body{
Html: &types.Content{
Data: aws.String("message"),
},
},
Subject: &types.Content{
Data: aws.String("subject"),
},
},
}
// No receivers added
ctx := context.Background()
mockClient := newMockSesClient(t)
mockClient.
On("SendEmail", ctx, &input).
Return(nil, nil)
service.client = mockClient
err = service.Send(ctx, "subject", "message")
assert.Nil(err)
mockClient.AssertExpectations(t)
// Test with receivers
receivers := []string{"1", "2"}
input.Destination.ToAddresses = receivers
service.AddReceivers(receivers...)
mockClient = newMockSesClient(t)
mockClient.
On("SendEmail", ctx, &input).
Return(nil, nil)
service.client = mockClient
err = service.Send(ctx, "subject", "message")
assert.Nil(err)
mockClient.AssertExpectations(t)
// Test with more receivers and error response
receivers = []string{"1", "2", "3", "4", "5"}
input.Destination.ToAddresses = receivers
service.receiverAddresses = make([]string, 0)
service.AddReceivers(receivers...)
mockClient = newMockSesClient(t)
mockClient.
On("SendEmail", ctx, &input).
Return(nil, errors.New("some error"))
service.client = mockClient
err = service.Send(ctx, "subject", "message")
assert.NotNil(err)
mockClient.AssertExpectations(t)
}