-
Notifications
You must be signed in to change notification settings - Fork 159
/
error_test.go
176 lines (139 loc) · 4.17 KB
/
error_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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package emailverifier
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
func TestParse550RCPTError(t *testing.T) {
err := errors.New("550 This mailbox does not exist")
le := ParseSMTPError(err)
assert.Equal(t, ErrServerUnavailable, le.Message)
assert.Equal(t, err.Error(), le.Details)
}
func TestParse550BlockedRCPTError(t *testing.T) {
err := errors.New("550 spamhaus")
le := ParseSMTPError(err)
assert.Equal(t, ErrBlocked, le.Message)
assert.Equal(t, err.Error(), le.Details)
}
func TestParseConnectMailExchangerError(t *testing.T) {
err := errors.New("Timeout connecting to mail-exchanger")
le := ParseSMTPError(err)
assert.Equal(t, ErrTimeout, le.Message)
assert.Equal(t, err.Error(), le.Details)
}
func TestParseNoMxRecordsFoundError(t *testing.T) {
errStr := "No MX records found"
err := errors.New(errStr)
le := ParseSMTPError(err)
assert.Equal(t, &LookupError{Details: errStr, Message: errStr}, le)
}
func TestParseFullInBoxError(t *testing.T) {
errStr := "452 full Inbox"
err := errors.New(errStr)
le := ParseSMTPError(err)
assert.Equal(t, ErrFullInbox, le.Message)
assert.Equal(t, err.Error(), le.Details)
}
func TestParseDailSMTPServerError(t *testing.T) {
errStr := "Unexpected response dialing SMTP server"
err := errors.New(errStr)
le := ParseSMTPError(err)
assert.Equal(t, &LookupError{Details: errStr, Message: errStr}, le)
}
func TestParseError_Code550(t *testing.T) {
errStr := "550"
err := errors.New(errStr)
le := ParseSMTPError(err)
assert.Equal(t, ErrServerUnavailable, le.Message)
assert.Equal(t, err.Error(), le.Details)
}
func TestParseError_Code400_Nil(t *testing.T) {
errStr := "400"
err := errors.New(errStr)
le := ParseSMTPError(err)
assert.Equal(t, (*LookupError)(nil), le)
}
func TestParseError_Code401(t *testing.T) {
errStr := "401"
err := errors.New(errStr)
le := ParseSMTPError(err)
assert.Equal(t, &LookupError{Details: errStr, Message: errStr}, le)
}
func TestParseError_Code421(t *testing.T) {
errStr := "421"
err := errors.New(errStr)
le := ParseSMTPError(err)
assert.Equal(t, ErrTryAgainLater, le.Message)
assert.Equal(t, err.Error(), le.Details)
}
func TestParseError_Code450(t *testing.T) {
errStr := "450"
err := errors.New(errStr)
le := ParseSMTPError(err)
assert.Equal(t, ErrMailboxBusy, le.Message)
assert.Equal(t, err.Error(), le.Details)
}
func TestParseError_Code451(t *testing.T) {
errStr := "451"
err := errors.New(errStr)
le := ParseSMTPError(err)
assert.Equal(t, ErrExceededMessagingLimits, le.Message)
assert.Equal(t, err.Error(), le.Details)
}
func TestParseError_Code452(t *testing.T) {
errStr := "452"
err := errors.New(errStr)
le := ParseSMTPError(err)
assert.Equal(t, ErrTooManyRCPT, le.Message)
assert.Equal(t, err.Error(), le.Details)
}
func TestParseError_Code503(t *testing.T) {
errStr := "503"
err := errors.New(errStr)
le := ParseSMTPError(err)
assert.Equal(t, ErrNeedMAILBeforeRCPT, le.Message)
assert.Equal(t, err.Error(), le.Details)
}
func TestParseError_Code551(t *testing.T) {
errStr := "551"
err := errors.New(errStr)
le := ParseSMTPError(err)
assert.Equal(t, ErrRCPTHasMoved, le.Message)
assert.Equal(t, err.Error(), le.Details)
}
func TestParseError_Code552(t *testing.T) {
errStr := "552"
err := errors.New(errStr)
le := ParseSMTPError(err)
assert.Equal(t, ErrFullInbox, le.Message)
assert.Equal(t, err.Error(), le.Details)
}
func TestParseError_Code553(t *testing.T) {
errStr := "553"
err := errors.New(errStr)
le := ParseSMTPError(err)
assert.Equal(t, ErrNoRelay, le.Message)
assert.Equal(t, err.Error(), le.Details)
}
func TestParseError_Code554(t *testing.T) {
errStr := "554"
err := errors.New(errStr)
le := ParseSMTPError(err)
assert.Equal(t, ErrNotAllowed, le.Message)
assert.Equal(t, err.Error(), le.Details)
}
func TestParseError_basicErr_timeout(t *testing.T) {
errStr := "559 timeout"
err := errors.New(errStr)
le := ParseSMTPError(err)
assert.Equal(t, ErrTimeout, le.Message)
assert.Equal(t, err.Error(), le.Details)
}
func TestParseError_basicErr_blocked(t *testing.T) {
errStr := "559 blocked"
err := errors.New(errStr)
le := ParseSMTPError(err)
assert.Equal(t, ErrBlocked, le.Message)
assert.Equal(t, err.Error(), le.Details)
}