Policy Testing
Because CircleCI’s policy engine uses OPA’s rego, we can write test cases and assettions against it.
pytest
has great parsing and output utilities, and python is great for dealing with yaml and json.
A pytest based helper class allows the tuple of circleci config, circleci policy, and circleci metadata to be be processed, and then evaluate the outcome.
This test class runs 4 tests against our context protection policy file.
- Good config passes (single filter, main branch only)
- Missing filters fails
- Multiple filters fails
- Single, non-main filter fails
|
|
|
|