| Index: common/testing/prpctest/server.go
|
| diff --git a/common/testing/prpctest/server.go b/common/testing/prpctest/server.go
|
| index 670482440596f82ba99e157f6af35790aee079a5..298f5f3459bb80ff30504dc1ad1e98dab6c4c79d 100644
|
| --- a/common/testing/prpctest/server.go
|
| +++ b/common/testing/prpctest/server.go
|
| @@ -5,55 +5,63 @@
|
| // Package prpctest is a package to facilitate pRPC testing by wrapping
|
| // httptest with a pRPC Server.
|
| package prpctest
|
|
|
| import (
|
| "errors"
|
| "fmt"
|
| "net/http/httptest"
|
| "net/url"
|
|
|
| - "github.com/julienschmidt/httprouter"
|
| prpcCommon "github.com/luci/luci-go/common/prpc"
|
| "github.com/luci/luci-go/server/auth"
|
| - "github.com/luci/luci-go/server/middleware"
|
| "github.com/luci/luci-go/server/prpc"
|
| + "github.com/luci/luci-go/server/router"
|
| "golang.org/x/net/context"
|
| )
|
|
|
| // Server is a pRPC test server.
|
| type Server struct {
|
| prpc.Server
|
|
|
| - // Base is the base middleware generator factory. It is handed the Context
|
| - // passed to Start. If nil, middleware.TestingBase will be used.
|
| - Base func(context.Context) middleware.Base
|
| + // Base returns a middleware chain. It is handed the Context passed to
|
| + // Start. If Base is nil, setContext will be used.
|
| + Base func(context.Context) router.MiddlewareChain
|
|
|
| // HTTP is the active HTTP test server. It will be valid when the Server is
|
| // running.
|
| HTTP *httptest.Server
|
| }
|
|
|
| +func setContext(c context.Context) router.MiddlewareChain {
|
| + return router.MiddlewareChain{
|
| + func(ctx *router.Context, next router.Handler) {
|
| + ctx.Context = c
|
| + next(ctx)
|
| + },
|
| + }
|
| +}
|
| +
|
| // Start starts the server. Any currently-registered services will be installed
|
| // into the pRPC Server.
|
| func (s *Server) Start(c context.Context) {
|
| // Clean up any active server.
|
| s.Close()
|
|
|
| s.Authenticator = auth.Authenticator{}
|
| - mwb := s.Base
|
| - if mwb == nil {
|
| - mwb = middleware.TestingBase
|
| + base := s.Base
|
| + if base == nil {
|
| + base = setContext
|
| }
|
|
|
| - r := httprouter.New()
|
| - s.InstallHandlers(r, mwb(c))
|
| + r := router.New()
|
| + s.InstallHandlers(r, base(c))
|
| s.HTTP = httptest.NewServer(r)
|
| }
|
|
|
| // NewClient returns a prpc.Client configured to use the Server.
|
| func (s *Server) NewClient() (*prpcCommon.Client, error) {
|
| if s.HTTP == nil {
|
| return nil, errors.New("not running")
|
| }
|
|
|
| u, err := url.Parse(s.HTTP.URL)
|
|
|