-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
How to test SetupWithManager? #3071
Comments
It's difficult to see where your test are failing to pick up the changes. If you are using the default kubebuilder scaffold for env test, you may need to modify what you wish to test. In envtest you can Expect(<name of controller>.SetupWithManager(ctx, mgr)).ToNot(HaveOccurred()) during your set up (BeforeSuite) in your suite_test.go and assert on the things that your SetUpWithManager does with predicates in your test file. |
Thanks for response @troy0820. I already called SetUpWithManager function in test, would like to test following code inside SetUpWithManager.
In practice I found that no matter how I create/update nodes in envtest environment, above code is not executed. I suspect it is because envtest doesn't emit event such as node create/delete/update, so controller can not watch predicates, but not very confirmed. |
If you need to see node events, it may make sense to try this on an existing cluster where you can see the events trigger when nodes get updated. If you are just trying to vet the functionality, you could unit test the predicates to see if what changes creates true/false which would trigger the parent object of your reconciler. |
Yes. I updated my test config and it can execute CreateFunc/DeleteFunc now. still not able to execute UpdateFunc, may need to further tweak the test. |
When trying to test default generated controller code, I found that test doesn't cover SetupWithManager function. I tried to create/update resource, but CreateFunc/UpdateFunc defined in Predicates of SetupWithManager is not called.
Is it because envtest package doesn't emit event when there is change? Wondering how should we test CreateFunc/UpdateFunc in this case.
not sure whether this question is more appropriate here or in the kubebuilder repo.
The text was updated successfully, but these errors were encountered: