| 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 services | 5 package services |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "testing" | 8 "testing" |
| 9 | 9 |
| 10 "github.com/luci/gae/impl/memory" | 10 "github.com/luci/gae/impl/memory" |
| 11 "github.com/luci/luci-go/appengine/gaesettings" | 11 "github.com/luci/luci-go/appengine/gaesettings" |
| 12 » "github.com/luci/luci-go/appengine/logdog/coordinator/config" | 12 » "github.com/luci/luci-go/appengine/logdog/coordinator" |
| 13 ct "github.com/luci/luci-go/appengine/logdog/coordinator/coordinatorTest
" | 13 ct "github.com/luci/luci-go/appengine/logdog/coordinator/coordinatorTest
" |
| 14 "github.com/luci/luci-go/common/api/logdog_coordinator/services/v1" | 14 "github.com/luci/luci-go/common/api/logdog_coordinator/services/v1" |
| 15 "github.com/luci/luci-go/common/proto/logdog/svcconfig" | |
| 16 "github.com/luci/luci-go/server/auth" | 15 "github.com/luci/luci-go/server/auth" |
| 17 "github.com/luci/luci-go/server/auth/authtest" | 16 "github.com/luci/luci-go/server/auth/authtest" |
| 18 "github.com/luci/luci-go/server/settings" | 17 "github.com/luci/luci-go/server/settings" |
| 19 "golang.org/x/net/context" | 18 "golang.org/x/net/context" |
| 20 | 19 |
| 21 . "github.com/luci/luci-go/common/testing/assertions" | 20 . "github.com/luci/luci-go/common/testing/assertions" |
| 22 . "github.com/smartystreets/goconvey/convey" | 21 . "github.com/smartystreets/goconvey/convey" |
| 23 ) | 22 ) |
| 24 | 23 |
| 25 func TestGetConfig(t *testing.T) { | 24 func TestGetConfig(t *testing.T) { |
| 26 t.Parallel() | 25 t.Parallel() |
| 27 | 26 |
| 28 Convey(`With a testing configuration`, t, func() { | 27 Convey(`With a testing configuration`, t, func() { |
| 29 c := memory.Use(context.Background()) | 28 c := memory.Use(context.Background()) |
| 30 c = settings.Use(c, settings.New(&gaesettings.Storage{})) | 29 c = settings.Use(c, settings.New(&gaesettings.Storage{})) |
| 31 be := Server{} | |
| 32 | 30 |
| 33 » » c = ct.UseConfig(c, &svcconfig.Coordinator{ | 31 » » svcStub := ct.Services{} |
| 34 » » » ServiceAuthGroup: "test-services", | 32 » » svcStub.InitConfig() |
| 35 » » }) | 33 » » svcStub.ServiceConfig.Coordinator.ServiceAuthGroup = "test-servi
ces" |
| 34 |
| 35 » » be := Server{ |
| 36 » » » ServiceBase: coordinator.ServiceBase{&svcStub}, |
| 37 » » } |
| 38 |
| 36 fs := authtest.FakeState{} | 39 fs := authtest.FakeState{} |
| 37 c = auth.WithState(c, &fs) | 40 c = auth.WithState(c, &fs) |
| 38 | 41 |
| 39 Convey(`Returns Forbidden error if not a service.`, func() { | 42 Convey(`Returns Forbidden error if not a service.`, func() { |
| 40 _, err := be.GetConfig(c, nil) | 43 _, err := be.GetConfig(c, nil) |
| 41 So(err, ShouldBeRPCPermissionDenied) | 44 So(err, ShouldBeRPCPermissionDenied) |
| 42 }) | 45 }) |
| 43 | 46 |
| 44 Convey(`When logged in as a service, can retrieve the configurat
ion.`, func() { | 47 Convey(`When logged in as a service, can retrieve the configurat
ion.`, func() { |
| 45 | |
| 46 c = ct.UseConfig(c, &svcconfig.Coordinator{ | |
| 47 ServiceAuthGroup: "test-services", | |
| 48 }) | |
| 49 fs := authtest.FakeState{} | |
| 50 c = auth.WithState(c, &fs) | |
| 51 fs.IdentityGroups = []string{"test-services"} | 48 fs.IdentityGroups = []string{"test-services"} |
| 52 | 49 |
| 53 gcfg, err := config.LoadGlobalConfig(c) | |
| 54 So(err, ShouldBeRPCOK) | |
| 55 | |
| 56 cr, err := be.GetConfig(c, nil) | 50 cr, err := be.GetConfig(c, nil) |
| 57 So(err, ShouldBeRPCOK) | 51 So(err, ShouldBeRPCOK) |
| 58 So(cr, ShouldResemble, &logdog.GetConfigResponse{ | 52 So(cr, ShouldResemble, &logdog.GetConfigResponse{ |
| 59 » » » » ConfigServiceUrl: gcfg.ConfigServiceURL, | 53 » » » » ConfigServiceUrl: svcStub.GlobalConfig.ConfigSer
viceURL, |
| 60 » » » » ConfigSet: gcfg.ConfigSet, | 54 » » » » ConfigSet: svcStub.GlobalConfig.ConfigSet
, |
| 61 » » » » ConfigPath: gcfg.ConfigPath, | 55 » » » » ConfigPath: svcStub.GlobalConfig.ConfigPat
h, |
| 62 }) | 56 }) |
| 63 }) | 57 }) |
| 64 }) | 58 }) |
| 65 } | 59 } |
| OLD | NEW |