Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: appengine/gaetesting/middleware.go

Issue 2043423004: Make HTTP middleware easier to use (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: Update tests Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package gaetesting 5 package gaetesting
6 6
7 import ( 7 import (
8 "net/http"
9
10 "github.com/julienschmidt/httprouter"
11 "golang.org/x/net/context" 8 "golang.org/x/net/context"
12 9
13 "github.com/luci/gae/impl/memory" 10 "github.com/luci/gae/impl/memory"
14 "github.com/luci/luci-go/server/middleware"
15 "github.com/luci/luci-go/server/proccache" 11 "github.com/luci/luci-go/server/proccache"
12 "github.com/luci/luci-go/server/router"
16 "github.com/luci/luci-go/server/secrets/testsecrets" 13 "github.com/luci/luci-go/server/secrets/testsecrets"
17 ) 14 )
18 15
19 // BaseTest adapts a middleware-style handler to a httprouter.Handle. It passes 16 // BaseTest adapts a middleware-style handler to a httprouter.Handle. It passes
20 // a new context to `h` with the following services installed: 17 // a new context to `h` with the following services installed:
21 // * github.com/luci/gae/impl/memory (in-memory appengine services) 18 // * github.com/luci/gae/impl/memory (in-memory appengine services)
22 // * github.com/luci/luci-go/server/secrets/testsecrets (access to fake secret keys) 19 // * github.com/luci/luci-go/server/secrets/testsecrets (access to fake secret keys)
23 func BaseTest(h middleware.Handler) httprouter.Handle { 20 func BaseTest() router.Handler {
24 » return func(rw http.ResponseWriter, r *http.Request, p httprouter.Params ) { 21 » return func(c *router.Context) {
25 » » h(TestingContext(), rw, r, p) 22 » » c.Context = TestingContext()
26 } 23 }
27 } 24 }
28 25
29 // TestingContext returns context with base services installed. 26 // TestingContext returns context with base services installed.
30 func TestingContext() context.Context { 27 func TestingContext() context.Context {
31 c := context.Background() 28 c := context.Background()
32 c = memory.Use(c) 29 c = memory.Use(c)
33 c = testsecrets.Use(c) 30 c = testsecrets.Use(c)
34 c = proccache.Use(c, &proccache.Cache{}) 31 c = proccache.Use(c, &proccache.Cache{})
35 return c 32 return c
36 } 33 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698