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:
@@ -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 {
|
||||
|
||||
@@ -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"))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user