mirror of
https://github.com/rancher/steve.git
synced 2025-09-16 07:18:28 +00:00
Add a missing test to verify we're parsing indirect queries correctly.
This commit is contained in:
@@ -25,11 +25,11 @@ const (
|
||||
|
||||
// ListOptions represents the query parameters that may be included in a list request.
|
||||
type ListOptions struct {
|
||||
ChunkSize int
|
||||
Resume string
|
||||
Filters []OrFilter
|
||||
SortList SortList
|
||||
Pagination Pagination
|
||||
ChunkSize int `json:"chunkSize"`
|
||||
Resume string `json:"resume"`
|
||||
Filters []OrFilter `json:"orFilters"`
|
||||
SortList SortList `json:"sortList"`
|
||||
Pagination Pagination `json:"pagination"`
|
||||
}
|
||||
|
||||
// Filter represents a field to filter by.
|
||||
@@ -40,12 +40,12 @@ type ListOptions struct {
|
||||
//
|
||||
// If more than one value is given for the `Match` field, we do an "IN (<values>)" test
|
||||
type Filter struct {
|
||||
Field []string
|
||||
Matches []string
|
||||
Op Op
|
||||
Partial bool
|
||||
IsIndirect bool
|
||||
IndirectFields []string
|
||||
Field []string `json:"fields"`
|
||||
Matches []string `json:"matches"`
|
||||
Op Op `json:"op"`
|
||||
Partial bool `json:"partial"`
|
||||
IsIndirect bool `json:"isIndirect"`
|
||||
IndirectFields []string `json:"indirectFields"`
|
||||
}
|
||||
|
||||
// OrFilter represents a set of possible fields to filter by, where an item may match any filter in the set to be included in the result.
|
||||
@@ -59,20 +59,20 @@ type OrFilter struct {
|
||||
// The order is represented by prefixing the sort key by '-', e.g. sort=-metadata.name.
|
||||
// e.g. To sort internal clusters first followed by clusters in alpha order: sort=-spec.internal,spec.displayName
|
||||
type Sort struct {
|
||||
Fields []string
|
||||
Order SortOrder
|
||||
IsIndirect bool
|
||||
IndirectFields []string
|
||||
Fields []string `json:"fields"`
|
||||
Order SortOrder `json:"order"`
|
||||
IsIndirect bool `json:"isIndirect"`
|
||||
IndirectFields []string `json:"indirectFields"`
|
||||
}
|
||||
|
||||
type SortList struct {
|
||||
SortDirectives []Sort
|
||||
SortDirectives []Sort `json:"sortDirectives"`
|
||||
}
|
||||
|
||||
// Pagination represents how to return paginated results.
|
||||
type Pagination struct {
|
||||
PageSize int
|
||||
Page int
|
||||
PageSize int `json:"pageSize"`
|
||||
Page int `json:"page"`
|
||||
}
|
||||
|
||||
func NewSortList() *SortList {
|
||||
|
@@ -73,11 +73,14 @@ func k8sRequirementToOrFilter(requirement queryparser.Requirement) (sqltypes.Fil
|
||||
values := requirement.Values()
|
||||
queryFields := splitQuery(requirement.Key())
|
||||
op, usePartialMatch, err := k8sOpToRancherOp(requirement.Operator())
|
||||
isIndirect, indirectFields := requirement.IndirectInfo()
|
||||
return sqltypes.Filter{
|
||||
Field: queryFields,
|
||||
Matches: values,
|
||||
Op: op,
|
||||
Partial: usePartialMatch,
|
||||
Field: queryFields,
|
||||
Matches: values,
|
||||
Op: op,
|
||||
Partial: usePartialMatch,
|
||||
IsIndirect: isIndirect,
|
||||
IndirectFields: indirectFields,
|
||||
}, err
|
||||
}
|
||||
|
||||
|
@@ -370,6 +370,33 @@ func TestParseQuery(t *testing.T) {
|
||||
},
|
||||
},
|
||||
})
|
||||
tests = append(tests, testCase{
|
||||
description: "ParseQuery() with an indirect labels filter param should create an indirect labels-specific filter.",
|
||||
req: &types.APIRequest{
|
||||
Request: &http.Request{
|
||||
URL: &url.URL{RawQuery: "filter=metadata.labels[grover.example.com/fish]=>[_v1][Foods][foodCode][country]=japan"},
|
||||
},
|
||||
},
|
||||
expectedLO: sqltypes.ListOptions{
|
||||
ChunkSize: defaultLimit,
|
||||
Filters: []sqltypes.OrFilter{
|
||||
{
|
||||
Filters: []sqltypes.Filter{
|
||||
{
|
||||
Field: []string{"metadata", "labels", "grover.example.com/fish"},
|
||||
Matches: []string{"japan"},
|
||||
Op: sqltypes.Eq,
|
||||
IsIndirect: true,
|
||||
IndirectFields: []string{"_v1", "Foods", "foodCode", "country"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Pagination: sqltypes.Pagination{
|
||||
Page: 1,
|
||||
},
|
||||
},
|
||||
})
|
||||
tests = append(tests, testCase{
|
||||
description: "ParseQuery() with multiple filter params, should include multiple or filters.",
|
||||
req: &types.APIRequest{
|
||||
|
Reference in New Issue
Block a user