-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
opa test should show readable errors when equality failed #2546
Comments
This would be a nice feature. Personally, I write & test inside of VS Code in which case I can just highlight the part of the test that I'm interested in (e.g., This is similar to #1581. |
thx, the |
It would be nice if this could use the same kind of logic for dealing with undefined as the upcoming test_something {
some_rule := result with input as { ... }
result.number == 5
} The above would then render something like |
👍 |
If anyone is looking for this before it's solved in OPA, I wrote a little test assertion library to help with this some time back. |
Local variable values in test report ------------------------------------ When enabled (`--var-values` flag), the failure report for tests will contain values for variables local to the failing expression. e.g.: ``` FAILURES -------------------------------------------------------------------------------- data.test.test_foo: FAIL (0ms) test.rego:8: x == y + z | | | | | 3 | y + z: 5 | y: 2 1 SUMMARY -------------------------------------------------------------------------------- test.rego: data.test.test_foo: FAIL (0ms) -------------------------------------------------------------------------------- FAIL: 1/1 ``` Local variable values in pretty trace ------------------------------------- When enabled on `eval` and `test` commands (`--var-values` flag), local variable values are added to pretty trace: ``` query:1 Enter data.test.p = _ {} query:1 | Eval data.test.p = _ {} query:1 | Index data.test.p (matched 1 rule, early exit) {} /test.rego:4 | Enter data.test.p {} /test.rego:5 | | Eval x = 1 {} /test.rego:6 | | Eval y = 2 {} /test.rego:7 | | Eval z = 3 {} /test.rego:8 | | Eval minus(z, y, __local3__) {y: 2, z: 3} /test.rego:8 | | Eval x = __local3__ {__local3__: 1, x: 1} /test.rego:4 | | Exit data.test.p early {} query:1 | Exit data.test.p = _ {_: true, data.test.p: true} query:1 Redo data.test.p = _ {_: true, data.test.p: true} query:1 | Redo data.test.p = _ {_: true, data.test.p: true} /test.rego:4 | Redo data.test.p {} /test.rego:8 | | Redo x = __local3__ {__local3__: 1, x: 1} /test.rego:8 | | Redo minus(z, y, __local3__) {__local3__: 1, y: 2, z: 3} /test.rego:7 | | Redo z = 3 {z: 3} /test.rego:6 | | Redo y = 2 {y: 2} /test.rego:5 | | Redo x = 1 {x: 1} ``` Fixing: open-policy-agent#2546 Signed-off-by: Johan Fylling <[email protected]>
Fixing: #2546 Signed-off-by: Johan Fylling <[email protected]>
Fixed in #6815. |
given a test like this:
--verbose
) does not tell me what the actual number was--verbose
does not help either (actual output was 1)please either show "expected 3 to equal 2" (at least in vebose)
or a helper method like
equal(a, b)
that then generates a readable error messageThe text was updated successfully, but these errors were encountered: