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

Rewrite test TargetHandler #181

Merged
merged 21 commits into from
Jan 20, 2022
Merged

Conversation

willbeason
Copy link
Member

@willbeason willbeason commented Jan 10, 2022

The big idea here is that the current TargetHandler makes it hard to test several things we want to have good tests for before we can safely shard rego environments. At its core, this PR is about this new handler and the resulting test changes. This makes pkg/client/clienttest/handler.go a good starting point for reviewing this PR.

I've broken "CRD Helpers" into individual methods and removed "CRDHelper" - this type was becoming a dumping ground of tenuously-related validation and constructing CRDs, ConstraintTemplates, and Constraints. Only one method used the single member of this type (the schema). So I've broken this into the client/crds package. The package could probably be better-named since not all of the functions in "CRDHelper" dealt with CRDs. Let me know if you have a better idea!

Since the test Handler needs to import the client package and is in a test package, all client tests need to be in the client_test package. All functionality they rely on then needs to be exported by client. This change is responsible for much of the code changes.

Lastly, the new test TargetHandler is much more flexible than the old one. This ended up making a lot of logic for existing E2E tests obsolete, so I've rewritten them. This makes the distinction between "e2e" and non-"e2e" tests a bit arbitrary as both flavors are using the same setup code (and have the same flexibility). I've arbitrarily decided to stick with the current convention that "e2e" tests are those which exercise "Review" or "Audit", or test sequences of behaviors (such as adding a Constraint, then deleting its Template).

Some changes in this PR are transitory - they are intended to be fixed in later PRs. These relate to making certain fields/methods exported which shouldn't be. AllowedDataFields, ParseModule, and RequireModuleRules are examples of these. They will be moved to client/drivers/local since that's the only location which should need that logic.

@willbeason willbeason self-assigned this Jan 10, 2022
@codecov-commenter
Copy link

codecov-commenter commented Jan 10, 2022

Codecov Report

Merging #181 (67abd24) into master (b0196c3) will decrease coverage by 0.04%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #181      +/-   ##
==========================================
- Coverage   45.70%   45.66%   -0.05%     
==========================================
  Files          59       60       +1     
  Lines        2866     2847      -19     
==========================================
- Hits         1310     1300      -10     
+ Misses       1309     1302       -7     
+ Partials      247      245       -2     
Flag Coverage Δ
unittests 45.66% <ø> (-0.05%) ⬇️

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

Impacted Files Coverage Δ
...-agent/frameworks/constraint/pkg/client/backend.go 86.66% <0.00%> (-1.22%) ⬇️
...y-agent/frameworks/constraint/pkg/client/errors.go 0.00% <0.00%> (ø)
...t/frameworks/constraint/pkg/client/test_handler.go
...nt/frameworks/constraint/pkg/client/crd_helpers.go
...gent/frameworks/constraint/pkg/client/crds/crds.go 90.32% <0.00%> (ø)
.../frameworks/constraint/pkg/client/crds/validate.go 85.71% <0.00%> (ø)
...nt/frameworks/constraint/pkg/client/crds/schema.go 100.00% <0.00%> (ø)
...y-agent/frameworks/constraint/pkg/client/client.go 71.98% <0.00%> (+0.92%) ⬆️

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 b0196c3...67abd24. Read the comment docs.

@willbeason willbeason changed the title [WIP] Query [WIP] Rewrite test TargetHandler Jan 11, 2022
@willbeason willbeason added this to the Rego Environment Sharding milestone Jan 11, 2022
@willbeason willbeason marked this pull request as ready for review January 13, 2022 16:56
Copy link
Contributor

@maxsmythe maxsmythe left a comment

Choose a reason for hiding this comment

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

LGTM with a few nits

constraint/pkg/client/clienttest/handler.go Outdated Show resolved Hide resolved
constraint/pkg/client/e2e_test.go Outdated Show resolved Hide resolved
Will Beason added 13 commits January 14, 2022 09:17
Signed-off-by: Will Beason <willbeason@google.com>
Signed-off-by: Will Beason <willbeason@google.com>
Signed-off-by: Will Beason <willbeason@google.com>
Signed-off-by: Will Beason <willbeason@google.com>
Signed-off-by: Will Beason <willbeason@google.com>
Signed-off-by: Will Beason <willbeason@google.com>
Signed-off-by: Will Beason <willbeason@google.com>
Signed-off-by: Will Beason <willbeason@google.com>
Signed-off-by: Will Beason <willbeason@google.com>
This means the merge conflict won't cause compilation errors.

Signed-off-by: Will Beason <willbeason@google.com>
Resolve various issues from now-merged commits, such as interface
changes.

Signed-off-by: Will Beason <willbeason@google.com>
Signed-off-by: Will Beason <willbeason@google.com>
Signed-off-by: Will Beason <willbeason@google.com>
Signed-off-by: Will Beason <willbeason@google.com>
@willbeason willbeason changed the title [WIP] Rewrite test TargetHandler Rewrite test TargetHandler Jan 14, 2022
Will Beason added 2 commits January 18, 2022 11:29
Signed-off-by: Will Beason <willbeason@google.com>
Signed-off-by: Will Beason <willbeason@google.com>
Signed-off-by: Will Beason <willbeason@google.com>
@ritazh
Copy link
Member

ritazh commented Jan 19, 2022

Gatekeeper Test is failing

Signed-off-by: Will Beason <willbeason@google.com>
@willbeason
Copy link
Member Author

Gatekeeper Test is failing

Yes, this is expected for right now. @becky-hd is working on changing where/when we do validation. Right now Gatekeeper relies on CreateCRD to fail under certain conditions, when really we should have a dedicated ValidateCRD method.

Will Beason added 2 commits January 19, 2022 13:11
Since it is needed by several layers of abstraction, it should be in its
own package. Ditto the test handler type.

Thanks to @davis-haba for identifying this

Signed-off-by: Will Beason <willbeason@google.com>
Signed-off-by: Will Beason <willbeason@google.com>
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

@willbeason willbeason merged commit cb43228 into open-policy-agent:master Jan 20, 2022
@willbeason willbeason deleted the query branch January 20, 2022 15:34
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.

None yet

4 participants