Skip to content

Allow passing output of opa eval --coverage #1

@anderseknert

Description

@anderseknert

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions