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

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: gaemiddleware: add middleware func for WithProd 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
« no previous file with comments | « appengine/gaemiddleware/routes.go ('k') | appengine/logdog/coordinator/config/middleware.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
16 "github.com/luci/luci-go/server/secrets/testsecrets" 12 "github.com/luci/luci-go/server/secrets/testsecrets"
17 ) 13 )
18 14
19 // BaseTest adapts a middleware-style handler to a httprouter.Handle. It passes 15 // TestingContext returns context with base services installed:
20 // a new context to `h` with the following services installed:
21 // * github.com/luci/gae/impl/memory (in-memory appengine services) 16 // * github.com/luci/gae/impl/memory (in-memory appengine services)
22 // * github.com/luci/luci-go/server/secrets/testsecrets (access to fake secret keys) 17 // * github.com/luci/luci-go/server/secrets/testsecrets (access to fake secret keys)
23 func BaseTest(h middleware.Handler) httprouter.Handle {
24 return func(rw http.ResponseWriter, r *http.Request, p httprouter.Params ) {
25 h(TestingContext(), rw, r, p)
26 }
27 }
28
29 // TestingContext returns context with base services installed.
30 func TestingContext() context.Context { 18 func TestingContext() context.Context {
31 c := context.Background() 19 c := context.Background()
32 c = memory.Use(c) 20 c = memory.Use(c)
33 c = testsecrets.Use(c) 21 c = testsecrets.Use(c)
34 c = proccache.Use(c, &proccache.Cache{}) 22 c = proccache.Use(c, &proccache.Cache{})
35 return c 23 return c
36 } 24 }
OLDNEW
« no previous file with comments | « appengine/gaemiddleware/routes.go ('k') | appengine/logdog/coordinator/config/middleware.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698