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) {
|
func NewContext(req *http.Request) (*Context, error) {
|
||||||
vars := mux.Vars(req)
|
vars := mux.Vars(req)
|
||||||
sess, err := sessionStore.Get(req, "inbucket")
|
sess, err := sessionStore.Get(req, "inbucket")
|
||||||
ds := smtpd.DefaultFileDataStore()
|
|
||||||
ctx := &Context{
|
ctx := &Context{
|
||||||
Vars: vars,
|
Vars: vars,
|
||||||
Session: sess,
|
Session: sess,
|
||||||
DataStore: ds,
|
DataStore: DataStore,
|
||||||
IsJson: headerMatch(req, "Accept", "application/json"),
|
IsJson: headerMatch(req, "Accept", "application/json"),
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/gorilla/sessions"
|
"github.com/gorilla/sessions"
|
||||||
"github.com/jhillyerd/inbucket/config"
|
"github.com/jhillyerd/inbucket/config"
|
||||||
"github.com/jhillyerd/inbucket/log"
|
"github.com/jhillyerd/inbucket/log"
|
||||||
|
"github.com/jhillyerd/inbucket/smtpd"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
@@ -17,6 +18,7 @@ import (
|
|||||||
|
|
||||||
type handler func(http.ResponseWriter, *http.Request, *Context) error
|
type handler func(http.ResponseWriter, *http.Request, *Context) error
|
||||||
|
|
||||||
|
var DataStore smtpd.DataStore
|
||||||
var Router *mux.Router
|
var Router *mux.Router
|
||||||
var listener net.Listener
|
var listener net.Listener
|
||||||
var sessionStore sessions.Store
|
var sessionStore sessions.Store
|
||||||
@@ -55,6 +57,9 @@ func Start() {
|
|||||||
cfg := config.GetWebConfig()
|
cfg := config.GetWebConfig()
|
||||||
setupRoutes(cfg)
|
setupRoutes(cfg)
|
||||||
|
|
||||||
|
// NewContext() will use this DataStore for the web handlers
|
||||||
|
DataStore = smtpd.DefaultFileDataStore()
|
||||||
|
|
||||||
// TODO Make configurable
|
// TODO Make configurable
|
||||||
sessionStore = sessions.NewCookieStore([]byte("something-very-secret"))
|
sessionStore = sessions.NewCookieStore([]byte("something-very-secret"))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user