unit-test
Runs the controller test suites (suite_test.go, ibmlicensing_controller_test.go,
operandrequest_controller_test.go, …). These are integration-style tests: they need a
reachable Kubernetes cluster (USE_EXISTING_CLUSTER=true) with the required CRDs and
RBAC applied. The prepare-unit-test target sets all of that up for you.
When to use
- After changing anything in
controllers/orapi/. - Before committing controller/API changes or opening a PR.
- To reproduce a CI unit-test failure locally.
Commands
Prepare the cluster and run the full suite:
make prepare-unit-test && make unit-test
make unit-test already depends on prepare-unit-test, so this also works:
make unit-test
Under the hood the tests run:
go test -v ./controllers/... -coverprofile cover.out -timeout 30m
Coverage is written to cover.out.
What prepare-unit-test does
- Creates namespaces
ibm-licensing(NAMESPACE) andopreq-ns(OPREQ_TEST_NAMESPACE). - Creates the
artifactory-tokenpull secret (needsARTIFACTORY_USERNAME/ARTIFACTORY_TOKEN). - Applies the
IBMLicensingCRD and namespace-scoped RBAC (Role, ServiceAccount, RoleBinding) rendered fromconfig/rbac. - Downloads and applies dependency CRDs from upstream: Red Hat Marketplace MeterDefinitions, Prometheus ServiceMonitors, ODLM OperandRequests, and Gateway API (GatewayClasses, Gateways, HTTPRoutes, BackendTLSPolicies).
Prerequisites
- A running cluster (Kind, Minikube, or a real/OpenShift cluster) with
kubectlpointed at it.prepare-unit-testmutates this cluster. ARTIFACTORY_USERNAMEandARTIFACTORY_TOKENexported (for the pull secret).- Internet access (dependency CRDs are fetched via
curl).
Key environment variables
| Var | Default | Purpose |
|---|---|---|
NAMESPACE |
ibm-licensing |
Operator/test namespace |
OPREQ_TEST_NAMESPACE |
opreq-ns |
OperandRequest test namespace |
OCP |
(unset) | Set when running against OpenShift |
IBM_LICENSING_IMAGE |
derived | Operand image under test |
Notes
- Tests can take up to 30 minutes (
-timeout 30m). - Because it uses an existing cluster, leftover resources may persist between runs; a fresh namespace or cluster avoids state bleed.
- This is the local equivalent of the Tekton PR test stage.
Related skills
- [[code-quality]] - run before tests.
- [[build-and-deploy]] - run the operator against a cluster manually.
- [[operator-sdk-guide]] - how the controllers under test are wired.