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 logs | 5 package logs |
6 | 6 |
7 import ( | 7 import ( |
8 "fmt" | 8 "fmt" |
9 "testing" | 9 "testing" |
10 | 10 |
11 "github.com/luci/gae/filter/featureBreaker" | 11 "github.com/luci/gae/filter/featureBreaker" |
12 "github.com/luci/gae/impl/memory" | 12 "github.com/luci/gae/impl/memory" |
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 "github.com/luci/luci-go/appengine/logdog/coordinator" |
15 ct "github.com/luci/luci-go/appengine/logdog/coordinator/coordinatorTest
" | 15 ct "github.com/luci/luci-go/appengine/logdog/coordinator/coordinatorTest
" |
16 "github.com/luci/luci-go/appengine/logdog/coordinator/hierarchy" | 16 "github.com/luci/luci-go/appengine/logdog/coordinator/hierarchy" |
17 "github.com/luci/luci-go/common/api/logdog_coordinator/logs/v1" | 17 "github.com/luci/luci-go/common/api/logdog_coordinator/logs/v1" |
18 "github.com/luci/luci-go/common/clock/testclock" | 18 "github.com/luci/luci-go/common/clock/testclock" |
| 19 "github.com/luci/luci-go/common/config" |
19 "github.com/luci/luci-go/common/logdog/types" | 20 "github.com/luci/luci-go/common/logdog/types" |
20 "github.com/luci/luci-go/common/proto/logdog/logpb" | 21 "github.com/luci/luci-go/common/proto/logdog/logpb" |
21 "github.com/luci/luci-go/server/auth" | 22 "github.com/luci/luci-go/server/auth" |
22 "github.com/luci/luci-go/server/auth/authtest" | 23 "github.com/luci/luci-go/server/auth/authtest" |
23 "golang.org/x/net/context" | 24 "golang.org/x/net/context" |
24 | 25 |
25 . "github.com/luci/luci-go/common/testing/assertions" | 26 . "github.com/luci/luci-go/common/testing/assertions" |
26 . "github.com/smartystreets/goconvey/convey" | 27 . "github.com/smartystreets/goconvey/convey" |
27 ) | 28 ) |
28 | 29 |
(...skipping 17 matching lines...) Expand all Loading... |
46 c, _ = featureBreaker.FilterRDS(c, nil) | 47 c, _ = featureBreaker.FilterRDS(c, nil) |
47 | 48 |
48 fs := authtest.FakeState{} | 49 fs := authtest.FakeState{} |
49 c = auth.WithState(c, &fs) | 50 c = auth.WithState(c, &fs) |
50 | 51 |
51 svcStub := ct.Services{} | 52 svcStub := ct.Services{} |
52 svcStub.InitConfig() | 53 svcStub.InitConfig() |
53 svcStub.ServiceConfig.Coordinator.AdminAuthGroup = "test-adminis
trators" | 54 svcStub.ServiceConfig.Coordinator.AdminAuthGroup = "test-adminis
trators" |
54 c = coordinator.WithServices(c, &svcStub) | 55 c = coordinator.WithServices(c, &svcStub) |
55 | 56 |
56 » » s := New() | 57 » » svc := New() |
57 | 58 |
58 » » req := logdog.ListRequest{} | 59 » » // di is a datastore bound to the test project namespace. |
| 60 » » const project = "test-project" |
| 61 » » if err := coordinator.WithProjectNamespace(&c, config.ProjectNam
e(project)); err != nil { |
| 62 » » » panic(err) |
| 63 » » } |
| 64 » » di := ds.Get(c) |
| 65 |
| 66 » » req := logdog.ListRequest{ |
| 67 » » » Project: project, |
| 68 » » } |
59 | 69 |
60 // Install a set of stock log streams to query against. | 70 // Install a set of stock log streams to query against. |
61 streams := map[string]*coordinator.LogStream{} | 71 streams := map[string]*coordinator.LogStream{} |
62 descs := map[string]*logpb.LogStreamDescriptor{} | 72 descs := map[string]*logpb.LogStreamDescriptor{} |
63 for i, v := range []types.StreamPath{ | 73 for i, v := range []types.StreamPath{ |
64 "testing/+/foo", | 74 "testing/+/foo", |
65 "testing/+/foo/bar", | 75 "testing/+/foo/bar", |
66 "other/+/foo/bar", | 76 "other/+/foo/bar", |
67 "other/+/baz", | 77 "other/+/baz", |
68 "purged/+/foo", | 78 "purged/+/foo", |
69 } { | 79 } { |
70 prefix, name := v.Split() | 80 prefix, name := v.Split() |
71 desc := ct.TestLogStreamDescriptor(c, string(name)) | 81 desc := ct.TestLogStreamDescriptor(c, string(name)) |
72 desc.Prefix = string(prefix) | 82 desc.Prefix = string(prefix) |
73 | 83 |
74 ls := ct.TestLogStream(c, desc) | 84 ls := ct.TestLogStream(c, desc) |
75 » » » if err := hierarchy.Put(ds.Get(c), ls.Path()); err != ni
l { | 85 » » » if err := hierarchy.Put(di, ls.Path()); err != nil { |
76 panic(fmt.Errorf("failed to put log stream %d: %
v", i, err)) | 86 panic(fmt.Errorf("failed to put log stream %d: %
v", i, err)) |
77 } | 87 } |
78 | 88 |
79 if prefix.Segments()[0] == "purged" { | 89 if prefix.Segments()[0] == "purged" { |
80 » » » » if err := hierarchy.MarkPurged(ds.Get(c), ls.Pat
h(), true); err != nil { | 90 » » » » if err := hierarchy.MarkPurged(di, ls.Path(), tr
ue); err != nil { |
81 panic(fmt.Errorf("failed to purge log st
ream %d: %v", i, err)) | 91 panic(fmt.Errorf("failed to purge log st
ream %d: %v", i, err)) |
82 } | 92 } |
83 } | 93 } |
84 | 94 |
85 descs[string(v)] = desc | 95 descs[string(v)] = desc |
86 streams[string(v)] = ls | 96 streams[string(v)] = ls |
87 } | 97 } |
88 » » ds.Get(c).Testable().CatchupIndexes() | 98 » » di.Testable().CatchupIndexes() |
89 | 99 |
90 Convey(`A default list request will return top-level entries.`,
func() { | 100 Convey(`A default list request will return top-level entries.`,
func() { |
91 » » » l, err := s.List(c, &req) | 101 » » » l, err := svc.List(c, &req) |
92 So(err, ShouldBeRPCOK) | 102 So(err, ShouldBeRPCOK) |
93 So(listPaths(l), ShouldResemble, []string{"other", "purg
ed", "testing"}) | 103 So(listPaths(l), ShouldResemble, []string{"other", "purg
ed", "testing"}) |
94 }) | 104 }) |
95 | 105 |
| 106 Convey(`If the project does not exist, will return nothing.`, fu
nc() { |
| 107 req.Project = "does-not-exist" |
| 108 |
| 109 l, err := svc.List(c, &req) |
| 110 So(err, ShouldBeRPCOK) |
| 111 So(listPaths(l), ShouldResemble, []string{}) |
| 112 }) |
| 113 |
96 Convey(`Will skip elements if requested.`, func() { | 114 Convey(`Will skip elements if requested.`, func() { |
97 req.Offset = int32(2) | 115 req.Offset = int32(2) |
98 » » » l, err := s.List(c, &req) | 116 » » » l, err := svc.List(c, &req) |
99 So(err, ShouldBeRPCOK) | 117 So(err, ShouldBeRPCOK) |
100 So(listPaths(l), ShouldResemble, []string{"testing"}) | 118 So(listPaths(l), ShouldResemble, []string{"testing"}) |
101 }) | 119 }) |
102 | 120 |
103 Convey(`A recursive list will return all elements iteratively.`,
func() { | 121 Convey(`A recursive list will return all elements iteratively.`,
func() { |
104 req.Recursive = true | 122 req.Recursive = true |
105 req.MaxResults = 4 | 123 req.MaxResults = 4 |
106 | 124 |
107 for _, round := range [][]string{ | 125 for _, round := range [][]string{ |
108 {"other", "other/+", "other/+/baz$", "other/+/fo
o"}, | 126 {"other", "other/+", "other/+/baz$", "other/+/fo
o"}, |
109 {"other/+/foo/bar$", "purged", "purged/+", "test
ing"}, | 127 {"other/+/foo/bar$", "purged", "purged/+", "test
ing"}, |
110 {"testing/+", "testing/+/foo$", "testing/+/foo",
"testing/+/foo/bar$"}, | 128 {"testing/+", "testing/+/foo$", "testing/+/foo",
"testing/+/foo/bar$"}, |
111 {}, | 129 {}, |
112 } { | 130 } { |
113 » » » » l, err := s.List(c, &req) | 131 » » » » l, err := svc.List(c, &req) |
114 So(err, ShouldBeRPCOK) | 132 So(err, ShouldBeRPCOK) |
115 So(listPaths(l), ShouldResemble, round) | 133 So(listPaths(l), ShouldResemble, round) |
116 | 134 |
117 if len(round) < int(req.MaxResults) { | 135 if len(round) < int(req.MaxResults) { |
118 So(l.Next, ShouldEqual, "") | 136 So(l.Next, ShouldEqual, "") |
119 break | 137 break |
120 } | 138 } |
121 | 139 |
122 So(l.Next, ShouldNotEqual, "") | 140 So(l.Next, ShouldNotEqual, "") |
123 req.Next = l.Next | 141 req.Next = l.Next |
124 } | 142 } |
125 }) | 143 }) |
126 | 144 |
127 Convey(`A list including purged will fail for an unanthenticated
user.`, func() { | 145 Convey(`A list including purged will fail for an unanthenticated
user.`, func() { |
128 req.IncludePurged = true | 146 req.IncludePurged = true |
129 | 147 |
130 » » » _, err := s.List(c, &req) | 148 » » » _, err := svc.List(c, &req) |
131 So(err, ShouldBeRPCPermissionDenied) | 149 So(err, ShouldBeRPCPermissionDenied) |
132 }) | 150 }) |
133 | 151 |
134 Convey(`When logged in as an administrator`, func() { | 152 Convey(`When logged in as an administrator`, func() { |
135 fs.IdentityGroups = []string{"test-administrators"} | 153 fs.IdentityGroups = []string{"test-administrators"} |
136 | 154 |
137 Convey(`A list including purged will include purged elem
ents.`, func() { | 155 Convey(`A list including purged will include purged elem
ents.`, func() { |
138 req.StreamOnly = true | 156 req.StreamOnly = true |
139 req.Recursive = true | 157 req.Recursive = true |
140 req.IncludePurged = true | 158 req.IncludePurged = true |
141 | 159 |
142 » » » » l, err := s.List(c, &req) | 160 » » » » l, err := svc.List(c, &req) |
143 So(err, ShouldBeRPCOK) | 161 So(err, ShouldBeRPCOK) |
144 So(listPaths(l), ShouldResemble, []string{ | 162 So(listPaths(l), ShouldResemble, []string{ |
145 "other/+/baz$", | 163 "other/+/baz$", |
146 "other/+/foo/bar$", | 164 "other/+/foo/bar$", |
147 "purged/+/foo$", | 165 "purged/+/foo$", |
148 "testing/+/foo$", | 166 "testing/+/foo$", |
149 "testing/+/foo/bar$", | 167 "testing/+/foo/bar$", |
150 }) | 168 }) |
151 }) | 169 }) |
152 }) | 170 }) |
153 }) | 171 }) |
154 } | 172 } |
OLD | NEW |