forked from mongodb/grip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmtp_mock_test.go
58 lines (46 loc) · 873 Bytes
/
smtp_mock_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
package send
import (
"bytes"
"errors"
"io"
)
type bufferCloser struct {
*bytes.Buffer
}
func (bufferCloser) Close() error {
return nil
}
type smtpClientMock struct {
failCreate bool
failMail bool
failRcpt bool
failData bool
message bufferCloser
numMsgs int
}
func (c *smtpClientMock) Create(opts *SMTPOptions) error {
if c.failCreate {
return errors.New("failed creation")
}
return nil
}
func (c *smtpClientMock) Mail(to string) error {
if c.failMail {
return errors.New("failed to send mail")
}
return nil
}
func (c *smtpClientMock) Rcpt(addr string) error {
if c.failRcpt {
return errors.New("fail recpt")
}
return nil
}
func (c *smtpClientMock) Data() (io.WriteCloser, error) {
if c.failData {
return nil, errors.New("failed data")
}
c.message = bufferCloser{&bytes.Buffer{}}
c.numMsgs++
return c.message, nil
}