Skip to content

Commit

Permalink
NewContext is now public
Browse files Browse the repository at this point in the history
  • Loading branch information
swithek committed Aug 3, 2019
1 parent 1773a29 commit b729ceb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func (m *Manager) wrap(rej func(error) http.Handler, next http.Handler) http.Han
return
}

next.ServeHTTP(w, r.WithContext(newContext(ctx, s)))
next.ServeHTTP(w, r.WithContext(NewContext(ctx, s)))
})
}

Expand Down
18 changes: 9 additions & 9 deletions manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ func TestRevoke(t *testing.T) {
},
"Error returned by store.DeleteByID": {
Store: storeStub(errors.New("error")),
Ctx: newContext(context.Background(), s),
Ctx: NewContext(context.Background(), s),
Checks: checks(
hasErr(true),
hasCookie(false),
Expand All @@ -631,7 +631,7 @@ func TestRevoke(t *testing.T) {
},
"Successful revoke": {
Store: storeStub(nil),
Ctx: newContext(context.Background(), s),
Ctx: NewContext(context.Background(), s),
Checks: checks(
hasErr(false),
hasCookie(true),
Expand Down Expand Up @@ -791,15 +791,15 @@ func TestRevokeOther(t *testing.T) {
},
"Error returned by store.DeleteByUserKey": {
Store: storeStub(errors.New("error")),
Ctx: newContext(context.Background(), s),
Ctx: NewContext(context.Background(), s),
Checks: checks(
hasErr(true),
wasDeleteByUserKeyCalled(1, s.UserKey, s.ID),
),
},
"Successful revoke": {
Store: storeStub(nil),
Ctx: newContext(context.Background(), s),
Ctx: NewContext(context.Background(), s),
Checks: checks(
hasErr(false),
wasDeleteByUserKeyCalled(1, s.UserKey, s.ID),
Expand Down Expand Up @@ -898,7 +898,7 @@ func TestRevokeAll(t *testing.T) {
},
"Error returned by store.DeleteByUserKey": {
Store: storeStub(errors.New("error")),
Ctx: newContext(context.Background(), s),
Ctx: NewContext(context.Background(), s),
Checks: checks(
hasErr(true),
hasCookie(false),
Expand All @@ -907,7 +907,7 @@ func TestRevokeAll(t *testing.T) {
},
"Successful revoke": {
Store: storeStub(nil),
Ctx: newContext(context.Background(), s),
Ctx: NewContext(context.Background(), s),
Checks: checks(
hasErr(false),
hasCookie(true),
Expand Down Expand Up @@ -1085,7 +1085,7 @@ func TestFetchAll(t *testing.T) {
},
"Error returned by store.FetchByUserKey": {
Store: storeStub(nil, errors.New("error")),
Ctx: newContext(context.Background(), curr),
Ctx: NewContext(context.Background(), curr),
Checks: checks(
hasErr(true),
hasSessions(nil, false),
Expand All @@ -1094,7 +1094,7 @@ func TestFetchAll(t *testing.T) {
},
"No sessions found": {
Store: storeStub(nil, nil),
Ctx: newContext(context.Background(), curr),
Ctx: NewContext(context.Background(), curr),
Checks: checks(
hasErr(false),
hasSessions(nil, false),
Expand All @@ -1103,7 +1103,7 @@ func TestFetchAll(t *testing.T) {
},
"Successful fetch": {
Store: storeStub(ss(), nil),
Ctx: newContext(context.Background(), curr),
Ctx: NewContext(context.Background(), curr),
Checks: checks(
hasErr(false),
hasSessions(ss(), true),
Expand Down
4 changes: 2 additions & 2 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ type contextKey int

const sessionKey contextKey = 0

// newContext creates a new context with the provided Session set as
// NewContext creates a new context with the provided Session set as
// a context value.
func newContext(ctx context.Context, s Session) context.Context {
func NewContext(ctx context.Context, s Session) context.Context {
return context.WithValue(ctx, sessionKey, s)
}

Expand Down
2 changes: 1 addition & 1 deletion session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func TestReadIP(t *testing.T) {

func TestNewContext(t *testing.T) {
s := Session{Current: true}
ctx := newContext(context.Background(), s)
ctx := NewContext(context.Background(), s)

cs, ok := ctx.Value(sessionKey).(Session)
if !ok {
Expand Down

0 comments on commit b729ceb

Please sign in to comment.