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

Unified Diff: service/datastore/index_test.go

Issue 1364333002: Add AutoIndex (Closed) Base URL: https://github.com/luci/gae.git@add_full_consistency
Patch Set: symbollls Created 5 years, 3 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « service/datastore/index.go ('k') | service/datastore/testable.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: service/datastore/index_test.go
diff --git a/service/datastore/index_test.go b/service/datastore/index_test.go
index 6eb523e91213fc597b206e047e788babad185e08..6ec9d0953a369a19083f4b131fdf2969cc7624de 100644
--- a/service/datastore/index_test.go
+++ b/service/datastore/index_test.go
@@ -7,38 +7,77 @@
package datastore
import (
+ "strings"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
+var indexDefinitionTests = []struct {
+ id *IndexDefinition
+ builtin bool
+ compound bool
+ str string
+ yaml []string
+}{
+ {
+ id: &IndexDefinition{Kind: "kind"},
+ builtin: true,
+ str: "B:kind",
+ },
+
+ {
+ id: &IndexDefinition{
+ Kind: "kind",
+ SortBy: []IndexColumn{{Property: ""}},
+ },
+ builtin: true,
+ str: "B:kind/",
+ },
+
+ {
+ id: &IndexDefinition{
+ Kind: "kind",
+ SortBy: []IndexColumn{{Property: "prop"}},
+ },
+ builtin: true,
+ str: "B:kind/prop",
+ },
+
+ {
+ id: &IndexDefinition{
+ Kind: "Kind",
+ Ancestor: true,
+ SortBy: []IndexColumn{
+ {Property: "prop"},
+ {Property: "other", Descending: true},
+ },
+ },
+ compound: true,
+ str: "C:Kind|A/prop/-other",
+ yaml: []string{
+ "- kind: Kind",
+ " ancestor: yes",
+ " properties:",
+ " - name: prop",
+ " - name: other",
+ " direction: desc",
+ },
+ },
+}
+
func TestIndexDefinition(t *testing.T) {
t.Parallel()
Convey("Test IndexDefinition", t, func() {
- Convey("basic", func() {
- id := IndexDefinition{Kind: "kind"}
-
- So(id.Builtin(), ShouldBeTrue)
- So(id.Compound(), ShouldBeFalse)
- So(id.String(), ShouldEqual, "B:kind")
-
- id.SortBy = append(id.SortBy, IndexColumn{Property: "prop"})
- So(id.SortBy[0].Descending, ShouldBeFalse)
- So(id.Builtin(), ShouldBeTrue)
- So(id.Compound(), ShouldBeFalse)
- So(id.String(), ShouldEqual, "B:kind/prop")
-
- id.SortBy = append(id.SortBy, IndexColumn{Property: "other", Descending: true})
- id.Ancestor = true
- So(id.Builtin(), ShouldBeFalse)
- So(id.Compound(), ShouldBeTrue)
- So(id.String(), ShouldEqual, "C:kind|A/prop/-other")
-
- // invalid
- id.SortBy = append(id.SortBy, IndexColumn{Property: "", Descending: true})
- So(id.Builtin(), ShouldBeFalse)
- So(id.Compound(), ShouldBeFalse)
- })
+ for _, tc := range indexDefinitionTests {
+ Convey(tc.str, func() {
+ So(tc.id.String(), ShouldEqual, tc.str)
+ So(tc.id.Builtin(), ShouldEqual, tc.builtin)
+ So(tc.id.Compound(), ShouldEqual, tc.compound)
+ yaml, _ := tc.id.YAMLString()
+ So(yaml, ShouldEqual, strings.Join(tc.yaml, "\n"))
+ })
+ }
})
}
« no previous file with comments | « service/datastore/index.go ('k') | service/datastore/testable.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698