-
Notifications
You must be signed in to change notification settings - Fork 0
/
integration_test.go
120 lines (90 loc) · 1.83 KB
/
integration_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
116
117
118
119
120
package smtpd
import (
"net/smtp"
"testing"
)
func mustGetClient(t *testing.T) *smtp.Client {
c, err := smtp.Dial("127.0.0.1:8025")
if err != nil {
t.Fatal(err)
}
return c
}
func TestSendMail(t *testing.T) {
c := mustGetClient(t)
err := c.Hello("testing")
if err != nil {
t.Fatal(err)
}
err = c.Mail("[email protected]")
if err != nil {
t.Fatal(err)
}
err = c.Rcpt("[email protected]")
if err != nil {
t.Fatal(err)
}
err = c.Rcpt("[email protected]")
if err != nil {
t.Fatal(err)
}
w, err := c.Data()
if err != nil {
t.Fatal(err)
}
msg := `
Dear Sir or Madam,
This is a message for you from the testing environment.
Thank you for your time.
Best,
Jonathan
`
w.Write([]byte(msg))
w.Close()
err = c.Quit()
if err != nil {
t.Fatal(err)
}
}
func TestRset(t *testing.T) {
c := mustGetClient(t)
c.Hello("TestRset")
c.Mail("[email protected]")
err := c.Reset()
if err != nil {
t.Fatal(err)
}
c.Quit()
}
func TestMailError(t *testing.T) {
c := mustGetClient(t)
c.Hello("TestMailError")
err := c.Mail("test@")
assertErrorEquals(t, "553 mail: invalid string", err)
}
func TestRcptError(t *testing.T) {
c := mustGetClient(t)
c.Hello("TestMailError")
c.Mail("[email protected]")
err := c.Rcpt("test@")
assertErrorEquals(t, "553 mail: invalid string", err)
}
func TestSequenceError(t *testing.T) {
c := mustGetClient(t)
_, err := c.Data()
assertErrorEquals(t, "503 bad command sequence", err)
}
func TestNotImplementedError(t *testing.T) {
c := mustGetClient(t)
err := c.Verify("[email protected]")
assertErrorEquals(t, "502 not implemented", err)
}
func assertErrorEquals(t *testing.T, want string, got error) {
if got == nil {
t.Error("error expected but got nil")
return
}
if want != got.Error() {
t.Errorf("wanted: %s, got: %s\n", want, got.Error())
}
}