| 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 So(testGetMeta(c, k), ShouldEqual, 11) | 103 So(testGetMeta(c, k), ShouldEqual, 11) |
| 104 | 104 |
| 105 keys := make([]*dsS.Key, len(foos)) | 105 keys := make([]*dsS.Key, len(foos)) |
| 106 for i, f := range foos { | 106 for i, f := range foos { |
| 107 keys[i] = ds.KeyForObj(&f) | 107 keys[i] = ds.KeyForObj(&f) |
| 108 } | 108 } |
| 109 | 109 |
| 110 Convey("ensure that group versions persist acros
s deletes", func() { | 110 Convey("ensure that group versions persist acros
s deletes", func() { |
| 111 So(ds.DeleteMulti(append(keys, k)), Shou
ldBeNil) | 111 So(ds.DeleteMulti(append(keys, k)), Shou
ldBeNil) |
| 112 | 112 |
| 113 » » » » » // TODO(riannucci): replace with a Count
query instead of this cast | 113 » » » » » ds.Testable().CatchupIndexes() |
| 114 » » » » » /* | 114 |
| 115 » » » » » » ents := ds.(*dsImpl).data.head.G
etCollection("ents:") | 115 » » » » » count := 0 |
| 116 » » » » » » num, _ := ents.GetTotals() | 116 » » » » » So(ds.Run(dsS.NewQuery(""), func(_ *dsS.
Key, _ dsS.CursorCB) bool { |
| 117 » » » » » » // /__entity_root_ids__,Foo | 117 » » » » » » count++ |
| 118 » » » » » » // /Foo,1/__entity_group__,1 | 118 » » » » » » return true |
| 119 » » » » » » // /Foo,1/__entity_group_ids__,1 | 119 » » » » » }), ShouldBeNil) |
| 120 » » » » » » So(num, ShouldEqual, 3) | 120 » » » » » So(count, ShouldEqual, 3) |
| 121 » » » » » */ | |
| 122 | 121 |
| 123 So(testGetMeta(c, k), ShouldEqual, 22) | 122 So(testGetMeta(c, k), ShouldEqual, 22) |
| 124 | 123 |
| 125 So(ds.Put(&Foo{ID: 1}), ShouldBeNil) | 124 So(ds.Put(&Foo{ID: 1}), ShouldBeNil) |
| 126 So(testGetMeta(c, k), ShouldEqual, 23) | 125 So(testGetMeta(c, k), ShouldEqual, 23) |
| 127 }) | 126 }) |
| 128 | 127 |
| 129 Convey("can Get", func() { | 128 Convey("can Get", func() { |
| 130 vals := make([]dsS.PropertyMap, len(keys
)) | 129 vals := make([]dsS.PropertyMap, len(keys
)) |
| 131 for i := range vals { | 130 for i := range vals { |
| 132 vals[i] = dsS.PropertyMap{} | 131 vals[i] = dsS.PropertyMap{} |
| 133 So(vals[i].SetMeta("key", keys[i
]), ShouldBeNil) | 132 So(vals[i].SetMeta("key", keys[i
]), ShouldBeNil) |
| 134 } | 133 } |
| 135 So(ds.GetMulti(vals), ShouldBeNil) | 134 So(ds.GetMulti(vals), ShouldBeNil) |
| 136 | 135 |
| 137 for i, val := range vals { | 136 for i, val := range vals { |
| 138 So(val, ShouldResemble, dsS.Prop
ertyMap{ | 137 So(val, ShouldResemble, dsS.Prop
ertyMap{ |
| 139 "Val": {dsS.MkProperty(
10)}, | 138 "Val": {dsS.MkProperty(
10)}, |
| 140 "$key": {dsS.MkPropertyN
I(keys[i])}, | 139 "$key": {dsS.MkPropertyN
I(keys[i])}, |
| 141 }) | 140 }) |
| 142 } | 141 } |
| 143 }) | 142 }) |
| 144 | 143 |
| 145 }) | 144 }) |
| 145 |
| 146 Convey("allocating ids prevents their use", func() { |
| 147 start, err := ds.AllocateIDs(ds.MakeKey("Foo", 0
), 100) |
| 148 So(err, ShouldBeNil) |
| 149 So(start, ShouldEqual, 2) |
| 150 |
| 151 f := &Foo{Val: 10} |
| 152 So(ds.Put(f), ShouldBeNil) |
| 153 k := ds.KeyForObj(f) |
| 154 So(k.String(), ShouldEqual, "dev~app::/Foo,102") |
| 155 }) |
| 146 }) | 156 }) |
| 147 | 157 |
| 148 Convey("implements DSTransactioner", func() { | 158 Convey("implements DSTransactioner", func() { |
| 149 Convey("Put", func() { | 159 Convey("Put", func() { |
| 150 f := &Foo{Val: 10} | 160 f := &Foo{Val: 10} |
| 151 So(ds.Put(f), ShouldBeNil) | 161 So(ds.Put(f), ShouldBeNil) |
| 152 k := ds.KeyForObj(f) | 162 k := ds.KeyForObj(f) |
| 153 So(k.String(), ShouldEqual, "dev~app::/Foo,1") | 163 So(k.String(), ShouldEqual, "dev~app::/Foo,1") |
| 154 | 164 |
| 155 Convey("can Put new entity groups", func() { | 165 Convey("can Put new entity groups", func() { |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 ds := dsS.Get(Use(context.Background())) | 527 ds := dsS.Get(Use(context.Background())) |
| 518 m := Model{ID: 1} | 528 m := Model{ID: 1} |
| 519 So(ds.Put(&m), ShouldBeNil) | 529 So(ds.Put(&m), ShouldBeNil) |
| 520 | 530 |
| 521 // Reset to something non zero to ensure zero is fetched. | 531 // Reset to something non zero to ensure zero is fetched. |
| 522 m.Time = time.Now().UTC() | 532 m.Time = time.Now().UTC() |
| 523 So(ds.Get(&m), ShouldBeNil) | 533 So(ds.Get(&m), ShouldBeNil) |
| 524 So(m.Time.IsZero(), ShouldBeTrue) | 534 So(m.Time.IsZero(), ShouldBeTrue) |
| 525 }) | 535 }) |
| 526 } | 536 } |
| OLD | NEW |