mirror of
https://gitlab.com/ric_harvey/MailHog.git
synced 2025-02-17 08:15:55 +00:00
Add reply struct tests
This commit is contained in:
parent
86a0d413ad
commit
f5a70dd078
3 changed files with 132 additions and 15 deletions
16
bindata.go
16
bindata.go
|
@ -1593,18 +1593,18 @@ type _bintree_t struct {
|
||||||
|
|
||||||
var _bintree = &_bintree_t{nil, map[string]*_bintree_t{
|
var _bintree = &_bintree_t{nil, map[string]*_bintree_t{
|
||||||
"assets": &_bintree_t{nil, map[string]*_bintree_t{
|
"assets": &_bintree_t{nil, map[string]*_bintree_t{
|
||||||
"js": &_bintree_t{nil, map[string]*_bintree_t{
|
|
||||||
"controllers.js": &_bintree_t{assets_js_controllers_js, map[string]*_bintree_t{}},
|
|
||||||
"strutil.js": &_bintree_t{assets_js_strutil_js, map[string]*_bintree_t{}},
|
|
||||||
}},
|
|
||||||
"templates": &_bintree_t{nil, map[string]*_bintree_t{
|
|
||||||
"index.html": &_bintree_t{assets_templates_index_html, map[string]*_bintree_t{}},
|
|
||||||
"layout.html": &_bintree_t{assets_templates_layout_html, map[string]*_bintree_t{}},
|
|
||||||
}},
|
|
||||||
"images": &_bintree_t{nil, map[string]*_bintree_t{
|
"images": &_bintree_t{nil, map[string]*_bintree_t{
|
||||||
"ajax-loader.gif": &_bintree_t{assets_images_ajax_loader_gif, map[string]*_bintree_t{}},
|
"ajax-loader.gif": &_bintree_t{assets_images_ajax_loader_gif, map[string]*_bintree_t{}},
|
||||||
"github.png": &_bintree_t{assets_images_github_png, map[string]*_bintree_t{}},
|
"github.png": &_bintree_t{assets_images_github_png, map[string]*_bintree_t{}},
|
||||||
"hog.png": &_bintree_t{assets_images_hog_png, map[string]*_bintree_t{}},
|
"hog.png": &_bintree_t{assets_images_hog_png, map[string]*_bintree_t{}},
|
||||||
}},
|
}},
|
||||||
|
"js": &_bintree_t{nil, map[string]*_bintree_t{
|
||||||
|
"controllers.js": &_bintree_t{assets_js_controllers_js, map[string]*_bintree_t{}},
|
||||||
|
"strutil.js": &_bintree_t{assets_js_strutil_js, map[string]*_bintree_t{}},
|
||||||
|
}},
|
||||||
|
"templates": &_bintree_t{nil, map[string]*_bintree_t{
|
||||||
|
"layout.html": &_bintree_t{assets_templates_layout_html, map[string]*_bintree_t{}},
|
||||||
|
"index.html": &_bintree_t{assets_templates_index_html, map[string]*_bintree_t{}},
|
||||||
|
}},
|
||||||
}},
|
}},
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
package protocol
|
package protocol
|
||||||
|
|
||||||
import (
|
import "strconv"
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
// http://www.rfc-editor.org/rfc/rfc5321.txt
|
// http://www.rfc-editor.org/rfc/rfc5321.txt
|
||||||
|
|
||||||
|
@ -19,7 +16,7 @@ func (r Reply) Lines() []string {
|
||||||
|
|
||||||
if len(r.lines) == 0 {
|
if len(r.lines) == 0 {
|
||||||
l := strconv.Itoa(r.Status)
|
l := strconv.Itoa(r.Status)
|
||||||
lines = append(lines, l)
|
lines = append(lines, l+"\n")
|
||||||
return lines
|
return lines
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,8 +27,6 @@ func (r Reply) Lines() []string {
|
||||||
} else {
|
} else {
|
||||||
l = strconv.Itoa(r.Status) + "-" + line + "\n"
|
l = strconv.Itoa(r.Status) + "-" + line + "\n"
|
||||||
}
|
}
|
||||||
logText := strings.Replace(l, "\n", "\\n", -1)
|
|
||||||
logText = strings.Replace(logText, "\r", "\\r", -1)
|
|
||||||
lines = append(lines, l)
|
lines = append(lines, l)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
122
mailhog/smtp/protocol/reply_test.go
Normal file
122
mailhog/smtp/protocol/reply_test.go
Normal file
|
@ -0,0 +1,122 @@
|
||||||
|
package protocol
|
||||||
|
|
||||||
|
// 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{}}
|
||||||
|
l := r.Lines()
|
||||||
|
So(l[0], ShouldEqual, "200\n")
|
||||||
|
|
||||||
|
r = &Reply{200, []string{"Ok"}}
|
||||||
|
l = r.Lines()
|
||||||
|
So(l[0], ShouldEqual, "200 Ok\n")
|
||||||
|
|
||||||
|
r = &Reply{200, []string{"Ok", "Still ok!"}}
|
||||||
|
l = r.Lines()
|
||||||
|
So(l[0], ShouldEqual, "200-Ok\n")
|
||||||
|
So(l[1], ShouldEqual, "200 Still ok!\n")
|
||||||
|
|
||||||
|
r = &Reply{200, []string{"Ok", "Still ok!", "OINK!"}}
|
||||||
|
l = r.Lines()
|
||||||
|
So(l[0], ShouldEqual, "200-Ok\n")
|
||||||
|
So(l[1], ShouldEqual, "200-Still ok!\n")
|
||||||
|
So(l[2], ShouldEqual, "200 OINK!\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")
|
||||||
|
})
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue