| OLD | NEW |
| 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 } |
| OLD | NEW |