VOL-3190 support nested ordering;
throw errors when fields don't exist
Change-Id: Ia607db45aec03413ffaf0696ee4043e42679803a
diff --git a/pkg/order/order_test.go b/pkg/order/order_test.go
index eba6fe2..28132d9 100644
--- a/pkg/order/order_test.go
+++ b/pkg/order/order_test.go
@@ -17,15 +17,21 @@
package order
import (
+ "github.com/stretchr/testify/assert"
"testing"
)
+type SortIncludedStruct struct {
+ Seven string
+}
+
type SortTestStruct struct {
Id int
One string
Two string
Three uint
Four int
+ Six SortIncludedStruct
}
var testSetOne = []SortTestStruct{
@@ -35,6 +41,7 @@
Two: "x",
Three: 10,
Four: 1,
+ Six: SortIncludedStruct{Seven: "o"},
},
{
Id: 1,
@@ -42,6 +49,7 @@
Two: "c",
Three: 1,
Four: 10,
+ Six: SortIncludedStruct{Seven: "p"},
},
{
Id: 2,
@@ -49,6 +57,7 @@
Two: "b",
Three: 2,
Four: 1000,
+ Six: SortIncludedStruct{Seven: "q"},
},
{
Id: 3,
@@ -56,6 +65,7 @@
Two: "a",
Three: 3,
Four: 100,
+ Six: SortIncludedStruct{Seven: "r"},
},
{
Id: 4,
@@ -63,6 +73,7 @@
Two: "a",
Three: 3,
Four: 0,
+ Six: SortIncludedStruct{Seven: "s"},
},
}
@@ -245,3 +256,54 @@
t.Errorf("results don't match input")
}
}
+
+func TestSortDotted(t *testing.T) {
+ s, err := Parse("+Six.Seven")
+ if err != nil {
+ t.Errorf("Unable to parse sort specification")
+ }
+ o, err := s.Process(testSetOne)
+ if err != nil {
+ t.Errorf("Sort failed: %s", err.Error())
+ }
+
+ if !Verify(o.([]SortTestStruct), []int{0, 1, 2, 3, 4}) {
+ t.Errorf("incorrect sort")
+ }
+}
+
+func TestInvaliodDotted(t *testing.T) {
+ s, err := Parse("+Six.Nonexistent")
+ if err != nil {
+ t.Errorf("Unable to parse sort specification")
+ }
+ o, err := s.Process(testSetOne)
+ assert.EqualError(t, err, "Failed to find field Nonexistent while sorting")
+ if o != nil {
+ t.Errorf("expected no results, got some")
+ }
+}
+
+func TestDotOnString(t *testing.T) {
+ s, err := Parse("+One.IsNotAStruct")
+ if err != nil {
+ t.Errorf("Unable to parse sort specification")
+ }
+ o, err := s.Process(testSetOne)
+ assert.EqualError(t, err, "Dotted field name specified in filter did not resolve to a valid field")
+ if o != nil {
+ t.Errorf("expected no results, got some")
+ }
+}
+
+func TestTrailingDot(t *testing.T) {
+ s, err := Parse("+Six.Seven.")
+ if err != nil {
+ t.Errorf("Unable to parse sort specification")
+ }
+ o, err := s.Process(testSetOne)
+ assert.EqualError(t, err, "Dotted field name specified in filter did not resolve to a valid field")
+ if o != nil {
+ t.Errorf("expected no results, got some")
+ }
+}