| 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 coordinatorTest | 5 package coordinatorTest |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | 8 "fmt" |
| 9 "strings" | 9 "strings" |
| 10 "time" | 10 "time" |
| 11 | 11 |
| 12 ds "github.com/luci/gae/service/datastore" | |
| 13 "github.com/luci/gae/service/info" | |
| 14 "github.com/luci/luci-go/common/clock" | 12 "github.com/luci/luci-go/common/clock" |
| 15 "github.com/luci/luci-go/common/clock/testclock" | 13 "github.com/luci/luci-go/common/clock/testclock" |
| 16 luciConfig "github.com/luci/luci-go/common/config" | 14 luciConfig "github.com/luci/luci-go/common/config" |
| 17 "github.com/luci/luci-go/common/config/impl/memory" | 15 "github.com/luci/luci-go/common/config/impl/memory" |
| 18 "github.com/luci/luci-go/common/data/caching/cacheContext" | 16 "github.com/luci/luci-go/common/data/caching/cacheContext" |
| 19 "github.com/luci/luci-go/common/gcloud/gs" | 17 "github.com/luci/luci-go/common/gcloud/gs" |
| 20 "github.com/luci/luci-go/common/logging" | 18 "github.com/luci/luci-go/common/logging" |
| 21 "github.com/luci/luci-go/common/logging/gologger" | 19 "github.com/luci/luci-go/common/logging/gologger" |
| 22 "github.com/luci/luci-go/common/proto/google" | 20 "github.com/luci/luci-go/common/proto/google" |
| 23 "github.com/luci/luci-go/logdog/api/config/svcconfig" | 21 "github.com/luci/luci-go/logdog/api/config/svcconfig" |
| 24 "github.com/luci/luci-go/logdog/appengine/coordinator" | 22 "github.com/luci/luci-go/logdog/appengine/coordinator" |
| 25 "github.com/luci/luci-go/logdog/appengine/coordinator/config" | 23 "github.com/luci/luci-go/logdog/appengine/coordinator/config" |
| 26 » "github.com/luci/luci-go/logdog/common/storage" | 24 » "github.com/luci/luci-go/logdog/common/storage/caching" |
| 27 » memoryStorage "github.com/luci/luci-go/logdog/common/storage/memory" | |
| 28 "github.com/luci/luci-go/server/auth" | 25 "github.com/luci/luci-go/server/auth" |
| 29 "github.com/luci/luci-go/server/auth/authtest" | 26 "github.com/luci/luci-go/server/auth/authtest" |
| 30 "github.com/luci/luci-go/server/auth/identity" | 27 "github.com/luci/luci-go/server/auth/identity" |
| 31 "github.com/luci/luci-go/server/settings" | 28 "github.com/luci/luci-go/server/settings" |
| 32 "github.com/luci/luci-go/tumble" | 29 "github.com/luci/luci-go/tumble" |
| 33 | 30 |
| 31 ds "github.com/luci/gae/service/datastore" |
| 32 "github.com/luci/gae/service/info" |
| 33 |
| 34 "github.com/golang/protobuf/proto" | 34 "github.com/golang/protobuf/proto" |
| 35 "golang.org/x/net/context" | 35 "golang.org/x/net/context" |
| 36 ) | 36 ) |
| 37 | 37 |
| 38 // Environment contains all of the testing facilities that are installed into | 38 // Environment contains all of the testing facilities that are installed into |
| 39 // the Context. | 39 // the Context. |
| 40 type Environment struct { | 40 type Environment struct { |
| 41 // Tumble is the Tumble testing instance. | 41 // Tumble is the Tumble testing instance. |
| 42 Tumble tumble.Testing | 42 Tumble tumble.Testing |
| 43 | 43 |
| 44 // Clock is the installed test clock instance. | 44 // Clock is the installed test clock instance. |
| 45 Clock testclock.TestClock | 45 Clock testclock.TestClock |
| 46 | 46 |
| 47 // AuthState is the fake authentication state. | 47 // AuthState is the fake authentication state. |
| 48 AuthState authtest.FakeState | 48 AuthState authtest.FakeState |
| 49 | 49 |
| 50 // Config is the luci-config configuration map that is installed. | 50 // Config is the luci-config configuration map that is installed. |
| 51 Config map[string]memory.ConfigSet | 51 Config map[string]memory.ConfigSet |
| 52 // ConfigIface is a reference to the memory config.Interface that Config
is | 52 // ConfigIface is a reference to the memory config.Interface that Config
is |
| 53 // installed into. | 53 // installed into. |
| 54 ConfigIface luciConfig.Interface | 54 ConfigIface luciConfig.Interface |
| 55 | 55 |
| 56 // Services is the set of installed Coordinator services. | 56 // Services is the set of installed Coordinator services. |
| 57 Services Services | 57 Services Services |
| 58 | 58 |
| 59 // IntermediateStorage is the memory Intermediate Storage instance | |
| 60 // installed (by default) into Services. | |
| 61 IntermediateStorage memoryStorage.Storage | |
| 62 // GSClient is the test GSClient instance installed (by default) into | 59 // GSClient is the test GSClient instance installed (by default) into |
| 63 // Services. | 60 // Services. |
| 64 GSClient GSClient | 61 GSClient GSClient |
| 65 // ArchivalPublisher is the test ArchivalPublisher instance installed (b
y | 62 // ArchivalPublisher is the test ArchivalPublisher instance installed (b
y |
| 66 // default) into Services. | 63 // default) into Services. |
| 67 ArchivalPublisher ArchivalPublisher | 64 ArchivalPublisher ArchivalPublisher |
| 65 |
| 66 // StorageCache is the default storage cache instance. |
| 67 StorageCache StorageCache |
| 68 } | 68 } |
| 69 | 69 |
| 70 // LogIn installs an testing identity into the testing auth state. | 70 // LogIn installs an testing identity into the testing auth state. |
| 71 func (e *Environment) LogIn() { | 71 func (e *Environment) LogIn() { |
| 72 id, err := identity.MakeIdentity("user:testing@example.com") | 72 id, err := identity.MakeIdentity("user:testing@example.com") |
| 73 if err != nil { | 73 if err != nil { |
| 74 panic(err) | 74 panic(err) |
| 75 } | 75 } |
| 76 e.AuthState.Identity = id | 76 e.AuthState.Identity = id |
| 77 } | 77 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 cset = make(map[string]string) | 157 cset = make(map[string]string) |
| 158 e.Config[configSet] = cset | 158 e.Config[configSet] = cset |
| 159 } | 159 } |
| 160 cset[path] = content | 160 cset[path] = content |
| 161 } | 161 } |
| 162 | 162 |
| 163 // Install creates a testing Context and installs common test facilities into | 163 // Install creates a testing Context and installs common test facilities into |
| 164 // it, returning the Environment to which they're bound. | 164 // it, returning the Environment to which they're bound. |
| 165 func Install() (context.Context, *Environment) { | 165 func Install() (context.Context, *Environment) { |
| 166 e := Environment{ | 166 e := Environment{ |
| 167 » » Config: make(map[string]memory.ConfigSet), | 167 » » Config: make(map[string]memory.ConfigSet), |
| 168 » » GSClient: GSClient{}, |
| 169 » » StorageCache: StorageCache{ |
| 170 » » » Base: &coordinator.StorageCache{}, |
| 171 » » }, |
| 168 } | 172 } |
| 169 | 173 |
| 170 // Get our starting context. This installs, among other things, in-memor
y | 174 // Get our starting context. This installs, among other things, in-memor
y |
| 171 // gae, settings, and logger. | 175 // gae, settings, and logger. |
| 172 c := e.Tumble.Context() | 176 c := e.Tumble.Context() |
| 173 if *testGoLogger { | 177 if *testGoLogger { |
| 174 c = logging.SetLevel(gologger.StdConfig.Use(c), logging.Debug) | 178 c = logging.SetLevel(gologger.StdConfig.Use(c), logging.Debug) |
| 175 } | 179 } |
| 176 | 180 |
| 177 // Add indexes. These should match the indexes defined in the applicatio
n's | 181 // Add indexes. These should match the indexes defined in the applicatio
n's |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 e.Tumble.UpdateSettings(c, tcfg) | 276 e.Tumble.UpdateSettings(c, tcfg) |
| 273 | 277 |
| 274 // Install authentication state. | 278 // Install authentication state. |
| 275 c = auth.WithState(c, &e.AuthState) | 279 c = auth.WithState(c, &e.AuthState) |
| 276 | 280 |
| 277 // Setup authentication state. | 281 // Setup authentication state. |
| 278 e.LeaveAllGroups() | 282 e.LeaveAllGroups() |
| 279 | 283 |
| 280 // Setup our default Coordinator services. | 284 // Setup our default Coordinator services. |
| 281 e.Services = Services{ | 285 e.Services = Services{ |
| 282 IS: func() (storage.Storage, error) { | |
| 283 return &e.IntermediateStorage, nil | |
| 284 }, | |
| 285 GS: func() (gs.Client, error) { | 286 GS: func() (gs.Client, error) { |
| 286 return &e.GSClient, nil | 287 return &e.GSClient, nil |
| 287 }, | 288 }, |
| 288 AP: func() (coordinator.ArchivalPublisher, error) { | 289 AP: func() (coordinator.ArchivalPublisher, error) { |
| 289 return &e.ArchivalPublisher, nil | 290 return &e.ArchivalPublisher, nil |
| 290 }, | 291 }, |
| 292 SC: func() caching.Cache { |
| 293 return &e.StorageCache |
| 294 }, |
| 291 } | 295 } |
| 292 c = coordinator.WithServices(c, &e.Services) | 296 c = coordinator.WithServices(c, &e.Services) |
| 293 | 297 |
| 294 return cacheContext.Wrap(c), &e | 298 return cacheContext.Wrap(c), &e |
| 295 } | 299 } |
| 296 | 300 |
| 297 // WithProjectNamespace runs f in proj's namespace, bypassing authentication | 301 // WithProjectNamespace runs f in proj's namespace, bypassing authentication |
| 298 // checks. | 302 // checks. |
| 299 func WithProjectNamespace(c context.Context, proj luciConfig.ProjectName, f func
(context.Context)) { | 303 func WithProjectNamespace(c context.Context, proj luciConfig.ProjectName, f func
(context.Context)) { |
| 300 if err := coordinator.WithProjectNamespace(&c, proj, coordinator.Namespa
ceAccessAllTesting); err != nil { | 304 if err := coordinator.WithProjectNamespace(&c, proj, coordinator.Namespa
ceAccessAllTesting); err != nil { |
| 301 panic(err) | 305 panic(err) |
| 302 } | 306 } |
| 303 f(c) | 307 f(c) |
| 304 } | 308 } |
| OLD | NEW |