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 coordinatorTest | 5 package coordinatorTest |
6 | 6 |
7 import ( | 7 import ( |
8 "github.com/luci/luci-go/appengine/logdog/coordinator" | 8 "github.com/luci/luci-go/appengine/logdog/coordinator" |
9 "github.com/luci/luci-go/appengine/logdog/coordinator/config" | 9 "github.com/luci/luci-go/appengine/logdog/coordinator/config" |
10 luciConfig "github.com/luci/luci-go/common/config" | |
10 "github.com/luci/luci-go/common/gcloud/gs" | 11 "github.com/luci/luci-go/common/gcloud/gs" |
12 "github.com/luci/luci-go/common/proto/logdog/svcconfig" | |
11 "github.com/luci/luci-go/server/logdog/storage" | 13 "github.com/luci/luci-go/server/logdog/storage" |
12 "golang.org/x/net/context" | 14 "golang.org/x/net/context" |
13 ) | 15 ) |
14 | 16 |
15 // Services is a testing stub for a coordinator.Services instance that allows | 17 // Services is a testing stub for a coordinator.Services instance that allows |
16 // the user to configure the various services that are returned. | 18 // the user to configure the various services that are returned. |
17 type Services struct { | 19 type Services struct { |
18 // C, if not nil, will be used to get the return values for Config, over riding | 20 // C, if not nil, will be used to get the return values for Config, over riding |
19 // local static members. | 21 // local static members. |
20 C func() (*config.Config, error) | 22 C func() (*config.Config, error) |
21 | 23 |
24 // PC, if nto nil, will be used to get the return values for ProjectConf ig, | |
nodir
2016/05/18 16:05:35
typo in not
dnj (Google)
2016/05/18 16:46:06
Done.
| |
25 // overriding local static members. | |
26 PC func() (*svcconfig.ProjectConfig, error) | |
27 | |
22 // Storage returns an intermediate storage instance for use by this serv ice. | 28 // Storage returns an intermediate storage instance for use by this serv ice. |
23 // | 29 // |
24 // The caller must close the returned instance if successful. | 30 // The caller must close the returned instance if successful. |
25 IS func() (storage.Storage, error) | 31 IS func() (storage.Storage, error) |
26 | 32 |
27 // GSClient instantiates a Google Storage client. | 33 // GSClient instantiates a Google Storage client. |
28 GS func() (gs.Client, error) | 34 GS func() (gs.Client, error) |
29 | 35 |
30 // ArchivalPublisher returns an ArchivalPublisher instance. | 36 // ArchivalPublisher returns an ArchivalPublisher instance. |
31 AP func() (coordinator.ArchivalPublisher, error) | 37 AP func() (coordinator.ArchivalPublisher, error) |
32 } | 38 } |
33 | 39 |
34 var _ coordinator.Services = (*Services)(nil) | 40 var _ coordinator.Services = (*Services)(nil) |
35 | 41 |
36 // Config implements coordinator.Services. | 42 // Config implements coordinator.Services. |
37 func (s *Services) Config(c context.Context) (*config.Config, error) { | 43 func (s *Services) Config(c context.Context) (*config.Config, error) { |
38 if s.C != nil { | 44 if s.C != nil { |
39 return s.C() | 45 return s.C() |
40 } | 46 } |
47 return config.Load(c) | |
48 } | |
41 | 49 |
42 » gcfg, err := config.Load(c) | 50 // ProjectConfig implements coordinator.Services. |
43 » if err != nil { | 51 func (s *Services) ProjectConfig(c context.Context, project luciConfig.ProjectNa me) (*svcconfig.ProjectConfig, error) { |
44 » » return nil, err | 52 » if s.PC != nil { |
53 » » return s.PC() | |
45 } | 54 } |
46 | 55 » return config.ProjectConfig(c, project) |
47 » return gcfg, nil | |
48 } | 56 } |
49 | 57 |
50 // IntermediateStorage implements coordinator.Services. | 58 // IntermediateStorage implements coordinator.Services. |
51 func (s *Services) IntermediateStorage(context.Context) (storage.Storage, error) { | 59 func (s *Services) IntermediateStorage(context.Context) (storage.Storage, error) { |
52 if s.IS != nil { | 60 if s.IS != nil { |
53 return s.IS() | 61 return s.IS() |
54 } | 62 } |
55 panic("not implemented") | 63 panic("not implemented") |
56 } | 64 } |
57 | 65 |
58 // GSClient implements coordinator.Services. | 66 // GSClient implements coordinator.Services. |
59 func (s *Services) GSClient(context.Context) (gs.Client, error) { | 67 func (s *Services) GSClient(context.Context) (gs.Client, error) { |
60 if s.GS != nil { | 68 if s.GS != nil { |
61 return s.GS() | 69 return s.GS() |
62 } | 70 } |
63 panic("not implemented") | 71 panic("not implemented") |
64 } | 72 } |
65 | 73 |
66 // ArchivalPublisher implements coordinator.Services. | 74 // ArchivalPublisher implements coordinator.Services. |
67 func (s *Services) ArchivalPublisher(context.Context) (coordinator.ArchivalPubli sher, error) { | 75 func (s *Services) ArchivalPublisher(context.Context) (coordinator.ArchivalPubli sher, error) { |
68 if s.AP != nil { | 76 if s.AP != nil { |
69 return s.AP() | 77 return s.AP() |
70 } | 78 } |
71 panic("not implemented") | 79 panic("not implemented") |
72 } | 80 } |
OLD | NEW |