-
Notifications
You must be signed in to change notification settings - Fork 33
/
reply_test.go
122 lines (102 loc) · 3.23 KB
/
reply_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
package smtp
// http://www.rfc-editor.org/rfc/rfc5321.txt
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestReply(t *testing.T) {
Convey("Reply creates properly formatted responses", t, func() {
r := &Reply{200, []string{}, nil}
l := r.Lines()
So(l[0], ShouldEqual, "200\n")
r = &Reply{200, []string{"Ok"}, nil}
l = r.Lines()
So(l[0], ShouldEqual, "200 Ok\r\n")
r = &Reply{200, []string{"Ok", "Still ok!"}, nil}
l = r.Lines()
So(l[0], ShouldEqual, "200-Ok\r\n")
So(l[1], ShouldEqual, "200 Still ok!\r\n")
r = &Reply{200, []string{"Ok", "Still ok!", "OINK!"}, nil}
l = r.Lines()
So(l[0], ShouldEqual, "200-Ok\r\n")
So(l[1], ShouldEqual, "200-Still ok!\r\n")
So(l[2], ShouldEqual, "200 OINK!\r\n")
})
}
func TestBuiltInReplies(t *testing.T) {
Convey("ReplyIdent is correct", t, func() {
r := ReplyIdent("oink")
So(r.Status, ShouldEqual, 220)
So(len(r.lines), ShouldEqual, 1)
So(r.lines[0], ShouldEqual, "oink")
})
Convey("ReplyBye is correct", t, func() {
r := ReplyBye()
So(r.Status, ShouldEqual, 221)
So(len(r.lines), ShouldEqual, 1)
So(r.lines[0], ShouldEqual, "Bye")
})
Convey("ReplyAuthOk is correct", t, func() {
r := ReplyAuthOk()
So(r.Status, ShouldEqual, 235)
So(len(r.lines), ShouldEqual, 1)
So(r.lines[0], ShouldEqual, "Authentication successful")
})
Convey("ReplyOk is correct", t, func() {
r := ReplyOk()
So(r.Status, ShouldEqual, 250)
So(len(r.lines), ShouldEqual, 1)
So(r.lines[0], ShouldEqual, "Ok")
r = ReplyOk("oink")
So(r.Status, ShouldEqual, 250)
So(len(r.lines), ShouldEqual, 1)
So(r.lines[0], ShouldEqual, "oink")
r = ReplyOk("mailhog", "OINK!")
So(r.Status, ShouldEqual, 250)
So(len(r.lines), ShouldEqual, 2)
So(r.lines[0], ShouldEqual, "mailhog")
So(r.lines[1], ShouldEqual, "OINK!")
})
Convey("ReplySenderOk is correct", t, func() {
r := ReplySenderOk("test")
So(r.Status, ShouldEqual, 250)
So(len(r.lines), ShouldEqual, 1)
So(r.lines[0], ShouldEqual, "Sender test ok")
})
Convey("ReplyRecipientOk is correct", t, func() {
r := ReplyRecipientOk("test")
So(r.Status, ShouldEqual, 250)
So(len(r.lines), ShouldEqual, 1)
So(r.lines[0], ShouldEqual, "Recipient test ok")
})
Convey("ReplyAuthResponse is correct", t, func() {
r := ReplyAuthResponse("test")
So(r.Status, ShouldEqual, 334)
So(len(r.lines), ShouldEqual, 1)
So(r.lines[0], ShouldEqual, "test")
})
Convey("ReplyDataResponse is correct", t, func() {
r := ReplyDataResponse()
So(r.Status, ShouldEqual, 354)
So(len(r.lines), ShouldEqual, 1)
So(r.lines[0], ShouldEqual, "End data with <CR><LF>.<CR><LF>")
})
Convey("ReplyStorageFailed is correct", t, func() {
r := ReplyStorageFailed("test")
So(r.Status, ShouldEqual, 452)
So(len(r.lines), ShouldEqual, 1)
So(r.lines[0], ShouldEqual, "test")
})
Convey("ReplyUnrecognisedCommand is correct", t, func() {
r := ReplyUnrecognisedCommand()
So(r.Status, ShouldEqual, 500)
So(len(r.lines), ShouldEqual, 1)
So(r.lines[0], ShouldEqual, "Unrecognised command")
})
Convey("ReplyUnsupportedAuth is correct", t, func() {
r := ReplyUnsupportedAuth()
So(r.Status, ShouldEqual, 504)
So(len(r.lines), ShouldEqual, 1)
So(r.lines[0], ShouldEqual, "Unsupported authentication mechanism")
})
}