Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(499)

Side by Side Diff: impl/memory/datastore_test.go

Issue 2517833002: Fix #66. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « impl/memory/datastore_index_test.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package memory 5 package memory
6 6
7 import ( 7 import (
8 "errors" 8 "errors"
9 "fmt" 9 "fmt"
10 "testing" 10 "testing"
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 m := Model{ID: 1} 724 m := Model{ID: 1}
725 So(ds.Put(c, &m), ShouldBeNil) 725 So(ds.Put(c, &m), ShouldBeNil)
726 726
727 // Reset to something non zero to ensure zero is fetched. 727 // Reset to something non zero to ensure zero is fetched.
728 m.Time = time.Now().UTC() 728 m.Time = time.Now().UTC()
729 So(ds.Get(c, &m), ShouldBeNil) 729 So(ds.Get(c, &m), ShouldBeNil)
730 So(m.Time.IsZero(), ShouldBeTrue) 730 So(m.Time.IsZero(), ShouldBeTrue)
731 }) 731 })
732 } 732 }
733 733
734 // High level test for ancestor queries where the parent and child have
735 // identical fields. There was a bug where it would accidentally load the parent
736 // entity when attempt to query for the child.
737 func TestAncestorChildFieldQuery(t *testing.T) {
dnj 2016/11/20 16:44:25 Can this test be folded up into one of the "datast
738 ctx := Use(context.Background())
739 testable := ds.GetTestable(ctx)
740 testable.Consistent(true)
741 testable.AutoIndex(true)
742
743 type Parent struct {
744 _ int64 `gae:"$id,1"`
745 Created time.Time
746 }
747 p := Parent{}
748 if err := ds.Put(ctx, &p); err != nil {
749 t.Fatal(err)
750 }
751 // If you comment out the .Order part below, the test succeeds
dnj 2016/11/20 16:44:25 This comment can be removed.
752 q := ds.NewQuery("notParent").Ancestor(ds.KeyForObj(ctx, &p)).Order("-Cr eated")
753 if val, err := ds.Count(ctx, q); err != nil {
754 t.Fatal(err)
755 } else if val != 0 {
756 t.Fatalf("val: %d != 0", val)
757 }
758 }
759
734 func TestNewDatastore(t *testing.T) { 760 func TestNewDatastore(t *testing.T) {
735 t.Parallel() 761 t.Parallel()
736 762
737 Convey("Can get and use a NewDatastore", t, func() { 763 Convey("Can get and use a NewDatastore", t, func() {
738 c := UseWithAppID(context.Background(), "dev~aid") 764 c := UseWithAppID(context.Background(), "dev~aid")
739 c = infoS.MustNamespace(c, "ns") 765 c = infoS.MustNamespace(c, "ns")
740 766
741 dsInst := NewDatastore(c, infoS.Raw(c)) 767 dsInst := NewDatastore(c, infoS.Raw(c))
742 c = ds.SetRaw(c, dsInst) 768 c = ds.SetRaw(c, dsInst)
743 769
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 // Add "foos" to a new namespace, then confirm that it g ets indexed. 834 // Add "foos" to a new namespace, then confirm that it g ets indexed.
809 So(ds.Put(infoS.MustNamespace(ctx, "qux"), foos), Should BeNil) 835 So(ds.Put(infoS.MustNamespace(ctx, "qux"), foos), Should BeNil)
810 ds.GetTestable(ctx).CatchupIndexes() 836 ds.GetTestable(ctx).CatchupIndexes()
811 837
812 results = nil 838 results = nil
813 So(ds.GetAll(infoS.MustNamespace(ctx, "qux"), q, &result s), ShouldBeNil) 839 So(ds.GetAll(infoS.MustNamespace(ctx, "qux"), q, &result s), ShouldBeNil)
814 So(len(results), ShouldEqual, 2) 840 So(len(results), ShouldEqual, 2)
815 }) 841 })
816 }) 842 })
817 } 843 }
OLDNEW
« no previous file with comments | « impl/memory/datastore_index_test.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698