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 memory | 5 package memory |
6 | 6 |
7 import ( | 7 import ( |
8 "fmt" | 8 "fmt" |
9 "strings" | 9 "strings" |
10 "testing" | 10 "testing" |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 pmap("$key", mkKey("dev~app", "", "__nam
espace__", "bob")), | 359 pmap("$key", mkKey("dev~app", "", "__nam
espace__", "bob")), |
360 pmap("$key", mkKey("dev~app", "", "__nam
espace__", "ns")), | 360 pmap("$key", mkKey("dev~app", "", "__nam
espace__", "ns")), |
361 }}, | 361 }}, |
362 {q: nq("__namespace__").Offset(1), get: []ds.Pro
pertyMap{ | 362 {q: nq("__namespace__").Offset(1), get: []ds.Pro
pertyMap{ |
363 pmap("$key", mkKey("dev~app", "", "__nam
espace__", "bob")), | 363 pmap("$key", mkKey("dev~app", "", "__nam
espace__", "bob")), |
364 pmap("$key", mkKey("dev~app", "", "__nam
espace__", "ns")), | 364 pmap("$key", mkKey("dev~app", "", "__nam
espace__", "ns")), |
365 }}, | 365 }}, |
366 {q: nq("__namespace__").Offset(1).Limit(1), get:
[]ds.PropertyMap{ | 366 {q: nq("__namespace__").Offset(1).Limit(1), get:
[]ds.PropertyMap{ |
367 pmap("$key", mkKey("dev~app", "", "__nam
espace__", "bob")), | 367 pmap("$key", mkKey("dev~app", "", "__nam
espace__", "bob")), |
368 }}, | 368 }}, |
| 369 // |
| 370 // eventual consistency; Unique/1 is deleted at
HEAD. Keysonly finds it, |
| 371 // but 'normal' doesn't. |
| 372 {q: nq("Unique").Gt("__key__", key("AKind", 5)).
Lte("__key__", key("Zeta", "prime")), |
| 373 keys: []*ds.Key{key("Unique", 1)}, |
| 374 get: []ds.PropertyMap{}}, |
369 }, | 375 }, |
370 | 376 |
371 extraFns: []func(context.Context){ | 377 extraFns: []func(context.Context){ |
372 func(c context.Context) { | 378 func(c context.Context) { |
373 curs := ds.Cursor(nil) | 379 curs := ds.Cursor(nil) |
374 | 380 |
375 q := nq("").Gt("__key__", key("Kind", 2)
) | 381 q := nq("").Gt("__key__", key("Kind", 2)
) |
376 | 382 |
377 err := ds.Run(c, q, func(pm ds.PropertyM
ap, gc ds.CursorCB) error { | 383 err := ds.Run(c, q, func(pm ds.PropertyM
ap, gc ds.CursorCB) error { |
378 So(pm, ShouldResemble, pmap( | 384 So(pm, ShouldResemble, pmap( |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 " ancestor: yes", | 420 " ancestor: yes", |
415 " properties:", | 421 " properties:", |
416 " - name: Val", | 422 " - name: Val", |
417 }, "\n")) | 423 }, "\n")) |
418 }, | 424 }, |
419 }, | 425 }, |
420 }, | 426 }, |
421 | 427 |
422 { | 428 { |
423 expect: []qExpect{ | 429 expect: []qExpect{ |
424 // eventual consistency; Unique/1 is deleted at
HEAD. Keysonly finds it, | |
425 // but 'normal' doesn't. | |
426 {q: nq("Unique").Gt("__key__", key("AKind", 5)).
Lte("__key__", key("Zeta", "prime")), | |
427 keys: []*ds.Key{key("Unique", 1)}, | |
428 get: []ds.PropertyMap{}}, | |
429 | |
430 {q: nq("Kind").Eq("Val", 1, 3), get: []ds.Proper
tyMap{ | 430 {q: nq("Kind").Eq("Val", 1, 3), get: []ds.Proper
tyMap{ |
431 stage1Data[0], stage2Data[2], | 431 stage1Data[0], stage2Data[2], |
432 }}, | 432 }}, |
433 }, | 433 }, |
434 }, | 434 }, |
435 }}, | 435 }}, |
| 436 |
436 {"collapsed types", []qExStage{ | 437 {"collapsed types", []qExStage{ |
437 { | 438 { |
438 putEnts: collapsedData, | 439 putEnts: collapsedData, |
439 }, | 440 }, |
440 { | 441 { |
441 expect: []qExpect{ | 442 expect: []qExpect{ |
442 // PTTime | 443 // PTTime |
443 { | 444 { |
444 q: nq("Kind").Lte("Date", time.Date(2000
, time.February, 1, 1, 1, 1, 1, time.UTC)), | 445 q: nq("Kind").Lte("Date", time.Date(2000
, time.February, 1, 1, 1, 1, 1, time.UTC)), |
445 get: []ds.PropertyMap{ | 446 get: []ds.PropertyMap{ |
(...skipping 30 matching lines...) Expand all Loading... |
476 }, | 477 }, |
477 { | 478 { |
478 q: nq("Kind").Eq("Val", []byte("uwutm8")
), | 479 q: nq("Kind").Eq("Val", []byte("uwutm8")
), |
479 get: []ds.PropertyMap{ | 480 get: []ds.PropertyMap{ |
480 collapsedData[5], | 481 collapsedData[5], |
481 }, | 482 }, |
482 }, | 483 }, |
483 }, | 484 }, |
484 }, | 485 }, |
485 }}, | 486 }}, |
| 487 |
| 488 {"regression: tombstones and limit/offset queries", []qExStage{ |
| 489 { |
| 490 putEnts: []ds.PropertyMap{ |
| 491 pmap("$key", key("Kind", 1)), |
| 492 pmap("$key", key("Kind", 2)), |
| 493 pmap("$key", key("Kind", 3)), |
| 494 }, |
| 495 delEnts: []*ds.Key{key("Kind", 2)}, |
| 496 }, |
| 497 { |
| 498 expect: []qExpect{ |
| 499 { |
| 500 q: nq("Kind").Limit(2), |
| 501 get: []ds.PropertyMap{ |
| 502 pmap("$key", key("Kind", 1)), |
| 503 pmap("$key", key("Kind", 3)), |
| 504 }, |
| 505 }, |
| 506 |
| 507 { |
| 508 q: nq("Kind").Offset(2), |
| 509 get: []ds.PropertyMap{}, |
| 510 }, |
| 511 }, |
| 512 }, |
| 513 }}, |
486 } | 514 } |
487 | 515 |
488 func TestQueryExecution(t *testing.T) { | 516 func TestQueryExecution(t *testing.T) { |
489 t.Parallel() | 517 t.Parallel() |
490 | 518 |
491 Convey("Test query execution", t, func() { | 519 Convey("Test query execution", t, func() { |
492 c, err := info.Namespace(Use(context.Background()), "ns") | 520 c, err := info.Namespace(Use(context.Background()), "ns") |
493 if err != nil { | 521 if err != nil { |
494 panic(err) | 522 panic(err) |
495 } | 523 } |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 | 661 |
634 v, ok := actual.(error) | 662 v, ok := actual.(error) |
635 if !ok { | 663 if !ok { |
636 return fmt.Sprintf("type of 'actual' must be error, not %T", act
ual) | 664 return fmt.Sprintf("type of 'actual' must be error, not %T", act
ual) |
637 } | 665 } |
638 if v == nil || v == ds.Stop { | 666 if v == nil || v == ds.Stop { |
639 return "" | 667 return "" |
640 } | 668 } |
641 return fmt.Sprintf("expected success value, not %v", v) | 669 return fmt.Sprintf("expected success value, not %v", v) |
642 } | 670 } |
OLD | NEW |