C5T / ocov

Colors `opa test --coverage` reports in the terminal.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow passing output of `opa eval --coverage`

anderseknert opened this issue · comments

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
  }
}
commented

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!

Thanks, Dima! 😃