Understanding coverage calculation on differently formatted rego #28
Replies: 2 comments 5 replies
-
In cover/cover.go, the Cover.Report() function has some inconsistency on how it reports covered and not covered statements. If a line has multiple statements and is covered, the code only puts that line in the FileReport.Covered once; however, if the line is not covered the code puts that line in the FileReport.NotCovered for each statement in that line. This produces the weird coverage percentage 20% in my above example. The report function should go by LOC covered, and the percent should be 50% in my example above. |
Beta Was this translation helpful? Give feedback.
-
Why is the coverage also reported on the test file itself? It should report the coverage of the executions on the policy files only, no? |
Beta Was this translation helpful? Give feedback.
-
I have been working with
opa test -c
with the example from https://www.openpolicyagent.org/docs/latest/policy-testing/. When I condense the rego from example.rego toAnd remove all test in example_test.rego except for
test_post_allowed
Actual Behavior
The coverage result shows the example.rego was covered only 20 percent.
Expected Behavior
I think coverage is counted from statements but the first allow definition has 2 statements and the second has 4, so coverage should be 33%. Overall I would think that if statements were counted then it shouldn't matter how the rego is formatted, but if I leave example.rego in the original format and only run
test_post_allowed
then I get a coverage on example.rego equal to"coverage": 42.85
.Steps to Reproduce the Problem
Copy the code blocks above for example.rego and example_test.rego and
run opa test . -c
. You should get the same result I have posed above.opa version
Version: 0.28.0
Build Commit: 3fbcd71
Build Timestamp: 2021-04-27T13:51:34Z
Go Version: go1.15.8
WebAssembly: unavailable
Beta Was this translation helpful? Give feedback.
All reactions