Skip to content

Commit 530579e

Browse files
authored
test: Not modifying global recursion depth limit in parser tests init (#7641)
The previous `init()` func in `v1/ast/parser_test.go` would also run for `make perf`, which would cause failing benchmark tests in CI. Signed-off-by: Johan Fylling <[email protected]>
1 parent 20fe70e commit 530579e

File tree

2 files changed

+2
-9
lines changed

2 files changed

+2
-9
lines changed

v1/ast/parser.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ import (
3232
// depth for the parser
3333
const DefaultMaxParsingRecursionDepth = 100000
3434

35-
var maxParsingRecursionDepth = DefaultMaxParsingRecursionDepth
36-
3735
// ErrMaxParsingRecursionDepthExceeded is returned when the parser
3836
// recursion exceeds the maximum allowed depth
3937
var ErrMaxParsingRecursionDepthExceeded = errors.New("max parsing recursion depth exceeded")
@@ -183,7 +181,7 @@ func NewParser() *Parser {
183181
p := &Parser{
184182
s: &state{},
185183
po: ParserOptions{},
186-
maxRecursionDepth: maxParsingRecursionDepth,
184+
maxRecursionDepth: DefaultMaxParsingRecursionDepth,
187185
}
188186
return p
189187
}

v1/ast/parser_test.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6378,11 +6378,6 @@ allow if {
63786378
assertLocationText(t, "# METADATA\n# title: rule", m.Rules[0].Annotations[0].Location)
63796379
}
63806380

6381-
func init() {
6382-
// maxParsingRecursionDepth is set much lower for testing purposes.
6383-
maxParsingRecursionDepth = 100
6384-
}
6385-
63866381
func TestMaxParsingRecursionDepth(t *testing.T) {
63876382
tests := []struct {
63886383
name string
@@ -6392,7 +6387,7 @@ func TestMaxParsingRecursionDepth(t *testing.T) {
63926387
}{
63936388
{
63946389
name: "deeply nested array exceeds default limit",
6395-
input: generateDeeplyNestedArray(200),
6390+
input: generateDeeplyNestedArray(DefaultMaxParsingRecursionDepth + 1),
63966391
expectError: true,
63976392
},
63986393
{

0 commit comments

Comments
 (0)