mirror of
https://github.com/rancher/steve.git
synced 2025-08-13 03:55:19 +00:00
Fix the ListOptions sort field.
Instead of making it a single array-ish field, convert it into a true array of Sort Directives. Easier to read, less bending backwards.
This commit is contained in:
parent
ec49b857fa
commit
a0d591a9b5
@ -6,7 +6,6 @@ import (
|
|||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/rancher/steve/pkg/sqlcache/sqltypes"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -817,27 +817,6 @@ func TestListByOptions(t *testing.T) {
|
|||||||
expectedErr: nil,
|
expectedErr: nil,
|
||||||
})
|
})
|
||||||
|
|
||||||
tests = append(tests, testCase{
|
|
||||||
description: "ListByOptions sorting when # fields != # sort orders should return an error",
|
|
||||||
listOptions: sqltypes.ListOptions{
|
|
||||||
Sort: sqltypes.Sort{
|
|
||||||
Fields: [][]string{{"metadata", "somefield"}, {"status", "someotherfield"}},
|
|
||||||
Orders: []sqltypes.SortOrder{sqltypes.DESC, sqltypes.ASC, sqltypes.ASC},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
partitions: []partition.Partition{},
|
|
||||||
ns: "",
|
|
||||||
expectedStmt: `SELECT o.object, o.objectnonce, o.dekid FROM "something" o
|
|
||||||
JOIN "something_fields" f ON o.key = f.key
|
|
||||||
WHERE
|
|
||||||
(FALSE)
|
|
||||||
ORDER BY f."metadata.somefield" DESC, f."status.someotherfield" ASC`,
|
|
||||||
returnList: []any{&unstructured.Unstructured{Object: unstrTestObjectMap}, &unstructured.Unstructured{Object: unstrTestObjectMap}},
|
|
||||||
expectedList: &unstructured.UnstructuredList{Object: map[string]interface{}{"items": []map[string]interface{}{unstrTestObjectMap, unstrTestObjectMap}}, Items: []unstructured.Unstructured{{Object: unstrTestObjectMap}, {Object: unstrTestObjectMap}}},
|
|
||||||
expectedContToken: "",
|
|
||||||
expectedErr: fmt.Errorf("sort fields length 2 != sort orders length 3"),
|
|
||||||
})
|
|
||||||
|
|
||||||
tests = append(tests, testCase{
|
tests = append(tests, testCase{
|
||||||
description: "ListByOptions with Pagination.PageSize set should set limit to PageSize in prepared sql.Stmt",
|
description: "ListByOptions with Pagination.PageSize set should set limit to PageSize in prepared sql.Stmt",
|
||||||
listOptions: sqltypes.ListOptions{
|
listOptions: sqltypes.ListOptions{
|
||||||
|
@ -65,10 +65,6 @@ type SortList struct {
|
|||||||
SortDirectives []Sort
|
SortDirectives []Sort
|
||||||
}
|
}
|
||||||
|
|
||||||
type SortList struct {
|
|
||||||
SortDirectives []Sort
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pagination represents how to return paginated results.
|
// Pagination represents how to return paginated results.
|
||||||
type Pagination struct {
|
type Pagination struct {
|
||||||
PageSize int
|
PageSize int
|
||||||
@ -80,9 +76,3 @@ func NewSortList() *SortList {
|
|||||||
SortDirectives: []Sort{},
|
SortDirectives: []Sort{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSortList() *SortList {
|
|
||||||
return &SortList{
|
|
||||||
SortDirectives: []Sort{},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user