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" |
11 | 11 |
12 dsS "github.com/luci/gae/service/datastore" | 12 dsS "github.com/luci/gae/service/datastore" |
13 "github.com/luci/gae/service/datastore/serialize" | 13 "github.com/luci/gae/service/datastore/serialize" |
14 infoS "github.com/luci/gae/service/info" | 14 infoS "github.com/luci/gae/service/info" |
| 15 . "github.com/luci/luci-go/common/testing/assertions" |
15 . "github.com/smartystreets/goconvey/convey" | 16 . "github.com/smartystreets/goconvey/convey" |
16 "golang.org/x/net/context" | 17 "golang.org/x/net/context" |
17 ) | 18 ) |
18 | 19 |
19 type MetaGroup struct { | 20 type MetaGroup struct { |
20 _id int64 `gae:"$id,1"` | 21 _id int64 `gae:"$id,1"` |
21 _kind string `gae:"$kind,__entity_group__"` | 22 _kind string `gae:"$kind,__entity_group__"` |
22 Parent *dsS.Key `gae:"$parent"` | 23 Parent *dsS.Key `gae:"$parent"` |
23 | 24 |
24 Version int64 `gae:"__version__"` | 25 Version int64 `gae:"__version__"` |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 So(err, ShouldBeNil) | 507 So(err, ShouldBeNil) |
507 So(count, ShouldEqual, 7) | 508 So(count, ShouldEqual, 7) |
508 | 509 |
509 So(ds.Delete(ds.MakeKey("Foo", 4)), ShouldBeNil) | 510 So(ds.Delete(ds.MakeKey("Foo", 4)), ShouldBeNil) |
510 | 511 |
511 count, err = ds.Count(q) | 512 count, err = ds.Count(q) |
512 So(err, ShouldBeNil) | 513 So(err, ShouldBeNil) |
513 So(count, ShouldEqual, 6) | 514 So(count, ShouldEqual, 6) |
514 }) | 515 }) |
515 }) | 516 }) |
| 517 |
| 518 Convey("Testable.DisableSpecialEntities", func() { |
| 519 ds.Testable().DisableSpecialEntities(true) |
| 520 |
| 521 So(ds.Put(&Foo{}), ShouldErrLike, "allocateIDs is disabl
ed") |
| 522 |
| 523 So(ds.Put(&Foo{ID: 1}), ShouldBeNil) |
| 524 |
| 525 ds.Testable().CatchupIndexes() |
| 526 |
| 527 count, err := ds.Count(dsS.NewQuery("")) |
| 528 So(err, ShouldBeNil) |
| 529 So(count, ShouldEqual, 1) // normally this would include
__entity_group__ |
| 530 }) |
516 }) | 531 }) |
517 } | 532 } |
518 | 533 |
519 func TestCompoundIndexes(t *testing.T) { | 534 func TestCompoundIndexes(t *testing.T) { |
520 t.Parallel() | 535 t.Parallel() |
521 | 536 |
522 idxKey := func(def dsS.IndexDefinition) string { | 537 idxKey := func(def dsS.IndexDefinition) string { |
523 So(def, ShouldNotBeNil) | 538 So(def, ShouldNotBeNil) |
524 return "idx::" + string(serialize.ToBytes(*def.PrepForIdxTable()
)) | 539 return "idx::" + string(serialize.ToBytes(*def.PrepForIdxTable()
)) |
525 } | 540 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 ds := dsS.Get(Use(context.Background())) | 598 ds := dsS.Get(Use(context.Background())) |
584 m := Model{ID: 1} | 599 m := Model{ID: 1} |
585 So(ds.Put(&m), ShouldBeNil) | 600 So(ds.Put(&m), ShouldBeNil) |
586 | 601 |
587 // Reset to something non zero to ensure zero is fetched. | 602 // Reset to something non zero to ensure zero is fetched. |
588 m.Time = time.Now().UTC() | 603 m.Time = time.Now().UTC() |
589 So(ds.Get(&m), ShouldBeNil) | 604 So(ds.Get(&m), ShouldBeNil) |
590 So(m.Time.IsZero(), ShouldBeTrue) | 605 So(m.Time.IsZero(), ShouldBeTrue) |
591 }) | 606 }) |
592 } | 607 } |
OLD | NEW |