forked from mocktools/go-smtp-mock
-
Notifications
You must be signed in to change notification settings - Fork 1
/
message_test.go
236 lines (172 loc) · 6.2 KB
/
message_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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
package smtpmock
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestMessageHeloRequest(t *testing.T) {
t.Run("getter for heloRequest field", func(t *testing.T) {
message := Message{heloRequest: "some context"}
assert.Equal(t, message.heloRequest, message.HeloRequest())
})
}
func TestMessageHeloResponse(t *testing.T) {
t.Run("getter for heloRequest field", func(t *testing.T) {
message := Message{heloResponse: "some context"}
assert.Equal(t, message.heloResponse, message.HeloResponse())
})
}
func TestMessageHelo(t *testing.T) {
t.Run("getter for helo field", func(t *testing.T) {
message := Message{helo: true}
assert.Equal(t, message.helo, message.Helo())
})
}
func TestMessageMailfromRequest(t *testing.T) {
t.Run("getter for mailfromRequest field", func(t *testing.T) {
message := Message{mailfromRequest: "some context"}
assert.Equal(t, message.mailfromRequest, message.MailfromRequest())
})
}
func TestMessageMailfromResponse(t *testing.T) {
t.Run("getter for mailfromResponse field", func(t *testing.T) {
message := Message{mailfromResponse: "some context"}
assert.Equal(t, message.mailfromResponse, message.MailfromResponse())
})
}
func TestMessageMailfrom(t *testing.T) {
t.Run("getter for mailfrom field", func(t *testing.T) {
message := Message{mailfrom: true}
assert.Equal(t, message.mailfrom, message.Mailfrom())
})
}
func TestMessageRcpttoRequestResponse(t *testing.T) {
t.Run("getter for rcpttoRequestResponse field", func(t *testing.T) {
message := Message{rcpttoRequestResponse: [][]string{{"request", "response"}}}
assert.Equal(t, message.rcpttoRequestResponse, message.RcpttoRequestResponse())
})
}
func TestMessageRcptto(t *testing.T) {
t.Run("getter for rcptto field", func(t *testing.T) {
message := Message{rcptto: true}
assert.Equal(t, message.rcptto, message.Rcptto())
})
}
func TestMessageDataRequest(t *testing.T) {
t.Run("getter for dataRequest field", func(t *testing.T) {
message := Message{dataRequest: "some context"}
assert.Equal(t, message.dataRequest, message.DataRequest())
})
}
func TestMessageDataResponse(t *testing.T) {
t.Run("getter for dataResponse field", func(t *testing.T) {
message := Message{dataResponse: "some context"}
assert.Equal(t, message.dataResponse, message.DataResponse())
})
}
func TestMessageData(t *testing.T) {
t.Run("getter for data field", func(t *testing.T) {
message := Message{data: true}
assert.Equal(t, message.data, message.Data())
})
}
func TestMessageMsgRequest(t *testing.T) {
t.Run("getter for msgRequest field", func(t *testing.T) {
message := Message{msgRequest: "some context"}
assert.Equal(t, message.msgRequest, message.MsgRequest())
})
}
func TestMessageMsgResponse(t *testing.T) {
t.Run("getter for msgRequest field", func(t *testing.T) {
message := Message{msgResponse: "some context"}
assert.Equal(t, message.msgResponse, message.MsgResponse())
})
}
func TestMessageMsg(t *testing.T) {
t.Run("getter for msg field", func(t *testing.T) {
message := Message{msg: true}
assert.Equal(t, message.msg, message.Msg())
})
}
func TestMessageRsetRequest(t *testing.T) {
t.Run("getter for rsetRequest field", func(t *testing.T) {
message := Message{rsetRequest: "some context"}
assert.Equal(t, message.rsetRequest, message.RsetRequest())
})
}
func TestMessageRsetResponse(t *testing.T) {
t.Run("getter for rsetRequest field", func(t *testing.T) {
message := Message{rsetResponse: "some context"}
assert.Equal(t, message.rsetResponse, message.RsetResponse())
})
}
func TestMessageRset(t *testing.T) {
t.Run("getter for rset field", func(t *testing.T) {
message := Message{rset: true}
assert.Equal(t, message.rset, message.Rset())
})
}
func TestMessageQuitSent(t *testing.T) {
t.Run("getter for quitSent field", func(t *testing.T) {
message := Message{quitSent: true}
assert.Equal(t, message.quitSent, message.QuitSent())
})
}
func TestMessageIsConsistent(t *testing.T) {
t.Run("when consistent", func(t *testing.T) {
message := &Message{mailfrom: true, rcptto: true, data: true, msg: true}
assert.True(t, message.IsConsistent())
})
t.Run("when not consistent MAILFROM", func(t *testing.T) {
assert.False(t, new(Message).IsConsistent())
})
t.Run("when not consistent RCPTTO", func(t *testing.T) {
message := &Message{mailfrom: true}
assert.False(t, message.IsConsistent())
})
t.Run("when not consistent DATA", func(t *testing.T) {
message := &Message{mailfrom: true, rcptto: true}
assert.False(t, message.IsConsistent())
})
t.Run("when not consistent MSG", func(t *testing.T) {
message := &Message{mailfrom: true, rcptto: true, data: true}
assert.False(t, message.IsConsistent())
})
}
func TestMessagePointerIsConsistent(t *testing.T) {
t.Run("when consistent", func(t *testing.T) {
message := &Message{mailfrom: true, rcptto: true, data: true, msg: true}
assert.True(t, message.isConsistent())
})
t.Run("when not consistent MAILFROM", func(t *testing.T) {
assert.False(t, new(Message).isConsistent())
})
t.Run("when not consistent RCPTTO", func(t *testing.T) {
message := &Message{mailfrom: true}
assert.False(t, message.isConsistent())
})
t.Run("when not consistent DATA", func(t *testing.T) {
message := &Message{mailfrom: true, rcptto: true}
assert.False(t, message.isConsistent())
})
t.Run("when not consistent MSG", func(t *testing.T) {
message := &Message{mailfrom: true, rcptto: true, data: true}
assert.False(t, message.isConsistent())
})
}
func TestMessageIsIncludesSuccessfulRcpttoResponse(t *testing.T) {
targetSuccessfulResponse := "response"
t.Run("when successful RCPTTO response exists", func(t *testing.T) {
message := &Message{rcpttoRequestResponse: [][]string{{"request", targetSuccessfulResponse}}}
assert.True(t, message.isIncludesSuccessfulRcpttoResponse(targetSuccessfulResponse))
})
t.Run("when successful RCPTTO response not exists", func(t *testing.T) {
assert.False(t, new(Message).isIncludesSuccessfulRcpttoResponse(targetSuccessfulResponse))
})
}
func TestMessagesAppend(t *testing.T) {
t.Run("addes message pointer into items slice", func(t *testing.T) {
message, messages := new(Message), new(messages)
messages.append(message)
assert.Same(t, message, messages.items[0])
})
}