Running tests

Kubebuilder will create scaffolding tests for controllers and resources. When run, these tests will start a local control plane as part of the integration test. Developers may talk to the local control plane using the provided config.

Resource Tests

The resource tests are created under pkg/apis/<group>/<version>/<kind>_types_test.go. When a resource is created with kubebuilder create api, a test file will be created to store and read back the object.

Update the test to include validation you add to your resource.

For more on Resources see What Is A Resource

Controller Tests

The controller tests are created under pkg/controller/<kind>/controller_test.go. When a resource is created with kubebuilder create api, a test file will be created to start the controller and reconcile objects. The default test will create a new object and verify that the controller Reconcile function is called.

Update the test to verify the business logic of your controller.

For more on Controllers see What Is A Controller

Run the tests

Run the tests using make test.

make test

Optional: Change Control Plane Test Binaries

To override the test binaries used to start the control plane, set the TEST_ASSET_ environment variables. This can be useful for performing testing against multiple Kubernetes cluster versions.

If these environment variables are unset, kubebuiler will default to the binaries packaged with kubebuilder.

export TEST_ASSET_KUBECTL=/usr/local/kubebuilder/bin/kubectl
export TEST_ASSET_KUBE_APISERVER=/usr/local/kubebuilder/bin/kube-apiserver
export TEST_ASSET_ETCD=/usr/local/kubebuilder/bin/etcd

results matching ""

    No results matching ""