-
Notifications
You must be signed in to change notification settings - Fork 353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wip: eskip: add more comment test cases #2866
Conversation
594f054
to
031c0a6
Compare
@@ -346,6 +346,16 @@ func TestParseFilters(t *testing.T) { | |||
`filter1(3.14) -> filter2("key", 42)`, | |||
[]*Filter{{Name: "filter1", Args: []interface{}{3.14}}, {Name: "filter2", Args: []interface{}{"key", float64(42)}}}, | |||
false, | |||
}, { | |||
"a comment produces empty filters without error", | |||
"// a comment", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its not clear whether we want to support comments or multiline strings for ParseFilters and ParsePredicates helpers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its tricky to support all test cases consistently due to how ParseFilters
(and ParsePredicates
fro that matter) is implemented:
rs, err := parse("* -> " + f + " -> <shunt>")
We can make comments on a separate line work by adding a newline:
rs, err := parse("* -> " + f + "\n -> <shunt>")
but its hard to make only comment input work:
rs, err := parse("* -> " + "// a comment" + "\n -> <shunt>")
because it produces invalid eskip.
We can not prohibit comments easily because they are skipped by lexer - the lexer would need to be changed to support "allow comments" flag.
Note also that due to use of "* -> "
prefix parse errors contain incorrect token offset value.
The proper fix would require:
- separate parse methods for routes, predicates and filters (see https://www.gnu.org/software/bison/manual/html_node/Multiple-start_002dsymbols.html)
- a lexer support to prohibit comments for
ParseFilters
andParsePredicates
if we decide so
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created a branch that separates document, predicates and filters parsing https://github.com/zalando/skipper/tree/eskip/separate-parse-predicates-filters
We can also disallow comments for ParsePredicates
and ParseFilters
, needs decision.
It includes several other changes that I'd like to land first before opening a PR.
Using the same approach of separate start symbols we can add singular ParseFilter
and ParsePredicate
for use in RouteGroup dataclient/validator instead of checking that ParseFilters
returned a single result:
skipper/dataclients/kubernetes/definitions/routegroupvalidator.go
Lines 69 to 74 in e63fe2c
filters, err := eskip.ParseFilters(f) | |
if err != nil { | |
errs = append(errs, err) | |
} else if len(filters) != 1 { | |
errs = append(errs, fmt.Errorf("%w at %q", errSingleFilterExpected, f)) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created draft PR #2873
Followup on #2849 Signed-off-by: Alexander Yastrebov <[email protected]>
031c0a6
to
9a2ac63
Compare
Should be rebased after #2874 gets merged. |
I've added these testcases to #2873 |
Followup on #2849