mirror of
https://github.com/rancher/steve.git
synced 2025-09-06 01:41:00 +00:00
Generate field names with brackets when needed. (#477)
* Generate field names with brackets when needed. * Stop hard-wiring complex selectors as `["field1", "field2[sub-field3]"]` and instead represent them as a more consistent `["field1", "field2", "sub-field3"]` * Convert all filter strings ending with square brackets to an array. Stop special-casing 'metadata.labels[X]' and handle any query string that ends with '[...]'. * Stop checking for pre-bracketed terms in constant field-accessor arrays. In this commit we stop converting string arrays like `["metadata", "labels[k8s.io/deepcode]"]` into the database field `"metadata.labels[k8s.io/deepcode]"` and instead will do a naive `join` to give `metadata[labels[k8s.io/deepcode]]`. The solution is to never express the above terms in separate fields, like `["metadata", "labels", "k8s.io/deepcode"]`. This also better reflects the stucture of the referenced object. * gofmt changes * Simplify comment about 'smartJoin'.
This commit is contained in:
@@ -61,7 +61,7 @@ func (i *IntegrationSuite) TearDownSuite() {
|
||||
}
|
||||
|
||||
func (i *IntegrationSuite) TestSQLCacheFilters() {
|
||||
fields := [][]string{{`metadata`, `annotations[somekey]`}}
|
||||
fields := [][]string{{"metadata", "annotations", "somekey"}}
|
||||
require := i.Require()
|
||||
configMapWithAnnotations := func(name string, annotations map[string]string) v1.ConfigMap {
|
||||
return v1.ConfigMap{
|
||||
@@ -122,7 +122,7 @@ func (i *IntegrationSuite) TestSQLCacheFilters() {
|
||||
{
|
||||
name: "matches filter",
|
||||
filters: orFiltersForFilters(informer.Filter{
|
||||
Field: []string{`metadata`, `annotations[somekey]`},
|
||||
Field: []string{"metadata", "annotations", "somekey"},
|
||||
Matches: []string{"somevalue"},
|
||||
Op: informer.Eq,
|
||||
Partial: false,
|
||||
@@ -132,7 +132,7 @@ func (i *IntegrationSuite) TestSQLCacheFilters() {
|
||||
{
|
||||
name: "partial matches filter",
|
||||
filters: orFiltersForFilters(informer.Filter{
|
||||
Field: []string{`metadata`, `annotations[somekey]`},
|
||||
Field: []string{"metadata", "annotations", "somekey"},
|
||||
Matches: []string{"somevalue"},
|
||||
Op: informer.Eq,
|
||||
Partial: true,
|
||||
@@ -142,7 +142,7 @@ func (i *IntegrationSuite) TestSQLCacheFilters() {
|
||||
{
|
||||
name: "no matches for filter with underscore as it is interpreted literally",
|
||||
filters: orFiltersForFilters(informer.Filter{
|
||||
Field: []string{`metadata`, `annotations[somekey]`},
|
||||
Field: []string{"metadata", "annotations", "somekey"},
|
||||
Matches: []string{"somevalu_"},
|
||||
Op: informer.Eq,
|
||||
Partial: true,
|
||||
@@ -152,7 +152,7 @@ func (i *IntegrationSuite) TestSQLCacheFilters() {
|
||||
{
|
||||
name: "no matches for filter with percent sign as it is interpreted literally",
|
||||
filters: orFiltersForFilters(informer.Filter{
|
||||
Field: []string{`metadata`, `annotations[somekey]`},
|
||||
Field: []string{"metadata", "annotations", "somekey"},
|
||||
Matches: []string{"somevalu%"},
|
||||
Op: informer.Eq,
|
||||
Partial: true,
|
||||
@@ -162,7 +162,7 @@ func (i *IntegrationSuite) TestSQLCacheFilters() {
|
||||
{
|
||||
name: "match with special characters",
|
||||
filters: orFiltersForFilters(informer.Filter{
|
||||
Field: []string{`metadata`, `annotations[somekey]`},
|
||||
Field: []string{"metadata", "annotations", "somekey"},
|
||||
Matches: []string{"c%%l_value"},
|
||||
Op: informer.Eq,
|
||||
Partial: true,
|
||||
@@ -172,7 +172,7 @@ func (i *IntegrationSuite) TestSQLCacheFilters() {
|
||||
{
|
||||
name: "match with literal backslash character",
|
||||
filters: orFiltersForFilters(informer.Filter{
|
||||
Field: []string{`metadata`, `annotations[somekey]`},
|
||||
Field: []string{"metadata", "annotations", "somekey"},
|
||||
Matches: []string{`my\windows\path`},
|
||||
Op: informer.Eq,
|
||||
Partial: true,
|
||||
@@ -182,7 +182,7 @@ func (i *IntegrationSuite) TestSQLCacheFilters() {
|
||||
{
|
||||
name: "not eq filter",
|
||||
filters: orFiltersForFilters(informer.Filter{
|
||||
Field: []string{`metadata`, `annotations[somekey]`},
|
||||
Field: []string{"metadata", "annotations", "somekey"},
|
||||
Matches: []string{"somevalue"},
|
||||
Op: informer.NotEq,
|
||||
Partial: false,
|
||||
@@ -192,7 +192,7 @@ func (i *IntegrationSuite) TestSQLCacheFilters() {
|
||||
{
|
||||
name: "partial not eq filter",
|
||||
filters: orFiltersForFilters(informer.Filter{
|
||||
Field: []string{`metadata`, `annotations[somekey]`},
|
||||
Field: []string{"metadata", "annotations", "somekey"},
|
||||
Matches: []string{"somevalue"},
|
||||
Op: informer.NotEq,
|
||||
Partial: true,
|
||||
@@ -203,13 +203,13 @@ func (i *IntegrationSuite) TestSQLCacheFilters() {
|
||||
name: "multiple or filters match",
|
||||
filters: orFiltersForFilters(
|
||||
informer.Filter{
|
||||
Field: []string{`metadata`, `annotations[somekey]`},
|
||||
Field: []string{"metadata", "annotations", "somekey"},
|
||||
Matches: []string{"somevalue"},
|
||||
Op: informer.Eq,
|
||||
Partial: true,
|
||||
},
|
||||
informer.Filter{
|
||||
Field: []string{`metadata`, `annotations[somekey]`},
|
||||
Field: []string{"metadata", "annotations", "somekey"},
|
||||
Matches: []string{"notequal"},
|
||||
Op: informer.Eq,
|
||||
Partial: false,
|
||||
@@ -221,7 +221,7 @@ func (i *IntegrationSuite) TestSQLCacheFilters() {
|
||||
name: "or filters on different fields",
|
||||
filters: orFiltersForFilters(
|
||||
informer.Filter{
|
||||
Field: []string{`metadata`, `annotations[somekey]`},
|
||||
Field: []string{"metadata", "annotations", "somekey"},
|
||||
Matches: []string{"somevalue"},
|
||||
Op: informer.Eq,
|
||||
Partial: true,
|
||||
@@ -241,7 +241,7 @@ func (i *IntegrationSuite) TestSQLCacheFilters() {
|
||||
{
|
||||
Filters: []informer.Filter{
|
||||
{
|
||||
Field: []string{`metadata`, `annotations[somekey]`},
|
||||
Field: []string{"metadata", "annotations", "somekey"},
|
||||
Matches: []string{"somevalue"},
|
||||
Op: informer.Eq,
|
||||
Partial: true,
|
||||
@@ -265,7 +265,7 @@ func (i *IntegrationSuite) TestSQLCacheFilters() {
|
||||
name: "no matches",
|
||||
filters: orFiltersForFilters(
|
||||
informer.Filter{
|
||||
Field: []string{`metadata`, `annotations[somekey]`},
|
||||
Field: []string{"metadata", "annotations", "somekey"},
|
||||
Matches: []string{"valueNotRepresented"},
|
||||
Op: informer.Eq,
|
||||
Partial: false,
|
||||
|
Reference in New Issue
Block a user