Goal
We are going to write a test that will do the following:
- Run our controller in the background
- Create a stateless
AbstractWorkload - Check for a created
Deployment - Delete the Deployment
- Check for a created
Deployment - Change the replica number
- Check for an updated
Deployment
Setting up the environment
Kubebuilder uses Kubernetes’ envtest package. With this package, we can run Kubernetes’ control plane locally, without the need to install a cluster.
Next to your controller go file, Kubebuilder generated another file: controllers/suite_test.go — this file is responsible for setting up the test environment and configuring and initializing anything needed before and after our tests.
The BeforeSuite is a function responsible for setting up the environment before the testing start to run. Let’s talk about what happens there:
First, it creates an envtest environment configuration. the CRDDirectoryPaths should contain a list of paths to custom CRD we want our control plane to know.














