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
OPA is reporting back the wrong code coverage percentage and duplicating not_covered rows #4393
Comments
Hi @gianna7wu 👋 And thanks for reporting this. The duplicate entry in |
From a cursory look, it seems that the |
I usually get those variables covered by writing a test without input.
|
Yeah, avoiding any line to be |
👀 I suppose it would make sense to try deduplicating both Covered and NotCovered. Since expressions are often expanded, and still retain there original row/col location data, there may be more cases where this happens.. Perhaps deduplication would help? With this switch {
case curr.Row == end.Row: // skip
case curr.Row == end.Row+1:
end = curr
default:
result = append(result, Range{start, end})
start, end = curr, curr
} instead of Lines 255 to 260 in 64a03c1
I get that report:
|
Neat, yeah I think that would do it 👍 |
Fixes open-policy-agent#4393 Signed-off-by: Anders Eknert <anders@eknert.com>
Fixes #4393 Signed-off-by: Anders Eknert <anders@eknert.com>
Short description
The OPA CLI is reporting incorrect code coverage percentages and duplicating not_covered rows in its JSON response. This is with the OPA CLI newly downloaded (01 March 2022) on macOS.
Examples:
Here is an example bundle (titled general.rego):
Here is an example test (titled test.rego):
The results are returned like so:
You can see that the coverage for
general.rego
is reported as 71.45% when it should be something closer to 80%. Additionally, you can see that in thenot_covered
field forgeneral.rego
, row 3 is specified twice innot_covered
, which I think is what's affecting the coverage score.This is the command that was run to get that output (assuming you have general.rego and test.rego saved in the same directory):
./opa test --coverage --format=json general.rego test.rego
Steps To Reproduce
curl -L -o opa https://openpolicyagent.org/downloads/v0.37.2/opa_darwin_amd64
to download the OPA CLI (following the instructions here).chmod 755 ./opa
./opa test --coverage --format=json general.rego test.rego
Expected behavior
I expect to see the code coverage be closer to 80% and row 3 not to be duplicated in the
not_covered
section.Additional context
N/A
The text was updated successfully, but these errors were encountered: