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 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 ds := dsS.Get(Use(context.Background())) | 598 ds := dsS.Get(Use(context.Background())) |
599 m := Model{ID: 1} | 599 m := Model{ID: 1} |
600 So(ds.Put(&m), ShouldBeNil) | 600 So(ds.Put(&m), ShouldBeNil) |
601 | 601 |
602 // Reset to something non zero to ensure zero is fetched. | 602 // Reset to something non zero to ensure zero is fetched. |
603 m.Time = time.Now().UTC() | 603 m.Time = time.Now().UTC() |
604 So(ds.Get(&m), ShouldBeNil) | 604 So(ds.Get(&m), ShouldBeNil) |
605 So(m.Time.IsZero(), ShouldBeTrue) | 605 So(m.Time.IsZero(), ShouldBeTrue) |
606 }) | 606 }) |
607 } | 607 } |
| 608 |
| 609 func TestNewDatastore(t *testing.T) { |
| 610 t.Parallel() |
| 611 |
| 612 Convey("Can get and use a NewDatastore", t, func() { |
| 613 ds, err := NewDatastore("aid", "ns") |
| 614 So(err, ShouldBeNil) |
| 615 |
| 616 k := ds.MakeKey("Something", 1) |
| 617 So(k.AppID(), ShouldEqual, "aid") |
| 618 So(k.Namespace(), ShouldEqual, "ns") |
| 619 |
| 620 type Model struct { |
| 621 ID int64 `gae:"$id"` |
| 622 Value []int64 |
| 623 } |
| 624 So(ds.Put(&Model{ID: 1, Value: []int64{20, 30}}), ShouldBeNil) |
| 625 |
| 626 vals := []dsS.PropertyMap{} |
| 627 So(ds.GetAll(dsS.NewQuery("Model").Project("Value"), &vals), Sho
uldBeNil) |
| 628 So(len(vals), ShouldEqual, 2) |
| 629 |
| 630 So(vals[0]["Value"][0].Value(), ShouldEqual, 20) |
| 631 So(vals[1]["Value"][0].Value(), ShouldEqual, 30) |
| 632 }) |
| 633 } |
OLD | NEW |