-
Notifications
You must be signed in to change notification settings - Fork 261
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
✨ Add API validation test framework #1919
✨ Add API validation test framework #1919
Conversation
TEST_PATHS defaults to the previous hardcoded value of './...', but can now be overridden. e.g. To run just the controller tests: make test TEST_PATHS=./controllers/...
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: mdbooth The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
✅ Deploy Preview for kubernetes-sigs-cluster-api-openstack ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
/cc @JoelSpeed whose CPMS code I cribbed from heavily. |
Expect((&infrav1.OpenStackMachineTemplateWebhook{}).SetupWebhookWithManager(mgr)).To(Succeed(), "OpenStackMachineTemplate webhook should be registered with manager") | ||
Expect((&infrav1.OpenStackMachineTemplateList{}).SetupWebhookWithManager(mgr)).To(Succeed(), "OpenStackMachineTemplateList webhook should be registered with manager") | ||
Expect((&infrav1.OpenStackCluster{}).SetupWebhookWithManager(mgr)).To(Succeed(), "OpenStackCluster webhook should be registered with manager") | ||
Expect((&infrav1.OpenStackClusterTemplate{}).SetupWebhookWithManager(mgr)).To(Succeed(), "OpenStackClusterTemplate webhook should be registered with manager") | ||
Expect((&infrav1.OpenStackMachine{}).SetupWebhookWithManager(mgr)).To(Succeed(), "OpenStackMachine webhook should be registered with manager") | ||
Expect((&infrav1.OpenStackMachineList{}).SetupWebhookWithManager(mgr)).To(Succeed(), "OpenStackMachineList webhook should be registered with manager") | ||
Expect((&infrav1.OpenStackClusterList{}).SetupWebhookWithManager(mgr)).To(Succeed(), "OpenStackClusterList webhook should be registered with manager") |
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.
In general it's bad practice to have code attached to your API types, introduces dependencies and makes it hard for people to import your API types. We've resolved this issue in core CAPI, will want to resolve in wider ecosystem too
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.
Yep. We've had a user report about that, too. It's on the TODO list!
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.
For reference: #1891
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.
@JoelSpeed Just for you: #1920
|
||
minorInt, err := strconv.Atoi(serverVersion.Minor) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(minorInt).To(BeNumerically(">=", 25), fmt.Sprintf("This test suite requires a Kube API server of at least version 1.25, current version is 1.%s", serverVersion.Minor)) |
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.
Depending on which validations you are using, this number may be greater. What is the minimum supported version for running this controller?
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.
Right now we're not relying any anything new. We don't even require CEL support. However, I deliberate left this in because:
- 1.25 is probably a reasonable support minimum right now
- You keep badgering me to add CEL support, and I'm hoping to get to it soon
23ab488
to
a6f2a46
Compare
/lgtm add a hold in case anyone want to see this again |
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.
Awesome!
Just one tiny nit below
a6f2a46
to
4d3e79c
Compare
Interesting that it didn't re-run the tests 🤔 /test all |
/test pull-cluster-api-provider-openstack-test |
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
/hold cancel
This series adds a framework for testing API validations via calls to a running apiserver using envtest. It initially adds only a couple of example tests.
Firstly we update ginkgo to have the same version in tools and the main module, because otherwise it emits a warning.
The we fix an actual bug discovered by the example test:
managedSecurityGroups
was missing anomitempty
, which caused creation of a bare cluster object to fail. We will likely want to visit the minimum set of required parameters, but this was an obvious bug.Running the tests requires a set of assets to have been downloaded, which the
make test
target conveniently does for us. However, it wasn't possible to restrictmake test
to only the tests we are interested in, so we give it an optionalTEST_PATHS
parameters.Finally we add a new test suite with 2 trivial tests, enough to demonstrate that it is working correctly.