mit einem Klick
running-unit-tests
// Use when running, writing, or troubleshooting unit tests for integration-service. Covers make test, envtest setup, suite patterns, mock loader, CRD discovery, coverage, and common test failures.
// Use when running, writing, or troubleshooting unit tests for integration-service. Covers make test, envtest setup, suite patterns, mock loader, CRD discovery, coverage, and common test failures.
| name | running-unit-tests |
| description | Use when running, writing, or troubleshooting unit tests for integration-service. Covers make test, envtest setup, suite patterns, mock loader, CRD discovery, coverage, and common test failures. |
Unit tests use Ginkgo v2 + Gomega with envtest (a local K8s API server). Every package has a *_suite_test.go that bootstraps envtest with CRDs, registers schemes, and starts a controller manager.
| Command | What it does |
|---|---|
make test | Full pipeline: manifests, generate, fmt, vet, envtest, download-crds, then go test ./... -coverprofile cover.out |
make download-crds | Downloads CRD YAMLs from dependency modules (vendoring prunes non-Go files) |
make envtest | Downloads setup-envtest tool |
go test ./internal/controller/snapshot/... | Run tests for a single package |
go test ./... -run TestName | Run a specific test by name |
Every suite follows this structure (see any *_suite_test.go):
CRDDirectoryPaths — local CRDs from config/crd/bases plus dependency CRDs found via toolkit.GetRelativeDependencyPath()applicationapiv1alpha1, tektonv1, releasev1alpha1, v1beta2)ctrl.NewManager() with Metrics.BindAddress: "0" (disables metrics to avoid port conflicts) and LeaderElection: falsecache.Setup*Cache(k8sManager) functions before starting managergo func() { defer GinkgoRecover(); k8sManager.Start(ctx) }()cancel() context and testEnv.Stop() in AfterSuiteCRD directory paths are relative to the suite file location. Adjust depth (.., ../..) based on package nesting.
loader/loader_mock.go intercepts resource loading via context keys:
mockContext := toolkit.GetMockedContext(ctx, []toolkit.MockData{
{ContextKey: loader.SnapshotContextKey, Resource: mySnapshot},
})
result, err := adapter.loader.GetSnapshot(mockContext, client, name, namespace)
Each resource type has a corresponding *ContextKey constant (34 keys available).
Describe > Context("When...") > It("should...")Eventually for async assertions, never time.SleepGet() after Create()/Update() to ensure server-side stateginkgolinter is enabled — follow its conventions| Problem | Fix |
|---|---|
no matches for kind "X" | Missing CRD in CRDDirectoryPaths — add the dependency path |
| Port conflict on metrics | Ensure Metrics.BindAddress: "0" in manager options |
make test fails on missing CRDs | Run make download-crds — vendoring prunes YAML files |
| Stale generated code | Run make generate manifests before testing |
| Tests pass locally, fail in CI | Check go mod tidy and make fmt — CI fails on uncommitted changes |
unit-tests**/zz_generated*, e2e-tests/**, vendorUse when CI checks fail unexpectedly, when preparing code for CI, or when encountering non-obvious build and pipeline behavior. Covers vendoring, hermetic builds, security scans, code generation checks, coverage, and webhook validation gotchas.
Use when debugging integration-service running on a cluster. Covers pod logs, health probes, metrics, webhooks, network policies, environment variables, snapshot GC, and common failure modes.
Use when setting up a local development environment, deploying integration-service to a cluster, installing CRDs, or tearing down a Kind cluster. Covers make targets, kustomize deployment, and full Konflux stack setup.
Use when preparing a pull request for review, before pushing, or when reviewing someone else's PR. Checklist of CI checks, commit conventions, code generation, testing, and documentation requirements.
Use when building, configuring, or running e2e tests for integration-service against a real cluster (Kind or OpenShift). Covers environment variables, test framework, Ginkgo flags, CI pipeline, and test repos.