Move integration tests to test/integration#4736
Move integration tests to test/integration#4736jetstack-bot merged 1 commit intocert-manager:masterfrom
Conversation
|
Hm, I don't think we should be moving everything under test/integration... this is test code that is specifically related to this area of the code (i.e. there is one per API group) and this feels like it makes things less clear.
Is there nothing that can be done to work around this? What's the long term plan for making this work without "further setup"? Right now this test case (in Bazel) defines what it depends on clearly in the BUILD.bazel file. Once we don't have Bazel here, how will this work? I'd really like it if we didn't have to just hide some setup code into a Makefile that's far away/not directly related to this package |
wallrj
left a comment
There was a problem hiding this comment.
Thanks @SgtCoDFish
I agree with moving these tests into ./test.
I suggest we add a `./test/README.md file explaining that this is where we put any tests that require other files to be downloaded or generated, such as CRD yamls or external binaries.
Kubernetes have a ./test/fuzz directory, but it contains fuzz configurations for https://github.com/google/oss-fuzz/tree/master/projects/kubernetes, so there is a precedent, but they use it for a slightly different purpose.
Kubernetes define unit-tests as follows:
Unit tests should be fully hermetic
Only access resources in the test binary.
They don't directly state that all non-unit-tests must live beneath ./test, but that is how I interpret it and that is how I think cert-manager ought to define it.
I think we also considered adding build tags to tests that are not hermetic (leaving them among the ./pkg and ./internal directories), but we rejected that because it would be too easy to add the wrong build tag and accidentally not run tests when you intended to run the entire suite.
Another alternative would be to Skip these tests if the required assets were not found on the filesystem.
But really what we then need is a way to ensure that these optional tests that may not be run on your laptop, are always run in the CI environment.
Unhold if you'd like to merge this as-is.
/approve
/lgtm
/hold
|
I've added a comment to the main tracking issue to try and explain what I'd personally like: #4712 (comment) I believe that the strategy of moving things that don't pass out of the box into the Can we discuss on that main issue what our intended end-state goal is before we starting moving more things around/adding tags etc? (namely @wallrj it'd be great if you can outline the expected UX from the developer running tests as well as for developers writing tests standpoint, with the approach where we put all tests that won't work with |
wallrj
left a comment
There was a problem hiding this comment.
Sorry @SgtCoDFish
I hadn't paid close attention to the files which were being moved.
I think only the non-hermetic test files should be moved to the ./test directory.
@munnerz Given that bazel is being removed (despite my misgivings about that),
I will be happy if the outcome is that I can run the only the unit-tests for a particular package and sub-packages without having to use make and without having to worry about running setip scripts first. E.g. If I've been working on validation functions and their unit tests I might run:
go test ./internal/apis/...
? github.com/jetstack/cert-manager/internal/apis/acme [no test files]
? github.com/jetstack/cert-manager/internal/apis/acme/fuzzer [no test files]
--- FAIL: TestPruneTypes (0.00s)
bazel.go:55: stat /home/richard/projects/cert-manager/cert-manager2/bazel-bin/deploy/crds: no such file or directory
FAIL
FAIL github.com/jetstack/cert-manager/internal/apis/acme/install 0.173s
? github.com/jetstack/cert-manager/internal/apis/acme/v1 [no test files]
? github.com/jetstack/cert-manager/internal/apis/acme/v1alpha2 [no test files]
? github.com/jetstack/cert-manager/internal/apis/acme/v1alpha3 [no test files]
? github.com/jetstack/cert-manager/internal/apis/acme/v1beta1 [no test files]
ok github.com/jetstack/cert-manager/internal/apis/acme/validation 0.026s
? github.com/jetstack/cert-manager/internal/apis/certmanager [no test files]
? github.com/jetstack/cert-manager/internal/apis/certmanager/fuzzer [no test files]
? github.com/jetstack/cert-manager/internal/apis/certmanager/identity [no test files]
ok github.com/jetstack/cert-manager/internal/apis/certmanager/identity/certificaterequests 0.017s
--- FAIL: TestPruneTypes (0.00s)
bazel.go:55: stat /home/richard/projects/cert-manager/cert-manager2/bazel-bin/deploy/crds: no such file or directory
FAIL
FAIL github.com/jetstack/cert-manager/internal/apis/certmanager/install 0.252s
? github.com/jetstack/cert-manager/internal/apis/certmanager/v1 [no test files]
? github.com/jetstack/cert-manager/internal/apis/certmanager/v1alpha2 [no test files]
? github.com/jetstack/cert-manager/internal/apis/certmanager/v1alpha3 [no test files]
? github.com/jetstack/cert-manager/internal/apis/certmanager/v1beta1 [no test files]
ok github.com/jetstack/cert-manager/internal/apis/certmanager/validation 6.316s
ok github.com/jetstack/cert-manager/internal/apis/certmanager/validation/plugins 0.023s
ok github.com/jetstack/cert-manager/internal/apis/certmanager/validation/util 0.011s
? github.com/jetstack/cert-manager/internal/apis/config/webhook [no test files]
? github.com/jetstack/cert-manager/internal/apis/config/webhook/fuzzer [no test files]
ok github.com/jetstack/cert-manager/internal/apis/config/webhook/install 0.020s
? github.com/jetstack/cert-manager/internal/apis/config/webhook/scheme [no test files]
? github.com/jetstack/cert-manager/internal/apis/config/webhook/v1alpha1 [no test files]
? github.com/jetstack/cert-manager/internal/apis/config/webhook/validation [no test files]
? github.com/jetstack/cert-manager/internal/apis/meta [no test files]
? github.com/jetstack/cert-manager/internal/apis/meta/fuzzer [no test files]
ok github.com/jetstack/cert-manager/internal/apis/meta/install 0.015s
? github.com/jetstack/cert-manager/internal/apis/meta/v1 [no test files]
FAIL
I don't want to run make test WHAT=./x/y/z GO_TEST_FLAGS=-count=10 -fail-fast -run TestFooBar because there's no command line completion for those bespoke make flags and certainly none for their arguments.
My other comment is that I can't tell what the pruning_tests do.
Do we need them any more?
I see that appscode / kubedb has a fork of your library and uses that, but he's the only other user AFAICS.
/lgtm cancel
/approve cancel
They ensure that the generated OpenAPI schema is valid for the given Go API types, by generating random data into the struct (i.e. filling out all known fields in the Go type), encoding that to JSON, "pruning" unknown fields in the JSON document based on the OpenAPI schema, and then decoding it back into the Go type. It then verifies that the input and the output are identical via a DeepEqual of the
As per my comment in #4712 (comment), that's precisely what using build tags would also achieve -
To this point, I don't think it would be easy to add the wrong build tag, because when you then run those test cases, the tests will fail because the appropriate setup won't be run. The only case I can think here is if somewhere were to add an integration flag when they don't need it - but that's effectively the same as if someone adds the file to |
TBH that sounds like a test that belongs in https://github.com/kubernetes-sigs/controller-tools not in cert-manager. |
We did discuss adding it upstream, but crucially you need a corpus of cases to test in that project, which could always be non-exhaustive compared to our own types. By running this test, we:
To avoid this going off topic though, if we think it's worthwhile shall we discuss removing them in its own issue? I am personally against removing them because the net result is less confidence in our openapi schema :) |
These tests have external dependencies (rendered CRDs) which mean they can't pass on a clean checkout without further setup. We define such tests as integration tests, and so these are moved to test/integration. Signed-off-by: Ashley Davis <ashley.davis@jetstack.io>
|
@wallrj I've made the changes you requested and updated the PR description to reference the specific goal of moving these files. I moved the files to
Agreed. I won't discuss further here. |
wallrj
left a comment
There was a problem hiding this comment.
Thanks @SgtCoDFish
It makes sense to me that these particular tests are considered "integration" tests and that they be moved.
Given that this PR now only moves the CRD pruning tests, which require the CRD yaml files.
And given that those tests are concerned with catching bugs in controller-gen tool and may in future be moved upstream to the controller-tools project.
/lgtm
/approve
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: SgtCoDFish, wallrj The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
It'd be good to chat about this - to clarify, moving these tests to only be run upstream would not give us the level of confidence we have today. Upstream may choose to run a similar test with their own corpus of types to prevent regressions, but our testing here catches unknown/new bugs that'd otherwise specifically affect us. So these tests shouldn't be removed in future 😊 |
|
/unhold |
|
/test all (check status says "Pending — Not mergeable. Retesting 5 jobs." but there don't appear to be any tests running) |
These tests have external dependencies (templated CRDs) which mean they can't pass on a clean checkout without further setup.
The original commit had these in
test/fuzzbut since we're laser-focused on defining integration tests, I've moved totest/integration/fuzzinstead to preserve the ability to callbazel test //test/integration/...and catch everything.This helps to achieve the following aim in the make migration:
/kind cleanup