Skip to content

Commit

Permalink
Fix SCS with all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhu committed Jun 28, 2017
1 parent 121159e commit 09ae3de
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
10 changes: 8 additions & 2 deletions scs/scs.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,18 @@ func (scs SCS) Flashes(req *http.Request) []session.Message {

func (scs SCS) Load(req *http.Request, key string, result interface{}) error {
value := scs.Get(req, key)
return json.Unmarshal([]byte(value), result)
if value != "" {
return json.Unmarshal([]byte(value), result)
}
return nil
}

func (scs SCS) PopLoad(req *http.Request, key string, result interface{}) error {
value := scs.Pop(req, key)
return json.Unmarshal([]byte(value), result)
if value != "" {
return json.Unmarshal([]byte(value), result)
}
return nil
}

func (scs SCS) Middleware(handler http.Handler) http.Handler {
Expand Down
18 changes: 16 additions & 2 deletions test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,25 @@ func (site Site) ServeHTTP(w http.ResponseWriter, req *http.Request) {
}
}

type server struct {
req *http.Request
}

func (s *server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
s.req = r
}

func TestAll(manager session.ManagerInterface, t *testing.T) {
Server = httptest.NewServer(manager.Middleware(Site{SessionManager: manager}))
newReq := func() *http.Request {
req, _ := http.NewRequest("GET", "/", nil)
return req
var (
req, _ = http.NewRequest("GET", "/", nil)
w = httptest.NewRecorder()
)

s := &server{}
manager.Middleware(s).ServeHTTP(w, req)
return s.req
}

TestWithRequest(manager, t)
Expand Down

0 comments on commit 09ae3de

Please sign in to comment.