open-policy-agent/opa

Extend `test` command to allow filtering package / file / test

Opened this issue · 1 comments

Having recently looked into a deeper integration of the OPA test runner (via command line invocation) and the OPA VS Code extension, there are some hurdles that I think would be best solved in OPA itself, as that would benefit not just VS Code but any editor including a similar integration. The problems are described in this issue, but to summarize here:

Editors and IDEs commonly run tests filtered by either:

  • file (run all tests in file)
  • package (run all tests in package)
  • name inside of a file (click test to run)

The opa test command doesn't really accomodate any of the above needs, as it'll always run all tests in the files that are loaded. From an editors POV, that'll be all files in the workspace, or all Rego files really. It's possible to workaround this in editors by actually running all the tests, but only presenting the filtered result to the user, making them think that only the tests they asked for got run. It's also possible to use the --run argument to pass a list of regular expressions that should match the name of the tests, but that doesn't take the name of the file or package into account... and a similarly named test could theoretically exist in any number of files without them being logically related.

Suggestion here is to either extend what --run accepts, so that it would be possible to provide something like package/*, file.rego/* or file.reg/test_1, or to introduce another flag for this purpose. Naturally, this would need to work as expected with things like coverage, etc.

stale commented

This issue has been automatically marked as inactive because it has not had any activity in the last 30 days. Although currently inactive, the issue could still be considered and actively worked on in the future. More details about the use-case this issue attempts to address, the value provided by completing it or possible solutions to resolve it would help to prioritize the issue.