| OLD | NEW |
| 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 registration | 5 package registration |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "errors" | 8 "errors" |
| 9 "testing" | 9 "testing" |
| 10 "time" | 10 "time" |
| 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/common/clock" | 14 "github.com/luci/luci-go/common/clock" |
| 15 "github.com/luci/luci-go/common/config" | |
| 16 "github.com/luci/luci-go/common/data/rand/cryptorand" | 15 "github.com/luci/luci-go/common/data/rand/cryptorand" |
| 17 "github.com/luci/luci-go/common/proto/google" | 16 "github.com/luci/luci-go/common/proto/google" |
| 18 "github.com/luci/luci-go/logdog/api/config/svcconfig" | 17 "github.com/luci/luci-go/logdog/api/config/svcconfig" |
| 19 "github.com/luci/luci-go/logdog/api/endpoints/coordinator/registration/v
1" | 18 "github.com/luci/luci-go/logdog/api/endpoints/coordinator/registration/v
1" |
| 20 "github.com/luci/luci-go/logdog/appengine/coordinator" | 19 "github.com/luci/luci-go/logdog/appengine/coordinator" |
| 21 ct "github.com/luci/luci-go/logdog/appengine/coordinator/coordinatorTest
" | 20 ct "github.com/luci/luci-go/logdog/appengine/coordinator/coordinatorTest
" |
| 22 "github.com/luci/luci-go/logdog/appengine/coordinator/hierarchy" | 21 "github.com/luci/luci-go/logdog/appengine/coordinator/hierarchy" |
| 23 "github.com/luci/luci-go/logdog/common/types" | 22 "github.com/luci/luci-go/logdog/common/types" |
| 23 "github.com/luci/luci-go/luci_config/common/cfgtypes" |
| 24 | 24 |
| 25 "golang.org/x/net/context" | 25 "golang.org/x/net/context" |
| 26 | 26 |
| 27 . "github.com/luci/luci-go/common/testing/assertions" | 27 . "github.com/luci/luci-go/common/testing/assertions" |
| 28 . "github.com/smartystreets/goconvey/convey" | 28 . "github.com/smartystreets/goconvey/convey" |
| 29 ) | 29 ) |
| 30 | 30 |
| 31 func TestRegisterPrefix(t *testing.T) { | 31 func TestRegisterPrefix(t *testing.T) { |
| 32 t.Parallel() | 32 t.Parallel() |
| 33 | 33 |
| 34 Convey(`With a testing configuration`, t, func() { | 34 Convey(`With a testing configuration`, t, func() { |
| 35 c, env := ct.Install() | 35 c, env := ct.Install() |
| 36 c, fb := featureBreaker.FilterRDS(c, nil) | 36 c, fb := featureBreaker.FilterRDS(c, nil) |
| 37 ds.GetTestable(c).Consistent(true) | 37 ds.GetTestable(c).Consistent(true) |
| 38 | 38 |
| 39 // Mock random number generator so we can predict secrets. | 39 // Mock random number generator so we can predict secrets. |
| 40 c = cryptorand.MockForTest(c, 0) | 40 c = cryptorand.MockForTest(c, 0) |
| 41 randSecret := []byte{ | 41 randSecret := []byte{ |
| 42 250, 18, 249, 42, 251, 224, 15, 133, 8, 208, 232, 59, | 42 250, 18, 249, 42, 251, 224, 15, 133, 8, 208, 232, 59, |
| 43 171, 156, 248, 206, 191, 66, 226, 94, 139, 20, 234, 252, | 43 171, 156, 248, 206, 191, 66, 226, 94, 139, 20, 234, 252, |
| 44 129, 234, 224, 208, 15, 44, 173, 228, 193, 124, 22, 209, | 44 129, 234, 224, 208, 15, 44, 173, 228, 193, 124, 22, 209, |
| 45 } | 45 } |
| 46 | 46 |
| 47 svr := New() | 47 svr := New() |
| 48 | 48 |
| 49 » » const project = config.ProjectName("proj-foo") | 49 » » const project = cfgtypes.ProjectName("proj-foo") |
| 50 req := logdog.RegisterPrefixRequest{ | 50 req := logdog.RegisterPrefixRequest{ |
| 51 Project: string(project), | 51 Project: string(project), |
| 52 Prefix: "testing/prefix", | 52 Prefix: "testing/prefix", |
| 53 SourceInfo: []string{"unit test"}, | 53 SourceInfo: []string{"unit test"}, |
| 54 } | 54 } |
| 55 pfx := &coordinator.LogPrefix{ID: coordinator.LogPrefixID(types.
StreamName(req.Prefix))} | 55 pfx := &coordinator.LogPrefix{ID: coordinator.LogPrefixID(types.
StreamName(req.Prefix))} |
| 56 | 56 |
| 57 Convey(`If user is logged in`, func() { | 57 Convey(`If user is logged in`, func() { |
| 58 // "proj-bar" does not have anonymous write. | 58 // "proj-bar" does not have anonymous write. |
| 59 req.Project = "proj-bar" | 59 req.Project = "proj-bar" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 }) | 167 }) |
| 168 }) | 168 }) |
| 169 | 169 |
| 170 Convey(`Will fail to register the prefix if Put is broken.`, fun
c() { | 170 Convey(`Will fail to register the prefix if Put is broken.`, fun
c() { |
| 171 fb.BreakFeatures(errors.New("test error"), "PutMulti") | 171 fb.BreakFeatures(errors.New("test error"), "PutMulti") |
| 172 _, err := svr.RegisterPrefix(c, &req) | 172 _, err := svr.RegisterPrefix(c, &req) |
| 173 So(err, ShouldBeRPCInternal) | 173 So(err, ShouldBeRPCInternal) |
| 174 }) | 174 }) |
| 175 }) | 175 }) |
| 176 } | 176 } |
| OLD | NEW |