This guide covers the different testing approaches, from unit tests to full end-to-end testing on Kubernetes.
- Rust toolchain (1.88+)
- Docker
- kubectl
- k3d for local Kubernetes clusters
# Lint and unit tests
make lint test
# Build
make build
# Generate CRDs
make crdsmake testUnit tests are located in each module and test individual functions without external dependencies.
Integration tests verify CRD schemas and validation against a live Kubernetes cluster (no Sonarr instance required).
# Create a k3d cluster and install CRDs
make e2e-cluster-create
make install
# Run integration tests
make integration-test
# Cleanup
make e2e-cluster-deleteE2E tests verify the full reconciliation loop: the operator watches CRDs, calls the Sonarr API, and updates resource status.
- Create a k3d cluster with NodePort mapping and install CRDs
- Run the operator locally (or as a Deployment)
- Create an API key Secret and apply the Sonarr CR
- The operator reconciles the Sonarr CR → creates Deployment, Service, PVC
- Sonarr boots with the deterministic API key
- Tests create sub-resource CRs (Tags, RootFolders, etc.) and verify via the Sonarr API
# Terminal 1: Create cluster + deploy Sonarr
make e2e-up
# Terminal 2: Run the operator locally
make run-debug
# Terminal 3: Run E2E tests
make e2e
# Verbose with debug logging
make e2e-verboseThe only fixture file is:
tests/e2e/fixtures/sonarr-instance.yaml— the Sonarr CR that the operator reconciles into a running Sonarr instance withserviceType: NodePorton port 30989.
All test resources (Tags, RootFolders, QualityProfiles, etc.) are created programmatically by the Rust test code.
# Remove test resources (keep cluster)
make e2e-cleanup
# Tear down everything
make e2e-downThe GitHub Actions CI pipeline (.github/workflows/ci.yml) automates the full test suite:
- Lint & Format —
cargo fmt --check+cargo clippy - Unit Tests —
cargo test --lib - Generate CRDs —
cargo run --bin crdgen - Build & Push Image — Docker build + push to GHCR
- Integration Tests — CRD schema validation on K8s v1.28, v1.29, and latest
- E2E Tests — Full reconciliation against a live Sonarr instance in k3d
# Local
RUST_LOG=debug cargo run --bin sonarr-operator
# In-cluster
kubectl logs -n sonarr-operator-system deployment/sonarr-operator -fcurl -H "X-Api-Key: $SONARR_API_KEY" http://localhost:8989/api/v3/tag
curl -H "X-Api-Key: $SONARR_API_KEY" http://localhost:8989/api/v3/system/status| Symptom | Fix |
|---|---|
SONARR_API_KEY not set |
export SONARR_API_KEY=<your-key> |
| Sonarr CR never becomes Ready | Check operator logs: kubectl logs -n sonarr-operator-system deploy/sonarr-operator |
| CRD not found | Run make install to apply CRDs |
| Finalizer stuck on delete | Check operator logs for cleanup errors |
| NodePort not reachable | Ensure k3d was created with --port 8989:30989@server:0 |