| 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 "github.com/luci/luci-go/common/clock" | 12 "github.com/luci/luci-go/common/clock" |
| 13 "github.com/luci/luci-go/common/clock/testclock" | 13 "github.com/luci/luci-go/common/clock/testclock" |
| 14 luciConfig "github.com/luci/luci-go/common/config" | 14 luciConfig "github.com/luci/luci-go/common/config" |
| 15 "github.com/luci/luci-go/common/config/impl/memory" | 15 "github.com/luci/luci-go/common/config/impl/memory" |
| 16 "github.com/luci/luci-go/common/data/caching/cacheContext" | 16 "github.com/luci/luci-go/common/data/caching/cacheContext" |
| 17 "github.com/luci/luci-go/common/gcloud/gs" | 17 "github.com/luci/luci-go/common/gcloud/gs" |
| 18 "github.com/luci/luci-go/common/logging" | 18 "github.com/luci/luci-go/common/logging" |
| 19 "github.com/luci/luci-go/common/logging/gologger" | 19 "github.com/luci/luci-go/common/logging/gologger" |
| 20 "github.com/luci/luci-go/common/proto/google" | 20 "github.com/luci/luci-go/common/proto/google" |
| 21 "github.com/luci/luci-go/logdog/api/config/svcconfig" | 21 "github.com/luci/luci-go/logdog/api/config/svcconfig" |
| 22 "github.com/luci/luci-go/logdog/appengine/coordinator" | 22 "github.com/luci/luci-go/logdog/appengine/coordinator" |
| 23 "github.com/luci/luci-go/logdog/appengine/coordinator/config" | 23 "github.com/luci/luci-go/logdog/appengine/coordinator/config" |
| 24 » "github.com/luci/luci-go/logdog/common/storage/caching" | 24 » "github.com/luci/luci-go/logdog/common/storage/archive" |
| 25 » "github.com/luci/luci-go/logdog/common/storage/bigtable" |
| 25 "github.com/luci/luci-go/server/auth" | 26 "github.com/luci/luci-go/server/auth" |
| 26 "github.com/luci/luci-go/server/auth/authtest" | 27 "github.com/luci/luci-go/server/auth/authtest" |
| 27 "github.com/luci/luci-go/server/auth/identity" | 28 "github.com/luci/luci-go/server/auth/identity" |
| 28 "github.com/luci/luci-go/server/settings" | 29 "github.com/luci/luci-go/server/settings" |
| 29 "github.com/luci/luci-go/tumble" | 30 "github.com/luci/luci-go/tumble" |
| 30 | 31 |
| 31 ds "github.com/luci/gae/service/datastore" | 32 ds "github.com/luci/gae/service/datastore" |
| 32 "github.com/luci/gae/service/info" | 33 "github.com/luci/gae/service/info" |
| 33 | 34 |
| 34 "github.com/golang/protobuf/proto" | 35 "github.com/golang/protobuf/proto" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 49 | 50 |
| 50 // Config is the luci-config configuration map that is installed. | 51 // Config is the luci-config configuration map that is installed. |
| 51 Config map[string]memory.ConfigSet | 52 Config map[string]memory.ConfigSet |
| 52 // ConfigIface is a reference to the memory config.Interface that Config
is | 53 // ConfigIface is a reference to the memory config.Interface that Config
is |
| 53 // installed into. | 54 // installed into. |
| 54 ConfigIface luciConfig.Interface | 55 ConfigIface luciConfig.Interface |
| 55 | 56 |
| 56 // Services is the set of installed Coordinator services. | 57 // Services is the set of installed Coordinator services. |
| 57 Services Services | 58 Services Services |
| 58 | 59 |
| 60 // BigTable in-memory testing instance. |
| 61 BigTable bigtable.Testing |
| 59 // GSClient is the test GSClient instance installed (by default) into | 62 // GSClient is the test GSClient instance installed (by default) into |
| 60 // Services. | 63 // Services. |
| 61 GSClient GSClient | 64 GSClient GSClient |
| 65 |
| 62 // ArchivalPublisher is the test ArchivalPublisher instance installed (b
y | 66 // ArchivalPublisher is the test ArchivalPublisher instance installed (b
y |
| 63 // default) into Services. | 67 // default) into Services. |
| 64 ArchivalPublisher ArchivalPublisher | 68 ArchivalPublisher ArchivalPublisher |
| 65 | 69 |
| 66 // StorageCache is the default storage cache instance. | 70 // StorageCache is the default storage cache instance. |
| 67 StorageCache StorageCache | 71 StorageCache StorageCache |
| 68 } | 72 } |
| 69 | 73 |
| 70 // LogIn installs an testing identity into the testing auth state. | 74 // LogIn installs an testing identity into the testing auth state. |
| 71 func (e *Environment) LogIn() { | 75 func (e *Environment) LogIn() { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 }, | 175 }, |
| 172 } | 176 } |
| 173 | 177 |
| 174 // Get our starting context. This installs, among other things, in-memor
y | 178 // Get our starting context. This installs, among other things, in-memor
y |
| 175 // gae, settings, and logger. | 179 // gae, settings, and logger. |
| 176 c := e.Tumble.Context() | 180 c := e.Tumble.Context() |
| 177 if *testGoLogger { | 181 if *testGoLogger { |
| 178 c = logging.SetLevel(gologger.StdConfig.Use(c), logging.Debug) | 182 c = logging.SetLevel(gologger.StdConfig.Use(c), logging.Debug) |
| 179 } | 183 } |
| 180 | 184 |
| 185 // Create/install our BigTable memory instance. |
| 186 e.BigTable = bigtable.NewMemoryInstance(c, bigtable.Options{ |
| 187 Cache: &e.StorageCache, |
| 188 }) |
| 189 |
| 181 // Add indexes. These should match the indexes defined in the applicatio
n's | 190 // Add indexes. These should match the indexes defined in the applicatio
n's |
| 182 // "index.yaml". | 191 // "index.yaml". |
| 183 indexDefs := [][]string{ | 192 indexDefs := [][]string{ |
| 184 {"Prefix", "-Created"}, | 193 {"Prefix", "-Created"}, |
| 185 {"Name", "-Created"}, | 194 {"Name", "-Created"}, |
| 186 {"State", "-Created"}, | 195 {"State", "-Created"}, |
| 187 {"Purged", "-Created"}, | 196 {"Purged", "-Created"}, |
| 188 {"ProtoVersion", "-Created"}, | 197 {"ProtoVersion", "-Created"}, |
| 189 {"ContentType", "-Created"}, | 198 {"ContentType", "-Created"}, |
| 190 {"StreamType", "-Created"}, | 199 {"StreamType", "-Created"}, |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 e.Tumble.UpdateSettings(c, tcfg) | 285 e.Tumble.UpdateSettings(c, tcfg) |
| 277 | 286 |
| 278 // Install authentication state. | 287 // Install authentication state. |
| 279 c = auth.WithState(c, &e.AuthState) | 288 c = auth.WithState(c, &e.AuthState) |
| 280 | 289 |
| 281 // Setup authentication state. | 290 // Setup authentication state. |
| 282 e.LeaveAllGroups() | 291 e.LeaveAllGroups() |
| 283 | 292 |
| 284 // Setup our default Coordinator services. | 293 // Setup our default Coordinator services. |
| 285 e.Services = Services{ | 294 e.Services = Services{ |
| 286 » » GS: func() (gs.Client, error) { | 295 » » ST: func(lst *coordinator.LogStreamState) (coordinator.Storage,
error) { |
| 287 » » » return &e.GSClient, nil | 296 » » » // If we're not archived, return our BigTable storage in
stance. |
| 297 » » » if !lst.ArchivalState().Archived() { |
| 298 » » » » return &BigTableStorage{ |
| 299 » » » » » Testing: e.BigTable, |
| 300 » » » » }, nil |
| 301 » » » } |
| 302 |
| 303 » » » opts := archive.Options{ |
| 304 » » » » Index: gs.Path(lst.ArchiveIndexURL), |
| 305 » » » » Stream: gs.Path(lst.ArchiveStreamURL), |
| 306 » » » » Client: &e.GSClient, |
| 307 » » » » Cache: &e.StorageCache, |
| 308 » » » } |
| 309 |
| 310 » » » base, err := archive.New(c, opts) |
| 311 » » » if err != nil { |
| 312 » » » » return nil, err |
| 313 » » » } |
| 314 » » » return &ArchivalStorage{ |
| 315 » » » » Storage: base, |
| 316 » » » » Opts: opts, |
| 317 » » » }, nil |
| 288 }, | 318 }, |
| 289 AP: func() (coordinator.ArchivalPublisher, error) { | 319 AP: func() (coordinator.ArchivalPublisher, error) { |
| 290 return &e.ArchivalPublisher, nil | 320 return &e.ArchivalPublisher, nil |
| 291 }, | 321 }, |
| 292 SC: func() caching.Cache { | |
| 293 return &e.StorageCache | |
| 294 }, | |
| 295 } | 322 } |
| 296 c = coordinator.WithServices(c, &e.Services) | 323 c = coordinator.WithServices(c, &e.Services) |
| 297 | 324 |
| 298 return cacheContext.Wrap(c), &e | 325 return cacheContext.Wrap(c), &e |
| 299 } | 326 } |
| 300 | 327 |
| 301 // WithProjectNamespace runs f in proj's namespace, bypassing authentication | 328 // WithProjectNamespace runs f in proj's namespace, bypassing authentication |
| 302 // checks. | 329 // checks. |
| 303 func WithProjectNamespace(c context.Context, proj luciConfig.ProjectName, f func
(context.Context)) { | 330 func WithProjectNamespace(c context.Context, proj luciConfig.ProjectName, f func
(context.Context)) { |
| 304 if err := coordinator.WithProjectNamespace(&c, proj, coordinator.Namespa
ceAccessAllTesting); err != nil { | 331 if err := coordinator.WithProjectNamespace(&c, proj, coordinator.Namespa
ceAccessAllTesting); err != nil { |
| 305 panic(err) | 332 panic(err) |
| 306 } | 333 } |
| 307 f(c) | 334 f(c) |
| 308 } | 335 } |
| OLD | NEW |