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 "infra/gae/libs/meta" | 9 "infra/gae/libs/meta" |
10 "infra/gae/libs/wrapper" | 10 "infra/gae/libs/wrapper" |
11 "math" | |
11 "testing" | 12 "testing" |
12 | 13 |
13 . "github.com/smartystreets/goconvey/convey" | 14 . "github.com/smartystreets/goconvey/convey" |
14 "golang.org/x/net/context" | 15 "golang.org/x/net/context" |
15 | 16 |
16 "appengine/datastore" | 17 "appengine/datastore" |
17 ) | 18 ) |
18 | 19 |
19 func TestDatastoreKinder(t *testing.T) { | 20 func TestDatastoreKinder(t *testing.T) { |
20 t.Parallel() | 21 t.Parallel() |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
518 }) | 519 }) |
519 }) | 520 }) |
520 }) | 521 }) |
521 }) | 522 }) |
522 | 523 |
523 }) | 524 }) |
524 } | 525 } |
525 | 526 |
526 const MaxUint = ^uint(0) | 527 const MaxUint = ^uint(0) |
527 const MaxInt = int(MaxUint >> 1) | 528 const MaxInt = int(MaxUint >> 1) |
529 const IntIs32Bits = MaxInt < math.MaxInt64 | |
528 | 530 |
529 func TestDatastoreQueryer(t *testing.T) { | 531 func TestDatastoreQueryer(t *testing.T) { |
530 Convey("Datastore Query suport", t, func() { | 532 Convey("Datastore Query suport", t, func() { |
531 c := Use(context.Background()) | 533 c := Use(context.Background()) |
532 ds := wrapper.GetDS(c) | 534 ds := wrapper.GetDS(c) |
533 So(ds, ShouldNotBeNil) | 535 So(ds, ShouldNotBeNil) |
534 | 536 |
535 Convey("can create good queries", func() { | 537 Convey("can create good queries", func() { |
536 q := ds.NewQuery("Foo").KeysOnly().Limit(10).Offset(39) | 538 q := ds.NewQuery("Foo").KeysOnly().Limit(10).Offset(39) |
537 q = q.Start(queryCursor("kosmik")).End(queryCursor("krab s")) | 539 q = q.Start(queryCursor("kosmik")).End(queryCursor("krab s")) |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
589 }) | 591 }) |
590 Convey("bad order", func() { | 592 Convey("bad order", func() { |
591 q := q.Order("+Bob") | 593 q := q.Order("+Bob") |
592 So(q.(*queryImpl).err.Error(), ShouldContainSubs tring, "invalid order") | 594 So(q.(*queryImpl).err.Error(), ShouldContainSubs tring, "invalid order") |
593 }) | 595 }) |
594 Convey("empty", func() { | 596 Convey("empty", func() { |
595 q := q.Order("") | 597 q := q.Order("") |
596 So(q.(*queryImpl).err.Error(), ShouldContainSubs tring, "empty order") | 598 So(q.(*queryImpl).err.Error(), ShouldContainSubs tring, "empty order") |
597 }) | 599 }) |
598 Convey("OOB limit", func() { | 600 Convey("OOB limit", func() { |
599 » » » » q := q.Limit(MaxInt) | 601 » » » » // this is supremely stupid. The SDK uses 'int' which measn we have to |
M-A Ruel
2015/06/01 13:08:20
means
| |
600 » » » » So(q.(*queryImpl).err.Error(), ShouldContainSubs tring, "query limit overflow") | 602 » » » » // use it too, but then THEY BOUNDS CHECK IT FOR 32 BITS... *sigh* |
M-A Ruel
2015/06/01 13:08:19
bah, 2 millions items is large. it's probably more
| |
603 » » » » if !IntIs32Bits { | |
604 » » » » » q := q.Limit(MaxInt) | |
605 » » » » » So(q.(*queryImpl).err.Error(), ShouldCon tainSubstring, "query limit overflow") | |
606 » » » » } | |
601 }) | 607 }) |
602 Convey("underflow offset", func() { | 608 Convey("underflow offset", func() { |
603 q := q.Offset(-29) | 609 q := q.Offset(-29) |
604 So(q.(*queryImpl).err.Error(), ShouldContainSubs tring, "negative query offset") | 610 So(q.(*queryImpl).err.Error(), ShouldContainSubs tring, "negative query offset") |
605 }) | 611 }) |
606 Convey("OOB offset", func() { | 612 Convey("OOB offset", func() { |
607 » » » » q := q.Offset(MaxInt) | 613 » » » » if !IntIs32Bits { |
608 » » » » So(q.(*queryImpl).err.Error(), ShouldContainSubs tring, "query offset overflow") | 614 » » » » » q := q.Offset(MaxInt) |
615 » » » » » So(q.(*queryImpl).err.Error(), ShouldCon tainSubstring, "query offset overflow") | |
616 » » » » } | |
609 }) | 617 }) |
610 Convey("Bad cursors", func() { | 618 Convey("Bad cursors", func() { |
611 q := q.Start(queryCursor("")).End(queryCursor("" )) | 619 q := q.Start(queryCursor("")).End(queryCursor("" )) |
612 So(q.(*queryImpl).err.Error(), ShouldContainSubs tring, "invalid cursor") | 620 So(q.(*queryImpl).err.Error(), ShouldContainSubs tring, "invalid cursor") |
613 }) | 621 }) |
614 Convey("Bad ancestors", func() { | 622 Convey("Bad ancestors", func() { |
615 q := q.Ancestor(ds.NewKey("Goop", "wat", 10, nil )) | 623 q := q.Ancestor(ds.NewKey("Goop", "wat", 10, nil )) |
616 So(q, ShouldNotBeNil) | 624 So(q, ShouldNotBeNil) |
617 qi := q.(*queryImpl).checkCorrectness("", false) | 625 qi := q.(*queryImpl).checkCorrectness("", false) |
618 So(qi.err, ShouldEqual, datastore.ErrInvalidKey) | 626 So(qi.err, ShouldEqual, datastore.ErrInvalidKey) |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
665 }) | 673 }) |
666 Convey("kindless with decending-__key__ orders", func() { | 674 Convey("kindless with decending-__key__ orders", func() { |
667 q := ds.NewQuery("").Order("-__key__") | 675 q := ds.NewQuery("").Order("-__key__") |
668 qi := q.(*queryImpl).checkCorrectness("", false) | 676 qi := q.(*queryImpl).checkCorrectness("", false) |
669 So(qi.err.Error(), ShouldContainSubstring, "kind is required for all orders") | 677 So(qi.err.Error(), ShouldContainSubstring, "kind is required for all orders") |
670 }) | 678 }) |
671 }) | 679 }) |
672 | 680 |
673 }) | 681 }) |
674 } | 682 } |
OLD | NEW |