Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1509)

Side by Side Diff: logdog/appengine/coordinator/hierarchy/hierarchy_test.go

Issue 2626433004: Move "common/config" common types into cfgtypes. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 hierarchy 5 package hierarchy
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 "testing" 9 "testing"
10 10
11 ds "github.com/luci/gae/service/datastore" 11 ds "github.com/luci/gae/service/datastore"
12 "github.com/luci/gae/service/info" 12 "github.com/luci/gae/service/info"
13 luciConfig "github.com/luci/luci-go/common/config"
14 "github.com/luci/luci-go/logdog/appengine/coordinator" 13 "github.com/luci/luci-go/logdog/appengine/coordinator"
15 ct "github.com/luci/luci-go/logdog/appengine/coordinator/coordinatorTest " 14 ct "github.com/luci/luci-go/logdog/appengine/coordinator/coordinatorTest "
16 "github.com/luci/luci-go/logdog/common/types" 15 "github.com/luci/luci-go/logdog/common/types"
16 "github.com/luci/luci-go/luci_config/common/cfgtypes"
17 17
18 . "github.com/luci/luci-go/common/testing/assertions" 18 . "github.com/luci/luci-go/common/testing/assertions"
19 . "github.com/smartystreets/goconvey/convey" 19 . "github.com/smartystreets/goconvey/convey"
20 ) 20 )
21 21
22 func TestHierarchy(t *testing.T) { 22 func TestHierarchy(t *testing.T) {
23 t.Parallel() 23 t.Parallel()
24 24
25 Convey(`With a testing configuration`, t, func() { 25 Convey(`With a testing configuration`, t, func() {
26 c, env := ct.Install() 26 c, env := ct.Install()
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 r.PathBase = "foo" 144 r.PathBase = "foo"
145 lv.pathBase = "foo" 145 lv.pathBase = "foo"
146 So(get(), lv.shouldHaveComponents) 146 So(get(), lv.shouldHaveComponents)
147 147
148 r.PathBase = "foo/+/bar" 148 r.PathBase = "foo/+/bar"
149 lv.pathBase = "foo/+/bar" 149 lv.pathBase = "foo/+/bar"
150 So(get(), lv.shouldHaveComponents) 150 So(get(), lv.shouldHaveComponents)
151 }) 151 })
152 152
153 Convey(`Can register a hierarchy of name components in multiple namespaces.`, func() { 153 Convey(`Can register a hierarchy of name components in multiple namespaces.`, func() {
154 » » » for _, proj := range []luciConfig.ProjectName{ 154 » » » for _, proj := range []cfgtypes.ProjectName{
155 "proj-foo", "proj-bar", "proj-exclusive", 155 "proj-foo", "proj-bar", "proj-exclusive",
156 } { 156 } {
157 // Bypass access check. 157 // Bypass access check.
158 ic := info.MustNamespace(c, coordinator.ProjectN amespace(proj)) 158 ic := info.MustNamespace(c, coordinator.ProjectN amespace(proj))
159 159
160 for _, p := range []types.StreamPath{ 160 for _, p := range []types.StreamPath{
161 "foo/+/baz", 161 "foo/+/baz",
162 "foo/+/qux", 162 "foo/+/qux",
163 "foo/+/qux", 163 "foo/+/qux",
164 "foo/+/qux/2468", 164 "foo/+/qux/2468",
(...skipping 15 matching lines...) Expand all
180 if err := c.Put(ic); err != nil { 180 if err := c.Put(ic); err != nil {
181 panic(err) 181 panic(err)
182 } 182 }
183 } 183 }
184 } 184 }
185 } 185 }
186 ds.GetTestable(c).CatchupIndexes() 186 ds.GetTestable(c).CatchupIndexes()
187 187
188 Convey(`Can list the hierarchy immediate paths (discrete ).`, func() { 188 Convey(`Can list the hierarchy immediate paths (discrete ).`, func() {
189 r.Project = "proj-foo" 189 r.Project = "proj-foo"
190 » » » » lv.project = luciConfig.ProjectName(r.Project) 190 » » » » lv.project = cfgtypes.ProjectName(r.Project)
191 191
192 list := func(b string) *List { 192 list := func(b string) *List {
193 r.Project = "proj-foo" 193 r.Project = "proj-foo"
194 r.PathBase = b 194 r.PathBase = b
195 195
196 // Set up our validator for these query results. 196 // Set up our validator for these query results.
197 lv.pathBase = types.StreamPath(r.PathBas e) 197 lv.pathBase = types.StreamPath(r.PathBas e)
198 return get() 198 return get()
199 } 199 }
200 200
201 So(list(""), lv.shouldHaveComponents, "bar", "fo o") 201 So(list(""), lv.shouldHaveComponents, "bar", "fo o")
202 So(list("foo"), lv.shouldHaveComponents, "+", "b ar") 202 So(list("foo"), lv.shouldHaveComponents, "+", "b ar")
203 So(list("foo/+"), lv.shouldHaveComponents, "14$" , "001337$", "bar$", "baz$", "qux$", "bar", "qux") 203 So(list("foo/+"), lv.shouldHaveComponents, "14$" , "001337$", "bar$", "baz$", "qux$", "bar", "qux")
204 So(list("foo/+/bar"), lv.shouldHaveComponents, " baz$") 204 So(list("foo/+/bar"), lv.shouldHaveComponents, " baz$")
205 So(list("foo/bar"), lv.shouldHaveComponents, "+" ) 205 So(list("foo/bar"), lv.shouldHaveComponents, "+" )
206 So(list("foo/bar/+"), lv.shouldHaveComponents, " baz$") 206 So(list("foo/bar/+"), lv.shouldHaveComponents, " baz$")
207 So(list("bar"), lv.shouldHaveComponents, "+") 207 So(list("bar"), lv.shouldHaveComponents, "+")
208 So(list("bar/+"), lv.shouldHaveComponents, "baz$ ", "baz") 208 So(list("bar/+"), lv.shouldHaveComponents, "baz$ ", "baz")
209 So(list("baz"), lv.shouldHaveComponents) 209 So(list("baz"), lv.shouldHaveComponents)
210 }) 210 })
211 211
212 Convey(`Performing discrete queries`, func() { 212 Convey(`Performing discrete queries`, func() {
213 r.Project = "proj-foo" 213 r.Project = "proj-foo"
214 » » » » lv.project = luciConfig.ProjectName(r.Project) 214 » » » » lv.project = cfgtypes.ProjectName(r.Project)
215 215
216 Convey(`When listing "proj-foo/foo/+"`, func() { 216 Convey(`When listing "proj-foo/foo/+"`, func() {
217 r.PathBase = "foo/+" 217 r.PathBase = "foo/+"
218 lv.pathBase = types.StreamPath(r.PathBas e) 218 lv.pathBase = types.StreamPath(r.PathBas e)
219 219
220 Convey(`Can list the first 2 elements.`, func() { 220 Convey(`Can list the first 2 elements.`, func() {
221 r.Limit = 2 221 r.Limit = 2
222 So(get(), lv.shouldHaveComponent s, "14$", "001337$") 222 So(get(), lv.shouldHaveComponent s, "14$", "001337$")
223 }) 223 })
224 224
(...skipping 30 matching lines...) Expand all
255 } 255 }
256 r.Next = l.Next 256 r.Next = l.Next
257 } 257 }
258 }) 258 })
259 }) 259 })
260 }) 260 })
261 }) 261 })
262 } 262 }
263 263
264 type listValidator struct { 264 type listValidator struct {
265 » project luciConfig.ProjectName 265 » project cfgtypes.ProjectName
266 pathBase types.StreamPath 266 pathBase types.StreamPath
267 } 267 }
268 268
269 func (lv *listValidator) shouldHaveComponents(actual interface{}, expected ...in terface{}) string { 269 func (lv *listValidator) shouldHaveComponents(actual interface{}, expected ...in terface{}) string {
270 a, ok := actual.(*List) 270 a, ok := actual.(*List)
271 if !ok { 271 if !ok {
272 return fmt.Sprintf("Actual value must be a *List, not %T", actua l) 272 return fmt.Sprintf("Actual value must be a *List, not %T", actua l)
273 } 273 }
274 274
275 // The project and path base components should match. 275 // The project and path base components should match.
(...skipping 28 matching lines...) Expand all
304 func norm(c []*ListComponent) []string { 304 func norm(c []*ListComponent) []string {
305 result := make([]string, len(c)) 305 result := make([]string, len(c))
306 for i, e := range c { 306 for i, e := range c {
307 result[i] = e.Name 307 result[i] = e.Name
308 if e.Stream { 308 if e.Stream {
309 result[i] += "$" 309 result[i] += "$"
310 } 310 }
311 } 311 }
312 return result 312 return result
313 } 313 }
OLDNEW
« no previous file with comments | « logdog/appengine/coordinator/hierarchy/hierarchy.go ('k') | logdog/appengine/coordinator/hierarchy/project.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698