| 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 "bytes" | 8 "bytes" |
| 9 "errors" | 9 "errors" |
| 10 "testing" | 10 "testing" |
| 11 | 11 |
| 12 "github.com/luci/gae/filter/featureBreaker" | 12 "github.com/luci/gae/filter/featureBreaker" |
| 13 ds "github.com/luci/gae/service/datastore" | 13 ds "github.com/luci/gae/service/datastore" |
| 14 "github.com/luci/luci-go/appengine/logdog/coordinator" |
| 14 ct "github.com/luci/luci-go/appengine/logdog/coordinator/coordinatorTest
" | 15 ct "github.com/luci/luci-go/appengine/logdog/coordinator/coordinatorTest
" |
| 15 "github.com/luci/luci-go/appengine/logdog/coordinator/hierarchy" | 16 "github.com/luci/luci-go/appengine/logdog/coordinator/hierarchy" |
| 16 "github.com/luci/luci-go/appengine/tumble" | 17 "github.com/luci/luci-go/appengine/tumble" |
| 17 "github.com/luci/luci-go/common/api/logdog_coordinator/services/v1" | 18 "github.com/luci/luci-go/common/api/logdog_coordinator/services/v1" |
| 18 "github.com/luci/luci-go/common/logdog/types" | 19 "github.com/luci/luci-go/common/logdog/types" |
| 19 "github.com/luci/luci-go/common/proto/logdog/logpb" | 20 "github.com/luci/luci-go/common/proto/logdog/logpb" |
| 20 "github.com/luci/luci-go/common/proto/logdog/svcconfig" | |
| 21 "github.com/luci/luci-go/server/auth" | 21 "github.com/luci/luci-go/server/auth" |
| 22 "github.com/luci/luci-go/server/auth/authtest" | 22 "github.com/luci/luci-go/server/auth/authtest" |
| 23 | 23 |
| 24 . "github.com/luci/luci-go/common/testing/assertions" | 24 . "github.com/luci/luci-go/common/testing/assertions" |
| 25 . "github.com/smartystreets/goconvey/convey" | 25 . "github.com/smartystreets/goconvey/convey" |
| 26 ) | 26 ) |
| 27 | 27 |
| 28 func TestRegisterStream(t *testing.T) { | 28 func TestRegisterStream(t *testing.T) { |
| 29 t.Parallel() | 29 t.Parallel() |
| 30 | 30 |
| 31 Convey(`With a testing configuration`, t, func() { | 31 Convey(`With a testing configuration`, t, func() { |
| 32 tt := tumble.NewTesting() | 32 tt := tumble.NewTesting() |
| 33 c := tt.Context() | 33 c := tt.Context() |
| 34 ds.Get(c).Testable().Consistent(true) | 34 ds.Get(c).Testable().Consistent(true) |
| 35 be := Server{} | |
| 36 | 35 |
| 37 » » c = ct.UseConfig(c, &svcconfig.Coordinator{ | 36 » » svcStub := ct.Services{} |
| 38 » » » ServiceAuthGroup: "test-services", | 37 » » svcStub.InitConfig() |
| 39 » » }) | 38 » » svcStub.ServiceConfig.Coordinator.ServiceAuthGroup = "test-servi
ces" |
| 39 |
| 40 » » be := Server{ |
| 41 » » » ServiceBase: coordinator.ServiceBase{&svcStub}, |
| 42 » » } |
| 43 |
| 40 fs := authtest.FakeState{} | 44 fs := authtest.FakeState{} |
| 41 c = auth.WithState(c, &fs) | 45 c = auth.WithState(c, &fs) |
| 42 | 46 |
| 43 Convey(`Returns Forbidden error if not a service.`, func() { | 47 Convey(`Returns Forbidden error if not a service.`, func() { |
| 44 _, err := be.RegisterStream(c, &logdog.RegisterStreamReq
uest{}) | 48 _, err := be.RegisterStream(c, &logdog.RegisterStreamReq
uest{}) |
| 45 So(err, ShouldBeRPCPermissionDenied) | 49 So(err, ShouldBeRPCPermissionDenied) |
| 46 }) | 50 }) |
| 47 | 51 |
| 48 Convey(`When logged in as a service`, func() { | 52 Convey(`When logged in as a service`, func() { |
| 49 fs.IdentityGroups = []string{"test-services"} | 53 fs.IdentityGroups = []string{"test-services"} |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 So(req.Desc.Validate(true), Shou
ldNotBeNil) | 184 So(req.Desc.Validate(true), Shou
ldNotBeNil) |
| 181 | 185 |
| 182 _, err := be.RegisterStream(c, &
req) | 186 _, err := be.RegisterStream(c, &
req) |
| 183 So(err, ShouldBeRPCInvalidArgume
nt, "Invalid log stream descriptor") | 187 So(err, ShouldBeRPCInvalidArgume
nt, "Invalid log stream descriptor") |
| 184 }) | 188 }) |
| 185 }) | 189 }) |
| 186 }) | 190 }) |
| 187 }) | 191 }) |
| 188 }) | 192 }) |
| 189 } | 193 } |
| OLD | NEW |