Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

AlexanderYastrebov
Copy link
Member

Followup on #2849

@AlexanderYastrebov AlexanderYastrebov added the wip work in progress label Jan 15, 2024
@AlexanderYastrebov AlexanderYastrebov force-pushed the eskip/parse-filters-comment branch from 594f054 to 031c0a6 Compare January 15, 2024 14:23
@AlexanderYastrebov AlexanderYastrebov changed the title wip: eskip: add comment test cases for ParseFilters wip: eskip: add more comment test cases Jan 15, 2024
@AlexanderYastrebov AlexanderYastrebov added the minor no risk changes, for example new filters label Jan 15, 2024
@@ -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",
Copy link
Member Author

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.

Copy link
Member Author

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:

Copy link
Member Author

@AlexanderYastrebov AlexanderYastrebov Jan 17, 2024

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:

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))
}

Copy link
Member Author

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]>
@AlexanderYastrebov
Copy link
Member Author

Should be rebased after #2874 gets merged.

@AlexanderYastrebov
Copy link
Member Author

I've added these testcases to #2873

@AlexanderYastrebov AlexanderYastrebov deleted the eskip/parse-filters-comment branch January 19, 2024 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor no risk changes, for example new filters wip work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant