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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 }) | 84 }) |
85 | 85 |
86 }) | 86 }) |
87 Convey("Deleteing with a bogus key is bad", func() { | 87 Convey("Deleteing with a bogus key is bad", func() { |
88 So(ds.Delete(ds.NewKey("Foo", "wat", 100, nil)),
ShouldEqual, dsS.ErrInvalidKey) | 88 So(ds.Delete(ds.NewKey("Foo", "wat", 100, nil)),
ShouldEqual, dsS.ErrInvalidKey) |
89 }) | 89 }) |
90 Convey("Deleteing a DNE entity is fine", func() { | 90 Convey("Deleteing a DNE entity is fine", func() { |
91 So(ds.Delete(ds.NewKey("Foo", "wat", 0, nil)), S
houldBeNil) | 91 So(ds.Delete(ds.NewKey("Foo", "wat", 0, nil)), S
houldBeNil) |
92 }) | 92 }) |
93 | 93 |
| 94 Convey("Deleting entities from a nonexistant namespace w
orks", func() { |
| 95 aid := infoS.Get(c).FullyQualifiedAppID() |
| 96 keys := make([]*dsS.Key, 10) |
| 97 for i := range keys { |
| 98 keys[i] = ds.MakeKey(aid, "noexist", "Ki
nd", i+1) |
| 99 } |
| 100 So(ds.DeleteMulti(keys), ShouldBeNil) |
| 101 count := 0 |
| 102 So(ds.Raw().DeleteMulti(keys, func(err error) { |
| 103 count++ |
| 104 So(err, ShouldBeNil) |
| 105 }), ShouldBeNil) |
| 106 So(count, ShouldEqual, len(keys)) |
| 107 }) |
| 108 |
94 Convey("with multiple puts", func() { | 109 Convey("with multiple puts", func() { |
95 So(testGetMeta(c, k), ShouldEqual, 1) | 110 So(testGetMeta(c, k), ShouldEqual, 1) |
96 | 111 |
97 foos := make([]Foo, 10) | 112 foos := make([]Foo, 10) |
98 for i := range foos { | 113 for i := range foos { |
99 foos[i].Val = 10 | 114 foos[i].Val = 10 |
100 foos[i].Parent = k | 115 foos[i].Parent = k |
101 } | 116 } |
102 So(ds.PutMulti(foos), ShouldBeNil) | 117 So(ds.PutMulti(foos), ShouldBeNil) |
103 So(testGetMeta(c, k), ShouldEqual, 11) | 118 So(testGetMeta(c, k), ShouldEqual, 11) |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 calls := 0 | 465 calls := 0 |
451 So(ds.RunInTransaction(func(c co
ntext.Context) error { | 466 So(ds.RunInTransaction(func(c co
ntext.Context) error { |
452 calls++ | 467 calls++ |
453 return fmt.Errorf("omg") | 468 return fmt.Errorf("omg") |
454 }, nil).Error(), ShouldEqual, "o
mg") | 469 }, nil).Error(), ShouldEqual, "o
mg") |
455 So(calls, ShouldEqual, 1) | 470 So(calls, ShouldEqual, 1) |
456 }) | 471 }) |
457 }) | 472 }) |
458 }) | 473 }) |
459 }) | 474 }) |
| 475 |
| 476 Convey("Testable.Consistent", func() { |
| 477 Convey("false", func() { |
| 478 ds.Testable().Consistent(false) // the default |
| 479 for i := 0; i < 10; i++ { |
| 480 So(ds.Put(&Foo{ID: int64(i + 1), Val: i
+ 1}), ShouldBeNil) |
| 481 } |
| 482 q := dsS.NewQuery("Foo").Gt("Val", 3) |
| 483 count, err := ds.Count(q) |
| 484 So(err, ShouldBeNil) |
| 485 So(count, ShouldEqual, 0) |
| 486 |
| 487 So(ds.Delete(ds.MakeKey("Foo", 4)), ShouldBeNil) |
| 488 |
| 489 count, err = ds.Count(q) |
| 490 So(err, ShouldBeNil) |
| 491 So(count, ShouldEqual, 0) |
| 492 |
| 493 ds.Testable().Consistent(true) |
| 494 count, err = ds.Count(q) |
| 495 So(err, ShouldBeNil) |
| 496 So(count, ShouldEqual, 6) |
| 497 }) |
| 498 |
| 499 Convey("true", func() { |
| 500 ds.Testable().Consistent(true) |
| 501 for i := 0; i < 10; i++ { |
| 502 So(ds.Put(&Foo{ID: int64(i + 1), Val: i
+ 1}), ShouldBeNil) |
| 503 } |
| 504 q := dsS.NewQuery("Foo").Gt("Val", 3) |
| 505 count, err := ds.Count(q) |
| 506 So(err, ShouldBeNil) |
| 507 So(count, ShouldEqual, 7) |
| 508 |
| 509 So(ds.Delete(ds.MakeKey("Foo", 4)), ShouldBeNil) |
| 510 |
| 511 count, err = ds.Count(q) |
| 512 So(err, ShouldBeNil) |
| 513 So(count, ShouldEqual, 6) |
| 514 }) |
| 515 }) |
460 }) | 516 }) |
461 } | 517 } |
462 | 518 |
463 func TestCompoundIndexes(t *testing.T) { | 519 func TestCompoundIndexes(t *testing.T) { |
464 t.Parallel() | 520 t.Parallel() |
465 | 521 |
466 idxKey := func(def dsS.IndexDefinition) string { | 522 idxKey := func(def dsS.IndexDefinition) string { |
467 So(def, ShouldNotBeNil) | 523 So(def, ShouldNotBeNil) |
468 return "idx::" + string(serialize.ToBytes(*def.PrepForIdxTable()
)) | 524 return "idx::" + string(serialize.ToBytes(*def.PrepForIdxTable()
)) |
469 } | 525 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 ds := dsS.Get(Use(context.Background())) | 583 ds := dsS.Get(Use(context.Background())) |
528 m := Model{ID: 1} | 584 m := Model{ID: 1} |
529 So(ds.Put(&m), ShouldBeNil) | 585 So(ds.Put(&m), ShouldBeNil) |
530 | 586 |
531 // Reset to something non zero to ensure zero is fetched. | 587 // Reset to something non zero to ensure zero is fetched. |
532 m.Time = time.Now().UTC() | 588 m.Time = time.Now().UTC() |
533 So(ds.Get(&m), ShouldBeNil) | 589 So(ds.Get(&m), ShouldBeNil) |
534 So(m.Time.IsZero(), ShouldBeTrue) | 590 So(m.Time.IsZero(), ShouldBeTrue) |
535 }) | 591 }) |
536 } | 592 } |
OLD | NEW |