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

Allow passing output of opa eval --coverage #1

Open
anderseknert opened this issue Apr 6, 2023 · 2 comments
Open

Allow passing output of opa eval --coverage #1

anderseknert opened this issue Apr 6, 2023 · 2 comments

Comments

@anderseknert
Copy link

It would be useful if this tool would work the same for opa eval --coverage as it does for opa test.

The output format is slightly different, as the coverage will be found under a coverage attribute, but the format of the coverage report is the same, so should be easy to detect, I think.

Example:

 opa eval --coverage -d foo.rego data
{
  "result": [
    {
      "expressions": [
        {
          "value": {
            "policies": {
              "cross_env": {
                "dev_to_prod": {
                  "match": []
                }
              }
            }
          },
          "text": "data",
          "location": {
            "row": 1,
            "col": 1
          }
        }
      ]
    }
  ],
  "coverage": {
    "files": {
      "foo.rego": {
        "covered": [
          {
            "start": {
              "row": 4
            },
            "end": {
              "row": 4
            }
          }
        ],
        "not_covered": [
          {
            "start": {
              "row": 3
            },
            "end": {
              "row": 3
            }
          },
          {
            "start": {
              "row": 5
            },
            "end": {
              "row": 5
            }
          }
        ],
        "covered_lines": 1,
        "not_covered_lines": 2,
        "coverage": 33.35
      }
    },
    "covered_lines": 1,
    "not_covered_lines": 2,
    "coverage": 33.35
  }
}
@dkorolev
Copy link
Member

dkorolev commented Apr 6, 2023

Hi @anderseknert!

Heh, it seems to work as is with | jq .coverage | ocov.

Added native support in #2, also made sure it prints total eval coverage, not total test coverage in opa eval mode.

Although ... it does seem to "cover" more than I expected, based on my trivial run. So back to you for testing!

@anderseknert
Copy link
Author

Thanks, Dima! 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants