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
feat: Add Constraint schema validation testing #2092
feat: Add Constraint schema validation testing #2092
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2092 +/- ##
==========================================
- Coverage 54.43% 54.42% -0.02%
==========================================
Files 111 111
Lines 9478 9502 +24
==========================================
+ Hits 5159 5171 +12
- Misses 3930 3937 +7
- Partials 389 394 +5
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
pkg/gator/runner.go
Outdated
results, err := r.runCases(ctx, suiteDir, filter, t) | ||
err := r.tryAddConstraint(ctx, suiteDir, t) | ||
var results []CaseResult | ||
if err == nil && !t.Invalid { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be more clear to check for the invalid constraint error here and fail the test as-necessary here. That avoids double-checking t.Invalid and makes it easier to reason about what happens if the error is nil and t.Invalid is true
.
dbf18ab
to
24ea191
Compare
24ea191
to
1989b6b
Compare
Add feature to "gator verify" which allows testing the schema of Constraints. Fixes: open-policy-agent#1989 Signed-off-by: Will Beason <willbeason@google.com>
Signed-off-by: Max Smythe <smythe@google.com>
1989b6b
to
0583470
Compare
pkg/gator/errors.go
Outdated
@@ -38,4 +38,6 @@ var ( | |||
// ErrConvertingTemplate means we were able to parse a template, but not convert | |||
// it into the version-independent format. | |||
ErrConvertingTemplate = errors.New("unable to convert template") | |||
|
|||
ErrValidConstraint = errors.New("constraint did not fail schema validation") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ErrValidConstraint = errors.New("constraint did not fail schema validation") | |
ErrValidConstraint = errors.New("constraint failed schema validation") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the original is correct. This error is saying that someone wanted a constraint to fail validation but it didn't
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wow that was not obvious to me LOL. how about:
ErrValidConstraint = errors.New("constraint did not fail schema validation") | |
ErrValidConstraint = errors.New("constraint should have failed schema validation") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also it's missing comments like the rest of the vars
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it, changing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ritazh updated
Signed-off-by: Max Smythe <smythe@google.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* feat: Add Constraint schema validation testing Add feature to "gator verify" which allows testing the schema of Constraints. Fixes: open-policy-agent#1989 Signed-off-by: Will Beason <willbeason@google.com> * fix lint errors and comments Signed-off-by: Max Smythe <smythe@google.com> * tweak error message Signed-off-by: Max Smythe <smythe@google.com> Co-authored-by: Will Beason <willbeason@google.com> Co-authored-by: Max Smythe <smythe@google.com> Co-authored-by: Rita Zhang <rita.z.zhang@gmail.com> Signed-off-by: Christoph Fraundorfer <christoph.fraundorfer@allianzdirect.de>
* feat: Add Constraint schema validation testing Add feature to "gator verify" which allows testing the schema of Constraints. Fixes: open-policy-agent#1989 Signed-off-by: Will Beason <willbeason@google.com> * fix lint errors and comments Signed-off-by: Max Smythe <smythe@google.com> * tweak error message Signed-off-by: Max Smythe <smythe@google.com> Co-authored-by: Will Beason <willbeason@google.com> Co-authored-by: Max Smythe <smythe@google.com> Co-authored-by: Rita Zhang <rita.z.zhang@gmail.com> Signed-off-by: Christoph Fraundorfer <christoph.fraundorfer@allianzdirect.de>
* feat: Add Constraint schema validation testing Add feature to "gator verify" which allows testing the schema of Constraints. Fixes: open-policy-agent#1989 Signed-off-by: Will Beason <willbeason@google.com> * fix lint errors and comments Signed-off-by: Max Smythe <smythe@google.com> * tweak error message Signed-off-by: Max Smythe <smythe@google.com> Co-authored-by: Will Beason <willbeason@google.com> Co-authored-by: Max Smythe <smythe@google.com> Co-authored-by: Rita Zhang <rita.z.zhang@gmail.com> Signed-off-by: Christoph Fraundorfer <christoph.fraundorfer@allianzdirect.de>
* feat: Add Constraint schema validation testing Add feature to "gator verify" which allows testing the schema of Constraints. Fixes: open-policy-agent#1989 Signed-off-by: Will Beason <willbeason@google.com> * fix lint errors and comments Signed-off-by: Max Smythe <smythe@google.com> * tweak error message Signed-off-by: Max Smythe <smythe@google.com> Co-authored-by: Will Beason <willbeason@google.com> Co-authored-by: Max Smythe <smythe@google.com> Co-authored-by: Rita Zhang <rita.z.zhang@gmail.com> Signed-off-by: Christoph Fraundorfer <christoph.fraundorfer@allianzdirect.de>
* feat: Add Constraint schema validation testing Add feature to "gator verify" which allows testing the schema of Constraints. Fixes: open-policy-agent#1989 Signed-off-by: Will Beason <willbeason@google.com> * fix lint errors and comments Signed-off-by: Max Smythe <smythe@google.com> * tweak error message Signed-off-by: Max Smythe <smythe@google.com> Co-authored-by: Will Beason <willbeason@google.com> Co-authored-by: Max Smythe <smythe@google.com> Co-authored-by: Rita Zhang <rita.z.zhang@gmail.com> Signed-off-by: Christoph Fraundorfer <christoph.fraundorfer@allianzdirect.de>
* feat: Add Constraint schema validation testing Add feature to "gator verify" which allows testing the schema of Constraints. Fixes: open-policy-agent#1989 Signed-off-by: Will Beason <willbeason@google.com> * fix lint errors and comments Signed-off-by: Max Smythe <smythe@google.com> * tweak error message Signed-off-by: Max Smythe <smythe@google.com> Co-authored-by: Will Beason <willbeason@google.com> Co-authored-by: Max Smythe <smythe@google.com> Co-authored-by: Rita Zhang <rita.z.zhang@gmail.com> Signed-off-by: Christoph Fraundorfer <christoph.fraundorfer@allianzdirect.de>
* feat: Add Constraint schema validation testing Add feature to "gator verify" which allows testing the schema of Constraints. Fixes: open-policy-agent#1989 Signed-off-by: Will Beason <willbeason@google.com> * fix lint errors and comments Signed-off-by: Max Smythe <smythe@google.com> * tweak error message Signed-off-by: Max Smythe <smythe@google.com> Co-authored-by: Will Beason <willbeason@google.com> Co-authored-by: Max Smythe <smythe@google.com> Co-authored-by: Rita Zhang <rita.z.zhang@gmail.com> Signed-off-by: Christoph Fraundorfer <christoph.fraundorfer@allianzdirect.de>
* feat: Add Constraint schema validation testing Add feature to "gator verify" which allows testing the schema of Constraints. Fixes: open-policy-agent#1989 Signed-off-by: Will Beason <willbeason@google.com> * fix lint errors and comments Signed-off-by: Max Smythe <smythe@google.com> * tweak error message Signed-off-by: Max Smythe <smythe@google.com> Co-authored-by: Will Beason <willbeason@google.com> Co-authored-by: Max Smythe <smythe@google.com> Co-authored-by: Rita Zhang <rita.z.zhang@gmail.com> Signed-off-by: Christoph Fraundorfer <christoph.fraundorfer@allianzdirect.de>
* feat: Add Constraint schema validation testing Add feature to "gator verify" which allows testing the schema of Constraints. Fixes: open-policy-agent#1989 Signed-off-by: Will Beason <willbeason@google.com> * fix lint errors and comments Signed-off-by: Max Smythe <smythe@google.com> * tweak error message Signed-off-by: Max Smythe <smythe@google.com> Co-authored-by: Will Beason <willbeason@google.com> Co-authored-by: Max Smythe <smythe@google.com> Co-authored-by: Rita Zhang <rita.z.zhang@gmail.com>
* feat: Add Constraint schema validation testing Add feature to "gator verify" which allows testing the schema of Constraints. Fixes: open-policy-agent#1989 Signed-off-by: Will Beason <willbeason@google.com> * fix lint errors and comments Signed-off-by: Max Smythe <smythe@google.com> * tweak error message Signed-off-by: Max Smythe <smythe@google.com> Co-authored-by: Will Beason <willbeason@google.com> Co-authored-by: Max Smythe <smythe@google.com> Co-authored-by: Rita Zhang <rita.z.zhang@gmail.com> Signed-off-by: davis-haba <davishaba@google.com>
Add feature to "gator verify" which allows testing the schema of
Constraints.
Before it was possible to test that Constraints were valid (by simply omitting Cases),
but now it is also possible to test that specific Constraints are invalid. For example -
that fields are not of the correct type, or that required fields are missing.
Fixes: #1989
Signed-off-by: Will Beason willbeason@google.com