Ginkgo
Ginkgo
BDD-style testing framework for Go applications
Ginkgo is a Behavior-Driven Development (BDD) testing framework for Go that is used in the Control Plane for writing expressive tests.
Behavior-Driven Development
Ginkgo encourages writing tests that describe the behavior of your application in a way that's easy to understand for both developers and non-technical stakeholders.
Overviewโ
Ginkgo is designed to make writing and running tests productive and enjoyable. It integrates with Go's built-in testing package but offers a more expressive and feature-rich approach to testing.

Why Ginkgo?โ
๐งช BDD-Style Tests
Write tests in a natural language style with Describe, Context, and It blocks.
๐ Nested Specs
Organize tests hierarchically with nested contexts and descriptions.
โฑ๏ธ Focused Specs
Run specific tests with F-prefixed blocks (FDescribe, FContext, FIt).
โญ๏ธ Skip Specs
Skip specific tests with X-prefixed blocks (XDescribe, XContext, XIt).
๐๏ธ Parallel Testing
Run tests in parallel for faster execution times.
๐ Reporting
Generate detailed test reports with various output formats.
Integration in the Control Planeโ
BDD for complex scenarios
In the Control Plane, Ginkgo is particularly valuable for testing complex behaviors like API interactions and controller reconciliation loops.
Controller Tests
Tests for Kubernetes controllers that follow the BDD pattern:
- Controller initialization and setup
- Resource creation and reconciliation
- Error handling and edge cases
- Status updates and finalizers
Integration Tests
Tests that verify interactions between components:
- API server and client communication
- Service interactions and dependencies
- End-to-end workflows
- Cross-component behavior
Configurationโ
Powerful testing capabilities
Ginkgo offers many advanced features that help with writing comprehensive tests for complex systems like the Control Plane.
Command Line Interfaceโ
Ginkgo provides a powerful command-line interface for running tests:
# Install the Ginkgo CLI
go install github.com/onsi/ginkgo/v2/ginkgo@latest
# Run all tests in current package
ginkgo
# Run tests in watch mode (rerun on file changes)
ginkgo watch
# Run tests in specific packages
ginkgo ./pkg/controllers/... ./pkg/apis/...
# Generate test coverage report
ginkgo -cover -coverprofile=coverage.out
# Run tests in parallel
ginkgo -p
# Focus on specific tests
ginkgo --focus "FileManager"
# Skip specific tests
ginkgo --skip "Database"
Advanced Featuresโ
Asynchronous Testing
Perfect for testing controllers that may reconcile resources asynchronously
Table-Driven Tests
Concisely test multiple cases
Setup & Teardown
Hooks for test preparation:
- BeforeEach: Before each spec
- AfterEach: After each spec
- BeforeSuite: Before all specs
- AfterSuite: After all specs
Kubernetes Integrationโ
Kubernetes integration
Ginkgo works seamlessly with the Kubernetes envtest package, making it ideal for testing controllers in the Control Plane.
Best Practices in the Control Planeโ
๐งฉ Modular Test Structure
Organize tests hierarchically with Describe and Context blocks matching logical components.
๐ฌ Clear Expectations
Write clear expectations with descriptive failure messages for easier debugging.
โป๏ธ Reusable Helpers
Create helper functions for common test setups to reduce duplication.
๐ Isolated Test Environments
Use BeforeEach and AfterEach to ensure tests start with a clean environment.
๐ Test Coverage
Run tests with coverage reports to identify untested code paths.
โก Fast Feedback
Run focused tests during development for quick feedback cycles.
Related Resourcesโ
Gomega
The matcher/assertion library designed to work with Ginkgo.
Testify
Another testing toolkit used in the Control Plane.
Go-Snaps
Snapshot testing library for Go applications.