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 // adapted from github.com/golang/appengine/datastore | 5 // adapted from github.com/golang/appengine/datastore |
6 | 6 |
7 package datastore | 7 package datastore |
8 | 8 |
9 import ( | 9 import ( |
10 "bytes" | |
11 "testing" | 10 "testing" |
12 | 11 |
13 . "github.com/smartystreets/goconvey/convey" | 12 . "github.com/smartystreets/goconvey/convey" |
14 ) | 13 ) |
15 | 14 |
16 func TestIndexDefinition(t *testing.T) { | 15 func TestIndexDefinition(t *testing.T) { |
17 t.Parallel() | 16 t.Parallel() |
18 | 17 |
19 Convey("Test IndexDefinition", t, func() { | 18 Convey("Test IndexDefinition", t, func() { |
20 Convey("basic", func() { | 19 Convey("basic", func() { |
(...skipping 13 matching lines...) Expand all Loading... |
34 id.Ancestor = true | 33 id.Ancestor = true |
35 So(id.Builtin(), ShouldBeFalse) | 34 So(id.Builtin(), ShouldBeFalse) |
36 So(id.Compound(), ShouldBeTrue) | 35 So(id.Compound(), ShouldBeTrue) |
37 So(id.String(), ShouldEqual, "C:kind|A/prop/-other") | 36 So(id.String(), ShouldEqual, "C:kind|A/prop/-other") |
38 | 37 |
39 // invalid | 38 // invalid |
40 id.SortBy = append(id.SortBy, IndexColumn{"", DESCENDING
}) | 39 id.SortBy = append(id.SortBy, IndexColumn{"", DESCENDING
}) |
41 So(id.Builtin(), ShouldBeFalse) | 40 So(id.Builtin(), ShouldBeFalse) |
42 So(id.Compound(), ShouldBeFalse) | 41 So(id.Compound(), ShouldBeFalse) |
43 }) | 42 }) |
44 | |
45 Convey("binary", func() { | |
46 id := IndexDefinition{Kind: "kind"} | |
47 buf := &bytes.Buffer{} | |
48 So(id.Write(buf), ShouldBeNil) | |
49 So(bytes.HasPrefix(buf.Bytes(), IndexBuiltinQueryPrefix(
)), ShouldBeTrue) | |
50 newId := IndexDefinition{} | |
51 So(newId.Read(buf), ShouldBeNil) | |
52 So(newId, ShouldResemble, id) | |
53 | |
54 id.SortBy = append(id.SortBy, IndexColumn{Property: "pro
p"}) | |
55 buf = &bytes.Buffer{} | |
56 So(id.Write(buf), ShouldBeNil) | |
57 So(bytes.HasPrefix(buf.Bytes(), IndexBuiltinQueryPrefix(
)), ShouldBeTrue) | |
58 newId = IndexDefinition{} | |
59 So(newId.Read(buf), ShouldBeNil) | |
60 So(newId, ShouldResemble, id) | |
61 | |
62 id.SortBy = append(id.SortBy, IndexColumn{"other", DESCE
NDING}) | |
63 id.Ancestor = true | |
64 buf = &bytes.Buffer{} | |
65 So(id.Write(buf), ShouldBeNil) | |
66 So(bytes.HasPrefix(buf.Bytes(), IndexComplexQueryPrefix(
)), ShouldBeTrue) | |
67 newId = IndexDefinition{} | |
68 So(newId.Read(buf), ShouldBeNil) | |
69 So(newId, ShouldResemble, id) | |
70 | |
71 // invalid | |
72 id.SortBy = append(id.SortBy, IndexColumn{"", DESCENDING
}) | |
73 buf = &bytes.Buffer{} | |
74 So(id.Write(buf), ShouldBeNil) | |
75 So(bytes.HasPrefix(buf.Bytes(), IndexComplexQueryPrefix(
)), ShouldBeTrue) | |
76 newId = IndexDefinition{} | |
77 So(newId.Read(buf), ShouldBeNil) | |
78 So(newId, ShouldResemble, id) | |
79 }) | |
80 | |
81 Convey("too many", func() { | |
82 id := IndexDefinition{Kind: "wat"} | |
83 for i := 0; i < MaxIndexColumns+1; i++ { | |
84 id.SortBy = append(id.SortBy, IndexColumn{"Hi",
ASCENDING}) | |
85 } | |
86 buf := &bytes.Buffer{} | |
87 So(id.Write(buf), ShouldBeNil) | |
88 newId := IndexDefinition{} | |
89 So(newId.Read(buf).Error(), ShouldContainSubstring, "ove
r 64 sort orders") | |
90 }) | |
91 }) | 43 }) |
92 } | 44 } |
OLD | NEW |