Learning Rego - Confusion regarding input behavior when writing unit tests #463
-
Hello! Hope you're all doing well. TL;DR: Confused on how the custom imports in Rego work and Not sure why unit test cases are passing when it should fail. I'm trying to write unit tests for certain policies that I have written, but I'm confused on how to write it. My directory structure where i'm storing my input, my policies, and unit tests is as follows:
And these are how each file is defined
And i'm running I've used the Any help would be greatly appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hi @mooneeb , replicating your setup, but cleaning up the input to valid json {
"Internal_deployment": {
"Deployment": {
},
"public_registry_urls": ["false"]
}
} I get: $ opa test . -v
FAILURES
--------------------------------------------------------------------------------
data.policy.special.test_resources_found: FAIL (2.360375ms)
query:1 Enter data.policy.special.test_resources_found = _
sources/policy_detector_test.rego:5 | Enter data.policy.special.test_resources_found
sources/policy_detector.rego:28 | | Enter data.policy.special.found
sources/policy_detector.rego:28 | | | Fail gt(__local13__, 0)
sources/policy_detector_test.rego:6 | | Fail data.policy.special.found with input as __local14__
query:1 | Fail data.policy.special.test_resources_found = _
SUMMARY
--------------------------------------------------------------------------------
sources/policy_detector_test.rego:
data.policy.special.test_resources_found: FAIL (2.360375ms)
--------------------------------------------------------------------------------
FAIL: 1/1 Updating the input json to: {
"Internal_deployment": {
"Deployment" : {
"kind": "DaemonSet",
"spec": {
"template": {
"spec": {
"containers": [
{
"image": "internalstorage"
}
]
}
}
},
"metadata": {
"name": "foo",
"namespace": "bar"
}
},
"public_registry_urls": ["false"]
}
} I get:
Could there be something at play in your local setup that isn't part of your problem description here? |
Beta Was this translation helpful? Give feedback.
Hi @mooneeb , replicating your setup, but cleaning up the input to valid json
I get: