| 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 datastore | 5 package datastore |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "math" | 8 "math" |
| 9 "testing" | 9 "testing" |
| 10 | 10 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 75 |
| 76 func nq(kinds ...string) *Query { | 76 func nq(kinds ...string) *Query { |
| 77 kind := "Foo" | 77 kind := "Foo" |
| 78 if len(kinds) > 0 { | 78 if len(kinds) > 0 { |
| 79 kind = kinds[0] | 79 kind = kinds[0] |
| 80 } | 80 } |
| 81 return NewQuery(kind) | 81 return NewQuery(kind) |
| 82 } | 82 } |
| 83 | 83 |
| 84 func mkKey(elems ...interface{}) *Key { | 84 func mkKey(elems ...interface{}) *Key { |
| 85 » return MakeKey("s~aid", "ns", elems...) | 85 » return KeyContext{"s~aid", "ns"}.MakeKey(elems...) |
| 86 } | 86 } |
| 87 | 87 |
| 88 var queryTests = []queryTest{ | 88 var queryTests = []queryTest{ |
| 89 {"only one inequality", | 89 {"only one inequality", |
| 90 nq().Order("bob", "wat").Gt("bob", 10).Lt("wat", 29), | 90 nq().Order("bob", "wat").Gt("bob", 10).Lt("wat", 29), |
| 91 "", | 91 "", |
| 92 "inequality filters on multiple properties", nil}, | 92 "inequality filters on multiple properties", nil}, |
| 93 | 93 |
| 94 {"bad order", | 94 {"bad order", |
| 95 nq().Order("+Bob"), | 95 nq().Order("+Bob"), |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 } | 314 } |
| 315 | 315 |
| 316 func TestQueries(t *testing.T) { | 316 func TestQueries(t *testing.T) { |
| 317 t.Parallel() | 317 t.Parallel() |
| 318 | 318 |
| 319 Convey("queries have tons of condition checking", t, func() { | 319 Convey("queries have tons of condition checking", t, func() { |
| 320 for _, tc := range queryTests { | 320 for _, tc := range queryTests { |
| 321 Convey(tc.name, func() { | 321 Convey(tc.name, func() { |
| 322 fq, err := tc.q.Finalize() | 322 fq, err := tc.q.Finalize() |
| 323 if err == nil { | 323 if err == nil { |
| 324 » » » » » err = fq.Valid("s~aid", "ns") | 324 » » » » » err = fq.Valid(KeyContext{"s~aid", "ns"}
) |
| 325 } | 325 } |
| 326 So(err, ShouldErrLike, tc.err) | 326 So(err, ShouldErrLike, tc.err) |
| 327 | 327 |
| 328 if tc.gql != "" { | 328 if tc.gql != "" { |
| 329 So(fq.GQL(), ShouldEqual, tc.gql) | 329 So(fq.GQL(), ShouldEqual, tc.gql) |
| 330 } | 330 } |
| 331 | 331 |
| 332 if tc.equivalentQuery != nil { | 332 if tc.equivalentQuery != nil { |
| 333 fq2, err := tc.equivalentQuery.Finalize(
) | 333 fq2, err := tc.equivalentQuery.Finalize(
) |
| 334 So(err, ShouldBeNil) | 334 So(err, ShouldBeNil) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 return err | 370 return err |
| 371 } | 371 } |
| 372 } | 372 } |
| 373 }) | 373 }) |
| 374 } | 374 } |
| 375 } | 375 } |
| 376 }) | 376 }) |
| 377 So(err, ShouldBeNil) | 377 So(err, ShouldBeNil) |
| 378 }) | 378 }) |
| 379 } | 379 } |
| OLD | NEW |