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

Side by Side Diff: logdog/appengine/coordinator/coordinatorTest/context.go

Issue 2575383002: Add server/cache support to gaeconfig. (Closed)
Patch Set: Un-collapse. Created 3 years, 11 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
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 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"
15 "github.com/luci/luci-go/common/config/impl/memory" 14 "github.com/luci/luci-go/common/config/impl/memory"
16 "github.com/luci/luci-go/common/data/caching/cacheContext" 15 "github.com/luci/luci-go/common/data/caching/cacheContext"
17 "github.com/luci/luci-go/common/gcloud/gs" 16 "github.com/luci/luci-go/common/gcloud/gs"
18 "github.com/luci/luci-go/common/logging" 17 "github.com/luci/luci-go/common/logging"
19 "github.com/luci/luci-go/common/logging/gologger" 18 "github.com/luci/luci-go/common/logging/gologger"
19 configPB "github.com/luci/luci-go/common/proto/config"
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/archive" 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/logdog/common/storage/bigtable"
26 "github.com/luci/luci-go/luci_config/common/cfgtypes" 26 "github.com/luci/luci-go/luci_config/common/cfgtypes"
27 "github.com/luci/luci-go/luci_config/server/cfgclient"
28 "github.com/luci/luci-go/luci_config/server/cfgclient/backend/testconfig "
29 "github.com/luci/luci-go/luci_config/server/cfgclient/textproto"
27 "github.com/luci/luci-go/server/auth" 30 "github.com/luci/luci-go/server/auth"
28 "github.com/luci/luci-go/server/auth/authtest" 31 "github.com/luci/luci-go/server/auth/authtest"
29 "github.com/luci/luci-go/server/auth/identity" 32 "github.com/luci/luci-go/server/auth/identity"
30 "github.com/luci/luci-go/server/settings" 33 "github.com/luci/luci-go/server/settings"
31 "github.com/luci/luci-go/tumble" 34 "github.com/luci/luci-go/tumble"
32 35
33 ds "github.com/luci/gae/service/datastore" 36 ds "github.com/luci/gae/service/datastore"
34 "github.com/luci/gae/service/info" 37 "github.com/luci/gae/service/info"
35 38
36 "github.com/golang/protobuf/proto" 39 "github.com/golang/protobuf/proto"
37 "golang.org/x/net/context" 40 "golang.org/x/net/context"
38 ) 41 )
39 42
40 // Environment contains all of the testing facilities that are installed into 43 // Environment contains all of the testing facilities that are installed into
41 // the Context. 44 // the Context.
42 type Environment struct { 45 type Environment struct {
43 // Tumble is the Tumble testing instance. 46 // Tumble is the Tumble testing instance.
44 Tumble tumble.Testing 47 Tumble tumble.Testing
45 48
46 // Clock is the installed test clock instance. 49 // Clock is the installed test clock instance.
47 Clock testclock.TestClock 50 Clock testclock.TestClock
48 51
49 // AuthState is the fake authentication state. 52 // AuthState is the fake authentication state.
50 AuthState authtest.FakeState 53 AuthState authtest.FakeState
51 54
52 // Config is the luci-config configuration map that is installed. 55 // Config is the luci-config configuration map that is installed.
53 Config map[string]memory.ConfigSet 56 Config map[string]memory.ConfigSet
54 // ConfigIface is a reference to the memory config.Interface that Config is
55 // installed into.
56 ConfigIface luciConfig.Interface
57 57
58 // Services is the set of installed Coordinator services. 58 // Services is the set of installed Coordinator services.
59 Services Services 59 Services Services
60 60
61 // BigTable in-memory testing instance. 61 // BigTable in-memory testing instance.
62 BigTable bigtable.Testing 62 BigTable bigtable.Testing
63 // GSClient is the test GSClient instance installed (by default) into 63 // GSClient is the test GSClient instance installed (by default) into
64 // Services. 64 // Services.
65 GSClient GSClient 65 GSClient GSClient
66 66
(...skipping 16 matching lines...) Expand all
83 83
84 // JoinGroup adds the named group the to the list of groups for the current 84 // JoinGroup adds the named group the to the list of groups for the current
85 // identity. 85 // identity.
86 func (e *Environment) JoinGroup(g string) { 86 func (e *Environment) JoinGroup(g string) {
87 e.AuthState.IdentityGroups = append(e.AuthState.IdentityGroups, g) 87 e.AuthState.IdentityGroups = append(e.AuthState.IdentityGroups, g)
88 } 88 }
89 89
90 // LeaveAllGroups clears all auth groups that the user is currently a member of. 90 // LeaveAllGroups clears all auth groups that the user is currently a member of.
91 func (e *Environment) LeaveAllGroups() { 91 func (e *Environment) LeaveAllGroups() {
92 e.AuthState.IdentityGroups = nil 92 e.AuthState.IdentityGroups = nil
93 e.JoinGroup("all")
94 } 93 }
95 94
96 // ClearCoordinatorConfig removes the Coordinator configuration entry, 95 // ClearCoordinatorConfig removes the Coordinator configuration entry,
97 // simulating a missing config. 96 // simulating a missing config.
98 func (e *Environment) ClearCoordinatorConfig(c context.Context) { 97 func (e *Environment) ClearCoordinatorConfig(c context.Context) {
99 configSet, _ := config.ServiceConfigPath(c) 98 configSet, _ := config.ServiceConfigPath(c)
100 delete(e.Config, string(configSet)) 99 delete(e.Config, string(configSet))
101 } 100 }
102 101
103 // ModServiceConfig loads the current service configuration, invokes the 102 // ModServiceConfig loads the current service configuration, invokes the
(...skipping 14 matching lines...) Expand all
118 117
119 var pcfg svcconfig.ProjectConfig 118 var pcfg svcconfig.ProjectConfig
120 e.modTextProtobuf(c, configSet, configPath, &pcfg, func() { 119 e.modTextProtobuf(c, configSet, configPath, &pcfg, func() {
121 fn(&pcfg) 120 fn(&pcfg)
122 }) 121 })
123 } 122 }
124 123
125 // IterateTumbleAll iterates all Tumble instances across all namespaces. 124 // IterateTumbleAll iterates all Tumble instances across all namespaces.
126 func (e *Environment) IterateTumbleAll(c context.Context) { e.Tumble.IterateAll( c) } 125 func (e *Environment) IterateTumbleAll(c context.Context) { e.Tumble.IterateAll( c) }
127 126
128 func (e *Environment) modTextProtobuf(c context.Context, configSet cfgtypes.Conf igSet, path string, msg proto.Message, fn func()) { 127 func (e *Environment) modTextProtobuf(c context.Context, configSet cfgtypes.Conf igSet, path string,
129 » cfg, err := e.ConfigIface.GetConfig(c, string(configSet), path, false) 128 » msg proto.Message, fn func()) {
130 129
131 » switch err { 130 » switch err := cfgclient.Get(c, cfgclient.AsService, configSet, path, tex tproto.Message(msg), nil); err {
132 » case nil: 131 » case nil, cfgclient.ErrNoConfig:
133 » » if err := proto.UnmarshalText(cfg.Content, msg); err != nil {
134 » » » panic(err)
135 » » }
136
137 » case luciConfig.ErrNoConfig:
138 break 132 break
139
140 default: 133 default:
141 panic(err) 134 panic(err)
142 } 135 }
143 136
144 fn() 137 fn()
145 e.addConfigEntry(configSet, path, proto.MarshalTextString(msg)) 138 e.addConfigEntry(configSet, path, proto.MarshalTextString(msg))
146 } 139 }
147 140
148 func (e *Environment) addConfigEntry(configSet cfgtypes.ConfigSet, path, content string) { 141 func (e *Environment) addConfigEntry(configSet cfgtypes.ConfigSet, path, content string) {
149 cset := e.Config[string(configSet)] 142 cset := e.Config[string(configSet)]
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 } 200 }
208 ds.GetTestable(c).AddIndexes(indexes...) 201 ds.GetTestable(c).AddIndexes(indexes...)
209 202
210 // Setup clock. 203 // Setup clock.
211 e.Clock = clock.Get(c).(testclock.TestClock) 204 e.Clock = clock.Get(c).(testclock.TestClock)
212 205
213 // Install GAE config service settings. 206 // Install GAE config service settings.
214 c = settings.Use(c, settings.New(&settings.MemoryStorage{})) 207 c = settings.Use(c, settings.New(&settings.MemoryStorage{}))
215 208
216 // Setup luci-config configuration. 209 // Setup luci-config configuration.
217 » e.ConfigIface = memory.New(e.Config) 210 » c = testconfig.WithCommonClient(c, memory.New(e.Config))
218 » c = luciConfig.SetImplementation(c, e.ConfigIface)
219 211
220 // luci-config: Projects. 212 // luci-config: Projects.
221 projectName := info.AppID(c) 213 projectName := info.AppID(c)
222 addProjectConfig := func(proj cfgtypes.ProjectName, access ...string) { 214 addProjectConfig := func(proj cfgtypes.ProjectName, access ...string) {
215 projectAccesses := make([]string, len(access))
216
217 // Build our service config. Also builds "projectAccesses".
223 e.ModProjectConfig(c, proj, func(pcfg *svcconfig.ProjectConfig) { 218 e.ModProjectConfig(c, proj, func(pcfg *svcconfig.ProjectConfig) {
224 » » » for _, a := range access { 219 » » » for i, a := range access {
225 parts := strings.SplitN(a, ":", 2) 220 parts := strings.SplitN(a, ":", 2)
226 group, field := parts[0], &pcfg.ReaderAuthGroups 221 group, field := parts[0], &pcfg.ReaderAuthGroups
227 if len(parts) == 2 { 222 if len(parts) == 2 {
228 switch parts[1] { 223 switch parts[1] {
229 case "R": 224 case "R":
230 break 225 break
231 case "W": 226 case "W":
232 field = &pcfg.WriterAuthGroups 227 field = &pcfg.WriterAuthGroups
233 default: 228 default:
234 panic(a) 229 panic(a)
235 } 230 }
236 } 231 }
237 *field = append(*field, group) 232 *field = append(*field, group)
233 projectAccesses[i] = fmt.Sprintf("group:%s", gro up)
234 }
235 })
236
237 var pcfg configPB.ProjectCfg
238 e.modTextProtobuf(c, cfgtypes.ProjectConfigSet(proj), cfgclient. ProjectConfigPath, &pcfg, func() {
239 pcfg = configPB.ProjectCfg{
240 Name: proto.String(string(proj)),
241 Access: projectAccesses,
238 } 242 }
239 }) 243 })
240 } 244 }
241 addProjectConfig("proj-foo", "all:R", "all:W") 245 addProjectConfig("proj-foo", "all:R", "all:W")
242 addProjectConfig("proj-bar", "all:R", "auth:W") 246 addProjectConfig("proj-bar", "all:R", "auth:W")
243 addProjectConfig("proj-exclusive", "auth:R", "auth:W") 247 addProjectConfig("proj-exclusive", "auth:R", "auth:W")
244 248
245 // Add a project without a LogDog project config. 249 // Add a project without a LogDog project config.
246 e.addConfigEntry("projects/proj-unconfigured", "not-logdog.cfg", "junk") 250 e.addConfigEntry("projects/proj-unconfigured", "not-logdog.cfg", "junk")
247 251
(...skipping 23 matching lines...) Expand all
271 tcfg := e.Tumble.GetConfig(c) 275 tcfg := e.Tumble.GetConfig(c)
272 tcfg.TemporalRoundFactor = 0 // Makes test timing easier to understand. 276 tcfg.TemporalRoundFactor = 0 // Makes test timing easier to understand.
273 tcfg.TemporalMinDelay = 0 // Makes test timing easier to understand. 277 tcfg.TemporalMinDelay = 0 // Makes test timing easier to understand.
274 e.Tumble.UpdateSettings(c, tcfg) 278 e.Tumble.UpdateSettings(c, tcfg)
275 279
276 // Install authentication state. 280 // Install authentication state.
277 c = auth.WithState(c, &e.AuthState) 281 c = auth.WithState(c, &e.AuthState)
278 282
279 // Setup authentication state. 283 // Setup authentication state.
280 e.LeaveAllGroups() 284 e.LeaveAllGroups()
285 e.JoinGroup("all")
281 286
282 // Setup our default Coordinator services. 287 // Setup our default Coordinator services.
283 e.Services = Services{ 288 e.Services = Services{
284 ST: func(lst *coordinator.LogStreamState) (coordinator.Storage, error) { 289 ST: func(lst *coordinator.LogStreamState) (coordinator.Storage, error) {
285 // If we're not archived, return our BigTable storage in stance. 290 // If we're not archived, return our BigTable storage in stance.
286 if !lst.ArchivalState().Archived() { 291 if !lst.ArchivalState().Archived() {
287 return &BigTableStorage{ 292 return &BigTableStorage{
288 Testing: e.BigTable, 293 Testing: e.BigTable,
289 }, nil 294 }, nil
290 } 295 }
(...skipping 24 matching lines...) Expand all
315 } 320 }
316 321
317 // WithProjectNamespace runs f in proj's namespace, bypassing authentication 322 // WithProjectNamespace runs f in proj's namespace, bypassing authentication
318 // checks. 323 // checks.
319 func WithProjectNamespace(c context.Context, proj cfgtypes.ProjectName, f func(c ontext.Context)) { 324 func WithProjectNamespace(c context.Context, proj cfgtypes.ProjectName, f func(c ontext.Context)) {
320 if err := coordinator.WithProjectNamespace(&c, proj, coordinator.Namespa ceAccessAllTesting); err != nil { 325 if err := coordinator.WithProjectNamespace(&c, proj, coordinator.Namespa ceAccessAllTesting); err != nil {
321 panic(err) 326 panic(err)
322 } 327 }
323 f(c) 328 f(c)
324 } 329 }
OLDNEW
« no previous file with comments | « logdog/appengine/coordinator/context_test.go ('k') | logdog/appengine/coordinator/coordinatorTest/logStream.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698