mirror of
https://github.com/rancher/steve.git
synced 2025-09-18 00:08:17 +00:00
Add secondary sort parameter
Extend the sorting functionality in the partition store to support primary and secondary sorting criteria. Sorting parameters are specified by a single 'sort' query and comma separated. Example: Sort by name and creation time: GET /v1/secrets?sort=metadata.name,metadata.creationTimestamp Reverse sort by name, normal sort by creation time: GET /v1/secrets?sort=-metadata.name,metadata.creationTimestamp Normal sort by name, reverse sort by creation time: GET /v1/secrets?sort=metadata.name,-metadata.creationTimestamp
This commit is contained in:
@@ -413,6 +413,117 @@ func TestList(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "sorting with secondary sort",
|
||||
apiOps: []*types.APIRequest{
|
||||
newRequest("sort=data.color,metadata.name,", "user1"),
|
||||
},
|
||||
access: []map[string]string{
|
||||
{
|
||||
"user1": "roleA",
|
||||
},
|
||||
},
|
||||
partitions: map[string][]Partition{
|
||||
"user1": {
|
||||
mockPartition{
|
||||
name: "all",
|
||||
},
|
||||
},
|
||||
},
|
||||
objects: map[string]*unstructured.UnstructuredList{
|
||||
"all": {
|
||||
Items: []unstructured.Unstructured{
|
||||
newApple("fuji").Unstructured,
|
||||
newApple("honeycrisp").Unstructured,
|
||||
newApple("granny-smith").Unstructured,
|
||||
},
|
||||
},
|
||||
},
|
||||
want: []types.APIObjectList{
|
||||
{
|
||||
Count: 3,
|
||||
Objects: []types.APIObject{
|
||||
newApple("granny-smith").toObj(),
|
||||
newApple("fuji").toObj(),
|
||||
newApple("honeycrisp").toObj(),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "sorting with missing primary sort is unsorted",
|
||||
apiOps: []*types.APIRequest{
|
||||
newRequest("sort=,metadata.name", "user1"),
|
||||
},
|
||||
access: []map[string]string{
|
||||
{
|
||||
"user1": "roleA",
|
||||
},
|
||||
},
|
||||
partitions: map[string][]Partition{
|
||||
"user1": {
|
||||
mockPartition{
|
||||
name: "all",
|
||||
},
|
||||
},
|
||||
},
|
||||
objects: map[string]*unstructured.UnstructuredList{
|
||||
"all": {
|
||||
Items: []unstructured.Unstructured{
|
||||
newApple("fuji").Unstructured,
|
||||
newApple("honeycrisp").Unstructured,
|
||||
newApple("granny-smith").Unstructured,
|
||||
},
|
||||
},
|
||||
},
|
||||
want: []types.APIObjectList{
|
||||
{
|
||||
Count: 3,
|
||||
Objects: []types.APIObject{
|
||||
newApple("fuji").toObj(),
|
||||
newApple("honeycrisp").toObj(),
|
||||
newApple("granny-smith").toObj(),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "sorting with missing secondary sort is single-column sorted",
|
||||
apiOps: []*types.APIRequest{
|
||||
newRequest("sort=metadata.name,", "user1"),
|
||||
},
|
||||
access: []map[string]string{
|
||||
{
|
||||
"user1": "roleA",
|
||||
},
|
||||
},
|
||||
partitions: map[string][]Partition{
|
||||
"user1": {
|
||||
mockPartition{
|
||||
name: "all",
|
||||
},
|
||||
},
|
||||
},
|
||||
objects: map[string]*unstructured.UnstructuredList{
|
||||
"all": {
|
||||
Items: []unstructured.Unstructured{
|
||||
newApple("fuji").Unstructured,
|
||||
newApple("honeycrisp").Unstructured,
|
||||
newApple("granny-smith").Unstructured,
|
||||
},
|
||||
},
|
||||
},
|
||||
want: []types.APIObjectList{
|
||||
{
|
||||
Count: 3,
|
||||
Objects: []types.APIObject{
|
||||
newApple("fuji").toObj(),
|
||||
newApple("granny-smith").toObj(),
|
||||
newApple("honeycrisp").toObj(),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "multi-partition sort=metadata.name",
|
||||
apiOps: []*types.APIRequest{
|
||||
|
Reference in New Issue
Block a user