| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package gaetesting | 5 package gaetesting |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "net/http" | 8 "net/http" |
| 9 | 9 |
| 10 "github.com/julienschmidt/httprouter" | 10 "github.com/julienschmidt/httprouter" |
| 11 "github.com/luci/gae/impl/memory" | 11 "github.com/luci/gae/impl/memory" |
| 12 "github.com/luci/luci-go/common/logging/memlogger" | |
| 13 "github.com/luci/luci-go/server/middleware" | 12 "github.com/luci/luci-go/server/middleware" |
| 14 "github.com/luci/luci-go/server/secrets/testsecrets" | 13 "github.com/luci/luci-go/server/secrets/testsecrets" |
| 15 "golang.org/x/net/context" | 14 "golang.org/x/net/context" |
| 16 ) | 15 ) |
| 17 | 16 |
| 18 // BaseTest adapts a middleware-style handler to a httprouter.Handle. It passes | 17 // BaseTest adapts a middleware-style handler to a httprouter.Handle. It passes |
| 19 // a new context to `h` with the following services installed: | 18 // a new context to `h` with the following services installed: |
| 20 // * github.com/luci/gae/impl/memory (in-memory appengine services) | 19 // * github.com/luci/gae/impl/memory (in-memory appengine services) |
| 21 // * github.com/luci/luci-go/common/logging/memlogger (in-memory logging servi
ce) | |
| 22 // * github.com/luci/luci-go/server/secrets/testsecrets (access to fake secret
keys) | 20 // * github.com/luci/luci-go/server/secrets/testsecrets (access to fake secret
keys) |
| 23 func BaseTest(h middleware.Handler) httprouter.Handle { | 21 func BaseTest(h middleware.Handler) httprouter.Handle { |
| 24 return func(rw http.ResponseWriter, r *http.Request, p httprouter.Params
) { | 22 return func(rw http.ResponseWriter, r *http.Request, p httprouter.Params
) { |
| 25 h(TestingContext(), rw, r, p) | 23 h(TestingContext(), rw, r, p) |
| 26 } | 24 } |
| 27 } | 25 } |
| 28 | 26 |
| 29 // TestingContext returns context with base services installed. | 27 // TestingContext returns context with base services installed. |
| 30 func TestingContext() context.Context { | 28 func TestingContext() context.Context { |
| 31 c := context.Background() | 29 c := context.Background() |
| 32 c = memory.Use(c) | 30 c = memory.Use(c) |
| 33 c = memlogger.Use(c) | |
| 34 c = testsecrets.Use(c) | 31 c = testsecrets.Use(c) |
| 35 return c | 32 return c |
| 36 } | 33 } |
| OLD | NEW |