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 memory | 5 package memory |
6 | 6 |
7 import ( | 7 import ( |
8 "fmt" | 8 "fmt" |
9 "testing" | 9 "testing" |
10 "time" | 10 "time" |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 calls := 0 | 450 calls := 0 |
451 So(ds.RunInTransaction(func(c co
ntext.Context) error { | 451 So(ds.RunInTransaction(func(c co
ntext.Context) error { |
452 calls++ | 452 calls++ |
453 return fmt.Errorf("omg") | 453 return fmt.Errorf("omg") |
454 }, nil).Error(), ShouldEqual, "o
mg") | 454 }, nil).Error(), ShouldEqual, "o
mg") |
455 So(calls, ShouldEqual, 1) | 455 So(calls, ShouldEqual, 1) |
456 }) | 456 }) |
457 }) | 457 }) |
458 }) | 458 }) |
459 }) | 459 }) |
| 460 |
| 461 Convey("Testable.Consistent", func() { |
| 462 Convey("false", func() { |
| 463 ds.Testable().Consistent(false) // the default |
| 464 for i := 0; i < 10; i++ { |
| 465 So(ds.Put(&Foo{ID: int64(i + 1), Val: i
+ 1}), ShouldBeNil) |
| 466 } |
| 467 q := dsS.NewQuery("Foo").Gt("Val", 3) |
| 468 count, err := ds.Count(q) |
| 469 So(err, ShouldBeNil) |
| 470 So(count, ShouldEqual, 0) |
| 471 |
| 472 ds.Delete(ds.MakeKey("Foo", 4)) |
| 473 |
| 474 count, err = ds.Count(q) |
| 475 So(err, ShouldBeNil) |
| 476 So(count, ShouldEqual, 0) |
| 477 |
| 478 ds.Testable().Consistent(true) |
| 479 count, err = ds.Count(q) |
| 480 So(err, ShouldBeNil) |
| 481 So(count, ShouldEqual, 6) |
| 482 }) |
| 483 |
| 484 Convey("true", func() { |
| 485 ds.Testable().Consistent(true) |
| 486 for i := 0; i < 10; i++ { |
| 487 So(ds.Put(&Foo{ID: int64(i + 1), Val: i
+ 1}), ShouldBeNil) |
| 488 } |
| 489 q := dsS.NewQuery("Foo").Gt("Val", 3) |
| 490 count, err := ds.Count(q) |
| 491 So(err, ShouldBeNil) |
| 492 So(count, ShouldEqual, 7) |
| 493 |
| 494 ds.Delete(ds.MakeKey("Foo", 4)) |
| 495 |
| 496 count, err = ds.Count(q) |
| 497 So(err, ShouldBeNil) |
| 498 So(count, ShouldEqual, 6) |
| 499 }) |
| 500 }) |
460 }) | 501 }) |
461 } | 502 } |
462 | 503 |
463 func TestCompoundIndexes(t *testing.T) { | 504 func TestCompoundIndexes(t *testing.T) { |
464 t.Parallel() | 505 t.Parallel() |
465 | 506 |
466 idxKey := func(def dsS.IndexDefinition) string { | 507 idxKey := func(def dsS.IndexDefinition) string { |
467 So(def, ShouldNotBeNil) | 508 So(def, ShouldNotBeNil) |
468 return "idx::" + string(serialize.ToBytes(*def.PrepForIdxTable()
)) | 509 return "idx::" + string(serialize.ToBytes(*def.PrepForIdxTable()
)) |
469 } | 510 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 ds := dsS.Get(Use(context.Background())) | 568 ds := dsS.Get(Use(context.Background())) |
528 m := Model{ID: 1} | 569 m := Model{ID: 1} |
529 So(ds.Put(&m), ShouldBeNil) | 570 So(ds.Put(&m), ShouldBeNil) |
530 | 571 |
531 // Reset to something non zero to ensure zero is fetched. | 572 // Reset to something non zero to ensure zero is fetched. |
532 m.Time = time.Now().UTC() | 573 m.Time = time.Now().UTC() |
533 So(ds.Get(&m), ShouldBeNil) | 574 So(ds.Get(&m), ShouldBeNil) |
534 So(m.Time.IsZero(), ShouldBeTrue) | 575 So(m.Time.IsZero(), ShouldBeTrue) |
535 }) | 576 }) |
536 } | 577 } |
OLD | NEW |