| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 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 coordinator | 5 package coordinator |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "errors" | 8 "errors" |
| 9 "fmt" | 9 "fmt" |
| 10 "testing" | 10 "testing" |
| 11 | 11 |
| 12 "github.com/luci/gae/impl/memory" | 12 "github.com/luci/gae/impl/memory" |
| 13 luciConfig "github.com/luci/luci-go/common/config" | |
| 14 "github.com/luci/luci-go/logdog/api/config/svcconfig" | 13 "github.com/luci/luci-go/logdog/api/config/svcconfig" |
| 15 "github.com/luci/luci-go/logdog/appengine/coordinator/config" | 14 "github.com/luci/luci-go/logdog/appengine/coordinator/config" |
| 16 "github.com/luci/luci-go/luci_config/common/cfgtypes" | 15 "github.com/luci/luci-go/luci_config/common/cfgtypes" |
| 16 "github.com/luci/luci-go/luci_config/server/cfgclient" |
| 17 "github.com/luci/luci-go/server/auth" | 17 "github.com/luci/luci-go/server/auth" |
| 18 "github.com/luci/luci-go/server/auth/authtest" | 18 "github.com/luci/luci-go/server/auth/authtest" |
| 19 "github.com/luci/luci-go/server/auth/identity" | 19 "github.com/luci/luci-go/server/auth/identity" |
| 20 | 20 |
| 21 "golang.org/x/net/context" | 21 "golang.org/x/net/context" |
| 22 | 22 |
| 23 . "github.com/luci/luci-go/common/testing/assertions" | 23 . "github.com/luci/luci-go/common/testing/assertions" |
| 24 . "github.com/smartystreets/goconvey/convey" | 24 . "github.com/smartystreets/goconvey/convey" |
| 25 ) | 25 ) |
| 26 | 26 |
| 27 type testServices struct { | 27 type testServices struct { |
| 28 Services | 28 Services |
| 29 | 29 |
| 30 configErr error | 30 configErr error |
| 31 configs map[cfgtypes.ProjectName]*svcconfig.ProjectConfig | 31 configs map[cfgtypes.ProjectName]*svcconfig.ProjectConfig |
| 32 } | 32 } |
| 33 | 33 |
| 34 func (s *testServices) ProjectConfig(c context.Context, project cfgtypes.Project
Name) (*svcconfig.ProjectConfig, error) { | 34 func (s *testServices) ProjectConfig(c context.Context, project cfgtypes.Project
Name) (*svcconfig.ProjectConfig, error) { |
| 35 if err := s.configErr; err != nil { | 35 if err := s.configErr; err != nil { |
| 36 return nil, err | 36 return nil, err |
| 37 } | 37 } |
| 38 | 38 |
| 39 cfg, ok := s.configs[project] | 39 cfg, ok := s.configs[project] |
| 40 switch { | 40 switch { |
| 41 case !ok: | 41 case !ok: |
| 42 » » return nil, luciConfig.ErrNoConfig | 42 » » return nil, cfgclient.ErrNoConfig |
| 43 | 43 |
| 44 case cfg == nil: | 44 case cfg == nil: |
| 45 return nil, config.ErrInvalidConfig | 45 return nil, config.ErrInvalidConfig |
| 46 | 46 |
| 47 default: | 47 default: |
| 48 return cfg, nil | 48 return cfg, nil |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 | 51 |
| 52 func TestWithProjectNamespace(t *testing.T) { | 52 func TestWithProjectNamespace(t *testing.T) { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 for _, proj := range []cfgtypes.ProjectN
ame{"all-access", "exclusive-access", "does-not-exist"} { | 164 for _, proj := range []cfgtypes.ProjectN
ame{"all-access", "exclusive-access", "does-not-exist"} { |
| 165 Convey(fmt.Sprintf(`Will fail to
access %q with Internal.`, proj), func() { | 165 Convey(fmt.Sprintf(`Will fail to
access %q with Internal.`, proj), func() { |
| 166 So(WithProjectNamespace(
&c, "all-access", tc.access), ShouldBeRPCInternal) | 166 So(WithProjectNamespace(
&c, "all-access", tc.access), ShouldBeRPCInternal) |
| 167 }) | 167 }) |
| 168 } | 168 } |
| 169 }) | 169 }) |
| 170 }) | 170 }) |
| 171 } | 171 } |
| 172 }) | 172 }) |
| 173 } | 173 } |
| OLD | NEW |