From 5ccd6b2044cf27ef0ff7767edff94fc62352b288 Mon Sep 17 00:00:00 2001 From: James Hillyerd Date: Tue, 29 Oct 2013 10:27:55 -0700 Subject: [PATCH] Inversion of Control for smtpd.Server Allow more control over how Server is instaniated so that it can be unit tested. --- inbucket.go | 5 ++++- smtpd/listener.go | 4 +--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/inbucket.go b/inbucket.go index 0235011..ddec725 100644 --- a/inbucket.go +++ b/inbucket.go @@ -94,6 +94,9 @@ func main() { fmt.Fprintf(pidf, "%v\n", os.Getpid()) } + // Grab our datastore + ds := smtpd.DefaultFileDataStore() + // Start HTTP server go web.Start() @@ -102,7 +105,7 @@ func main() { go pop3Server.Start() // Startup SMTP server, block until it exits - smtpServer = smtpd.New() + smtpServer = smtpd.NewSmtpServer(config.GetSmtpConfig(), ds) smtpServer.Start() // Wait for active connections to finish diff --git a/smtpd/listener.go b/smtpd/listener.go index b0e40b7..d351c8f 100644 --- a/smtpd/listener.go +++ b/smtpd/listener.go @@ -46,9 +46,7 @@ var expErrorsHist = new(expvar.String) var expWarnsHist = new(expvar.String) // Init a new Server object -func New() *Server { - ds := DefaultFileDataStore() - cfg := config.GetSmtpConfig() +func NewSmtpServer(cfg config.SmtpConfig, ds DataStore) *Server { return &Server{dataStore: ds, domain: cfg.Domain, maxRecips: cfg.MaxRecipients, maxIdleSeconds: cfg.MaxIdleSeconds, maxMessageBytes: cfg.MaxMessageBytes, storeMessages: cfg.StoreMessages, domainNoStore: strings.ToLower(cfg.DomainNoStore),