Skip to content

Commit

Permalink
rego-v1: Future-proofing cover pkg tests to be 1.0 compatible (#7015)
Browse files Browse the repository at this point in the history
Signed-off-by: Johan Fylling <[email protected]>
  • Loading branch information
johanfylling authored Sep 12, 2024
1 parent ebe5b01 commit 53075f6
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions cover/cover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,38 @@ func TestCover(t *testing.T) {
import data.deadbeef # expect not reported
foo {
foo if {
bar
p
not baz
}
bar {
bar if {
a := 1
b := 2
a != b
}
baz { # expect no exit
baz if { # expect no exit
true
false # expect eval but fail
true # expect not covered
}
p {
p if {
some bar # should not be included in coverage report
bar = 1
bar + 1 == 2
}
`

parsedModule, err := ast.ParseModule("test.rego", module)
parsedModule, err := ast.ParseModuleWithOpts("test.rego", module, ast.ParserOptions{AllFutureKeywords: true})
if err != nil {
t.Fatal(err)
}

eval := rego.New(
rego.Module("test.rego", module),
rego.ParsedModule(parsedModule),
rego.Query("data.test.foo"),
rego.QueryTracer(cover),
)
Expand Down Expand Up @@ -148,16 +148,16 @@ func TestCoverNoDuplicates(t *testing.T) {
# Both a rule and an expression, but should not be counted twice
foo := 1
allow { true }
allow if { true }
`

parsedModule, err := ast.ParseModule("test.rego", module)
parsedModule, err := ast.ParseModuleWithOpts("test.rego", module, ast.ParserOptions{AllFutureKeywords: true})
if err != nil {
t.Fatal(err)
}

eval := rego.New(
rego.Module("test.rego", module),
rego.ParsedModule(parsedModule),
rego.Query("data.test.allow"),
rego.QueryTracer(cover),
)
Expand Down

0 comments on commit 53075f6

Please sign in to comment.