1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-17 09:37:02 +00:00

Make it possible to inject web DataStore for tests

This commit is contained in:
James Hillyerd
2013-11-07 10:56:50 -08:00
parent d80521b24d
commit 0f1e75b473
2 changed files with 6 additions and 2 deletions

View File

@@ -39,11 +39,10 @@ func headerMatch(req *http.Request, name string, value string) bool {
func NewContext(req *http.Request) (*Context, error) {
vars := mux.Vars(req)
sess, err := sessionStore.Get(req, "inbucket")
ds := smtpd.DefaultFileDataStore()
ctx := &Context{
Vars: vars,
Session: sess,
DataStore: ds,
DataStore: DataStore,
IsJson: headerMatch(req, "Accept", "application/json"),
}
if err != nil {

View File

@@ -10,6 +10,7 @@ import (
"github.com/gorilla/sessions"
"github.com/jhillyerd/inbucket/config"
"github.com/jhillyerd/inbucket/log"
"github.com/jhillyerd/inbucket/smtpd"
"net"
"net/http"
"time"
@@ -17,6 +18,7 @@ import (
type handler func(http.ResponseWriter, *http.Request, *Context) error
var DataStore smtpd.DataStore
var Router *mux.Router
var listener net.Listener
var sessionStore sessions.Store
@@ -55,6 +57,9 @@ func Start() {
cfg := config.GetWebConfig()
setupRoutes(cfg)
// NewContext() will use this DataStore for the web handlers
DataStore = smtpd.DefaultFileDataStore()
// TODO Make configurable
sessionStore = sessions.NewCookieStore([]byte("something-very-secret"))