Skip to content
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

Test failure should return correct "fail" value #954

Closed
johscheuer opened this issue Sep 17, 2018 · 1 comment
Closed

Test failure should return correct "fail" value #954

johscheuer opened this issue Sep 17, 2018 · 1 comment
Labels

Comments

@johscheuer
Copy link
Contributor

I followed the steps described here: https://www.openpolicyagent.org/docs/how-do-i-test-policies.html#test-results and I wondered about the "fail": false actually I would expect that when a test case fails the value ist set to: "fail": true?

{
  "location": {
    "file": "pass_fail_error_test.rego",
    "row": 4,
    "col": 1
  },
  "package": "data.example",
  "name": "test_ok",
  "duration": 1291364
}
{
  "location": {
    "file": "pass_fail_error_test.rego",
    "row": 9,
    "col": 1
  },
  "package": "data.example",
  "name": "test_failure",
  "fail": false,
  "duration": 597117
}
{
  "location": {
    "file": "pass_fail_error_test.rego",
    "row": 14,
    "col": 1
  },
  "package": "data.example",
  "name": "test_error",
  "error": {
    "code": "eval_internal_error",
    "message": "div: divide by zero",
    "location": {
      "file": "pass_fail_error_test.rego",
      "row": 15,
      "col": 5
    }
  },
  "duration": 527246
}
@tsandall
Copy link
Member

Yes, this is confusing. The current implementation sets the fail field as follows:

  • If the test rule is undefined, the field is set to false
  • If the test rule generates a value that is not true, the field is set to the value

We should just set the test fail field to true if the test failed in all cases. I'll submit a PR today.

@tsandall tsandall added the bug label Sep 17, 2018
tsandall added a commit to tsandall/opa that referenced this issue Sep 17, 2018
Previously the test runner would set fail to the value generated by the
test rule or false on undefined. The intent was to communicate the value
generated by the rule. In practice users are not writing tests that
generate values other than true so this is essentially unnecessary.

Fixes open-policy-agent#954

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
tsandall added a commit that referenced this issue Sep 17, 2018
Previously the test runner would set fail to the value generated by the
test rule or false on undefined. The intent was to communicate the value
generated by the rule. In practice users are not writing tests that
generate values other than true so this is essentially unnecessary.

Fixes #954

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants