cherrypick: ts.User is now pointer

This commit is contained in:
cblgh 2021-04-23 13:25:13 +02:00
parent 57c1375e54
commit 80686dec26
2 changed files with 7 additions and 3 deletions

View File

@ -99,6 +99,10 @@ func newSession(t *testing.T) *testSession {
ts.User = roomdb.Member{
ID: 1234,
Role: roomdb.RoleModerator,
PubKey: refs.FeedRef{
ID: bytes.Repeat([]byte("0"), 32),
Algo: "ed25519",
},
}
testPath := filepath.Join("testrun", t.Name())
@ -174,7 +178,7 @@ func newSession(t *testing.T) *testSession {
},
)
handler = members.MiddlewareForTests(ts.User)(handler)
handler = members.MiddlewareForTests(&ts.User)(handler)
ts.Mux = http.NewServeMux()
ts.Mux.Handle("/", handler)

View File

@ -13,10 +13,10 @@ import (
// This is part of testing.go because we need to use roomMemberContextKey, which shouldn't be exported either.
// TODO: could be protected with an extra build tag.
// (Sadly +build test does not exist https://github.com/golang/go/issues/21360 )
func MiddlewareForTests(m roomdb.Member) func(http.Handler) http.Handler {
func MiddlewareForTests(m *roomdb.Member) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
ctx := context.WithValue(req.Context(), roomMemberContextKey, &m)
ctx := context.WithValue(req.Context(), roomMemberContextKey, m)
next.ServeHTTP(w, req.WithContext(ctx))
})
}