Skip to content

Commit fe932a7

Browse files
authored
Merge pull request #5200 from camilamacedo86/test-organization
🌱 Reorganise tests: separate unit and integration tests with build tags
2 parents 3682ddd + a1424c0 commit fe932a7

File tree

16 files changed

+64
-208
lines changed

16 files changed

+64
-208
lines changed

.github/workflows/coverage.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ jobs:
2222
- name: Remove pre-installed kustomize
2323
run: sudo rm -f /usr/local/bin/kustomize
2424

25+
- name: Install Kubebuilder
26+
run: make install
27+
2528
- name: Run tests with coverage
2629
run: make test-coverage
2730

AGENTS.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pkg/
3232
external/ External plugin support
3333
docs/book/ mdBook sources + tutorial samples
3434
test/
35-
e2e/ End-to-end tests (v4, helm, deployimage, alpha*)
35+
e2e/ End-to-end tests requiring Kubernetes cluster (v4, helm, deployimage)
3636
testdata/ Testdata generation scripts
3737
testdata/ Generated sample projects (DO NOT EDIT)
3838
hack/docs/ Documentation generation scripts
@@ -82,8 +82,7 @@ make lint-fix # Auto-fix Go code
8282
### Testing
8383
```bash
8484
make test-unit # Fast unit tests (./pkg/..., ./test/e2e/utils/...)
85-
make test-integration # Integration tests
86-
make test-features # Feature tests
85+
make test-integration # Integration tests (may create temp dirs, download binaries)
8786
make test-testdata # Test all testdata projects
8887
make test-e2e-local # Full e2e (creates kind cluster)
8988
make test # CI aggregate (all of above + license)
@@ -191,6 +190,17 @@ kubebuilder alpha update # Update to latest plugin versions
191190
- Use **Ginkgo v2** + **Gomega** for BDD-style tests.
192191
- Tests depending on the Kubebuilder binary should use: `utils.NewTestContext(util.KubebuilderBinName, "GO111MODULE=on")`
193192

193+
### Test Organization
194+
- **Unit tests** (`*_test.go` in `pkg/`) - Test individual packages in isolation, fast
195+
- **Integration tests** (`*_integration_test.go` in `pkg/`) - Test multiple components together without cluster
196+
- Must have `//go:build integration` tag at the top
197+
- May create temp dirs, download binaries, or scaffold files
198+
- Examples: alpha update, grafana scaffolding, helm chart generation
199+
- **E2E tests** (`test/e2e/`) - **ONLY** for tests requiring a Kubernetes cluster (KIND)
200+
- `v4/plugin_cluster_test.go` - Test v4 plugin deployment
201+
- `helm/plugin_cluster_test.go` - Test Helm chart deployment
202+
- `deployimage/plugin_cluster_test.go` - Test deploy-image plugin
203+
194204
### Scaffolding
195205
- Use library helpers from `pkg/plugin/util/`
196206
- Use markers for extensibility

Makefile

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,25 +145,21 @@ go-apidiff:
145145
##@ Tests
146146

147147
.PHONY: test
148-
test: test-unit test-integration test-features test-testdata test-book test-license ## Run the unit and integration tests (used in the CI)
148+
test: test-unit test-integration test-testdata test-book test-license ## Run the unit and integration tests (used in the CI)
149149

150150
.PHONY: test-unit
151151
TEST_PKGS := ./pkg/... ./test/e2e/utils/...
152152
test-unit: ## Run the unit tests
153153
go test -race $(TEST_PKGS)
154154

155+
.PHONY: test-integration
156+
test-integration: install ## Run the integration tests (requires kubebuilder binary in PATH)
157+
go test -race -tags=integration -timeout 30m $(TEST_PKGS)
158+
155159
.PHONY: test-coverage
156-
test-coverage: ## Run unit tests creating the output to report coverage
160+
test-coverage: ## Run unit and integration tests with coverage report
157161
- rm -rf *.out # Remove all coverage files if exists
158-
go test -race -failfast -tags=integration -coverprofile=coverage-all.out -coverpkg="./pkg/cli/...,./pkg/config/...,./pkg/internal/...,./pkg/machinery/...,./pkg/model/...,./pkg/plugin/...,./pkg/plugins/golang/...,./pkg/plugins/external/...,./pkg/plugins/optional/grafana/...,./pkg/plugins/optional/helm/v2alpha/..." $(TEST_PKGS)
159-
160-
.PHONY: test-features
161-
test-features: ## Run the integration tests
162-
./test/features.sh
163-
164-
.PHONY: test-integration
165-
test-integration: ## Run the integration tests
166-
./test/integration.sh
162+
go test -race -failfast -tags=integration -timeout 30m -coverprofile=coverage-all.out -coverpkg="./pkg/cli/...,./pkg/config/...,./pkg/internal/...,./pkg/machinery/...,./pkg/model/...,./pkg/plugin/...,./pkg/plugins/golang/...,./pkg/plugins/external/...,./pkg/plugins/optional/grafana/...,./pkg/plugins/optional/helm/v2alpha/..." $(TEST_PKGS)
167163

168164
.PHONY: check-testdata
169165
check-testdata: ## Run the script to ensure that the testdata is updated

pkg/cli/alpha/internal/common/common_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build integration
2+
// +build integration
3+
14
/*
25
Copyright 2025 The Kubernetes Authors.
36

test/e2e/alphaupdate/update_test.go renamed to pkg/cli/alpha/internal/update/integration_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build integration
2+
// +build integration
3+
14
/*
25
Copyright 2025 The Kubernetes Authors.
36
@@ -14,7 +17,7 @@ See the License for the specific language governing permissions and
1417
limitations under the License.
1518
*/
1619

17-
package alphaupdate
20+
package update
1821

1922
import (
2023
"bytes"

pkg/cli/alpha/internal/update/prepare_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build integration
2+
// +build integration
3+
14
/*
25
Copyright 2025 The Kubernetes Authors.
36

pkg/cli/alpha/internal/update/update_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build integration
2+
// +build integration
3+
14
/*
25
Copyright 2025 The Kubernetes Authors.
36

pkg/cli/alpha/internal/update/validate_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build integration
2+
// +build integration
3+
14
/*
25
Copyright 2025 The Kubernetes Authors.
36

pkg/plugins/optional/grafana/v1alpha/scaffolds/edit_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build integration
2+
// +build integration
3+
14
/*
25
Copyright 2025 The Kubernetes Authors.
36

pkg/plugins/optional/grafana/v1alpha/scaffolds/init_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//go:build integration
2+
// +build integration
3+
14
/*
25
Copyright 2025 The Kubernetes Authors.
36

0 commit comments

Comments
 (0)