This commit is contained in:
Ian Kent 2014-04-20 17:12:32 +01:00
parent ecf4d071c2
commit 9868f1f7f6
2 changed files with 26 additions and 26 deletions

22
main.go
View file

@ -2,12 +2,12 @@ package main
import ( import (
"flag" "flag"
"log"
"net"
"os"
"github.com/ian-kent/MailHog/mailhog" "github.com/ian-kent/MailHog/mailhog"
"github.com/ian-kent/MailHog/mailhog/http" "github.com/ian-kent/MailHog/mailhog/http"
"github.com/ian-kent/MailHog/mailhog/smtp" "github.com/ian-kent/MailHog/mailhog/smtp"
"log"
"net"
"os"
) )
var conf *mailhog.Config var conf *mailhog.Config
@ -28,10 +28,10 @@ func config() {
conf = &mailhog.Config{ conf = &mailhog.Config{
SMTPBindAddr: smtpbindaddr, SMTPBindAddr: smtpbindaddr,
HTTPBindAddr: httpbindaddr, HTTPBindAddr: httpbindaddr,
Hostname: hostname, Hostname: hostname,
MongoUri: mongouri, MongoUri: mongouri,
MongoDb: mongodb, MongoDb: mongodb,
MongoColl: mongocoll, MongoColl: mongocoll,
} }
} }
@ -44,9 +44,9 @@ func main() {
for { for {
select { select {
case <-exitCh: case <-exitCh:
log.Printf("Received exit signal") log.Printf("Received exit signal")
os.Exit(0) os.Exit(0)
} }
} }
} }
@ -56,7 +56,7 @@ func web_listen() {
http.Start(exitCh, conf) http.Start(exitCh, conf)
} }
func smtp_listen() (*net.TCPListener) { func smtp_listen() *net.TCPListener {
log.Printf("[SMTP] Binding to address: %s\n", conf.SMTPBindAddr) log.Printf("[SMTP] Binding to address: %s\n", conf.SMTPBindAddr)
ln, err := net.Listen("tcp", conf.SMTPBindAddr) ln, err := net.Listen("tcp", conf.SMTPBindAddr)
if err != nil { if err != nil {

View file

@ -1,13 +1,13 @@
package main package main
import ( import (
"testing"
"github.com/stretchr/testify/assert"
"net"
"strings"
"regexp"
"github.com/ian-kent/MailHog/mailhog" "github.com/ian-kent/MailHog/mailhog"
"github.com/ian-kent/MailHog/mailhog/storage" "github.com/ian-kent/MailHog/mailhog/storage"
"github.com/stretchr/testify/assert"
"net"
"regexp"
"strings"
"testing"
) )
// FIXME requires a running instance of MailHog // FIXME requires a running instance of MailHog
@ -108,9 +108,9 @@ func TestBasicHappyPath(t *testing.T) {
assert.Equal(t, message.Content.Headers["Content-Length"], []string{"220"}, "Content-Length is 220") assert.Equal(t, message.Content.Headers["Content-Length"], []string{"220"}, "Content-Length is 220")
assert.Equal(t, message.Content.Headers["To"], []string{"Someone <someone@mailhog.example>"}, "To is Someone <someone@mailhog.example>") assert.Equal(t, message.Content.Headers["To"], []string{"Someone <someone@mailhog.example>"}, "To is Someone <someone@mailhog.example>")
assert.Equal(t, message.Content.Headers["From"], []string{"Nobody <nobody@mailhog.example>"}, "From is Nobody <nobody@mailhog.example>") assert.Equal(t, message.Content.Headers["From"], []string{"Nobody <nobody@mailhog.example>"}, "From is Nobody <nobody@mailhog.example>")
assert.True(t, strings.HasPrefix(message.Content.Headers["Received"][0], "from localhost by mailhog.example (Go-MailHog)\r\n id " + match[1] + "@mailhog.example; "), "Received header is correct") assert.True(t, strings.HasPrefix(message.Content.Headers["Received"][0], "from localhost by mailhog.example (Go-MailHog)\r\n id "+match[1]+"@mailhog.example; "), "Received header is correct")
assert.Equal(t, message.Content.Headers["Return-Path"], []string{"<nobody@mailhog.example>"}, "Return-Path is <nobody@mailhog.example>") assert.Equal(t, message.Content.Headers["Return-Path"], []string{"<nobody@mailhog.example>"}, "Return-Path is <nobody@mailhog.example>")
assert.Equal(t, message.Content.Headers["Message-ID"], []string{match[1] + "@mailhog.example"}, "Message-ID is " + match[1] + "@mailhog.example") assert.Equal(t, message.Content.Headers["Message-ID"], []string{match[1] + "@mailhog.example"}, "Message-ID is "+match[1]+"@mailhog.example")
assert.Equal(t, message.Content.Body, "Hi there :)", "message has correct body") assert.Equal(t, message.Content.Body, "Hi there :)", "message has correct body")
} }