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

feat: Add Constraint schema validation testing #2092

Merged

Conversation

willbeason
Copy link
Member

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

@willbeason willbeason requested review from maxsmythe and a team June 6, 2022 16:42
@willbeason willbeason self-assigned this Jun 6, 2022
@willbeason willbeason modified the milestones: Mutation Beta, gator beta Jun 6, 2022
@codecov-commenter
Copy link

codecov-commenter commented Jun 6, 2022

Codecov Report

Merging #2092 (d024aa0) into master (c998cea) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

@@            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     
Flag Coverage Δ
unittests 54.42% <100.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/gator/runner.go 87.44% <100.00%> (-9.42%) ⬇️
pkg/readiness/list.go 79.41% <0.00%> (-11.77%) ⬇️
pkg/readiness/object_tracker.go 83.98% <0.00%> (+1.06%) ⬆️
...onstrainttemplate/constrainttemplate_controller.go 58.99% <0.00%> (+2.39%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c998cea...d024aa0. Read the comment docs.

results, err := r.runCases(ctx, suiteDir, filter, t)
err := r.tryAddConstraint(ctx, suiteDir, t)
var results []CaseResult
if err == nil && !t.Invalid {
Copy link
Contributor

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.

@maxsmythe maxsmythe force-pushed the invalid-constraint-schema branch 2 times, most recently from dbf18ab to 24ea191 Compare June 23, 2022 02:33
@maxsmythe
Copy link
Contributor

@ritazh @sozercan @chewong LGTY?

Will Beason and others added 2 commits June 23, 2022 11:04
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>
@@ -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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ErrValidConstraint = errors.New("constraint did not fail schema validation")
ErrValidConstraint = errors.New("constraint failed schema validation")

Copy link
Contributor

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

Copy link
Member

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:

Suggested change
ErrValidConstraint = errors.New("constraint did not fail schema validation")
ErrValidConstraint = errors.New("constraint should have failed schema validation")

Copy link
Member

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it, changing.

Copy link
Contributor

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>
@maxsmythe maxsmythe requested a review from ritazh June 24, 2022 18:09
Copy link
Member

@ritazh ritazh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@maxsmythe maxsmythe merged commit 838ee89 into open-policy-agent:master Jun 24, 2022
ChrisFraun pushed a commit to ChrisFraun/gatekeeper that referenced this pull request Jun 28, 2022
* 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>
ChrisFraun pushed a commit to ChrisFraun/gatekeeper that referenced this pull request Jun 29, 2022
* 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>
ChrisFraun pushed a commit to ChrisFraun/gatekeeper that referenced this pull request Jun 29, 2022
* 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>
ChrisFraun pushed a commit to ChrisFraun/gatekeeper that referenced this pull request Jun 29, 2022
* 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>
ChrisFraun pushed a commit to ChrisFraun/gatekeeper that referenced this pull request Jun 29, 2022
* 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>
ChrisFraun pushed a commit to ChrisFraun/gatekeeper that referenced this pull request Jun 29, 2022
* 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>
ChrisFraun pushed a commit to ChrisFraun/gatekeeper that referenced this pull request Jul 4, 2022
* 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>
ChrisFraun pushed a commit to ChrisFraun/gatekeeper that referenced this pull request Jul 6, 2022
* 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>
davis-haba pushed a commit to davis-haba/gatekeeper that referenced this pull request Jul 11, 2022
* 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>
davis-haba pushed a commit to davis-haba/gatekeeper that referenced this pull request Jul 19, 2022
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[gator verify] Add way to test Constraints fail schema validation
5 participants