| 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"))
|
| + })
|
| + }
|
| })
|
| }
|
|
|