-
Notifications
You must be signed in to change notification settings - Fork 228
/
Copy pathpushover_test.go
86 lines (76 loc) · 2.2 KB
/
pushover_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
package pushover
import (
"context"
"errors"
"testing"
"github.com/gregdel/pushover"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
func TestPushover_Send(t *testing.T) {
t.Parallel()
tests := []struct {
name string
recipients []pushover.Recipient
subject string
message string
mockSetup func(*mockpushoverClient)
expectedError string
}{
{
name: "Successful send to single recipient",
recipients: []pushover.Recipient{*pushover.NewRecipient("recipient1")},
subject: "Test Subject",
message: "Test Message",
mockSetup: func(m *mockpushoverClient) {
m.On("SendMessage", mock.AnythingOfType("*pushover.Message"), mock.AnythingOfType("*pushover.Recipient")).
Return(&pushover.Response{}, nil)
},
expectedError: "",
},
{
name: "Successful send to multiple recipients",
recipients: []pushover.Recipient{
*pushover.NewRecipient("recipient1"),
*pushover.NewRecipient("recipient2"),
},
subject: "Test Subject",
message: "Test Message",
mockSetup: func(m *mockpushoverClient) {
m.On("SendMessage", mock.AnythingOfType("*pushover.Message"), mock.AnythingOfType("*pushover.Recipient")).
Return(&pushover.Response{}, nil).
Times(2)
},
expectedError: "",
},
{
name: "Pushover client error",
recipients: []pushover.Recipient{*pushover.NewRecipient("recipient1")},
subject: "Test Subject",
message: "Test Message",
mockSetup: func(m *mockpushoverClient) {
m.On("SendMessage", mock.AnythingOfType("*pushover.Message"), mock.AnythingOfType("*pushover.Recipient")).
Return(nil, errors.New("Pushover error"))
},
expectedError: "send message to recipient 1: Pushover error",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
mockClient := new(mockpushoverClient)
tt.mockSetup(mockClient)
p := &Pushover{
client: mockClient,
recipients: tt.recipients,
}
err := p.Send(context.Background(), tt.subject, tt.message)
if tt.expectedError != "" {
require.EqualError(t, err, tt.expectedError)
} else {
require.NoError(t, err)
}
mockClient.AssertExpectations(t)
})
}
}