Search code examples
jenkinsopen-policy-agentrego

Running Rego Tests in Jenkins Pipeline


I am trying to run rego test cases as part of jenkins pipeline run. I previously had my test case and the input data for the test case in a single file and they all ran successfully.

I modified my test cases to read the data from an external json file and the current folder structure is as follows: test.rego file and input.json file in same folder.

This is what I use in Jenkins to run the tests *./opa test -b -v .*

The tests are failing with the error data.utilities.test_no_OwnerContact: FAIL I am assuming this is because the rego test is unable to read the data from input.json

When I am trying to pass the input file explicitly using -i/--input, I see an error in jenkins as Error: unknown flag: --input

I am not sure if I am using the required tags or if it is something else. Any help would be appreciated. Thanks!

Edit: I printed the files in the bundle, and I see the data.json file present. So the OPA engine is not able to read the data file from the Bundle. How can I fix this issue?


Solution

  • The way you'd specify input data in tests is not with an input.json file, but by mocking the input using the with .. as construct. An example test mocking input might look something like this:

    test_with_mocked_input {
        allow with input as {
            "deployment_name": "testing",
            "replicas": 2 
        }
    }
    

    See the docs on data mocking for further info.