From 430d654cc38e156bafbaa4af92ed0af6024e9ec5 Mon Sep 17 00:00:00 2001 From: Todd Short Date: Fri, 18 Sep 2026 12:04:44 -0400 Subject: [PATCH] test: collect coverage from unit test target Signed-off-by: Todd Short --- .github/workflows/migration-test.yaml | 2 +- migration.mk | 18 ++++++++---------- specs/20260821-migration-v0-to-v1/e2e.md | 8 +++++--- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/workflows/migration-test.yaml b/.github/workflows/migration-test.yaml index 8664256..0e26c90 100644 --- a/.github/workflows/migration-test.yaml +++ b/.github/workflows/migration-test.yaml @@ -23,7 +23,7 @@ jobs: with: go-version-file: go.mod - name: Run unit tests with coverage - run: make migration/test-coverage + run: make migration/test-unit - name: Upload unit coverage if: always() uses: actions/upload-artifact@v7 diff --git a/migration.mk b/migration.mk index 389509d..167172b 100644 --- a/migration.mk +++ b/migration.mk @@ -46,19 +46,15 @@ migration/build-catalogs: ## Build migrate-catalogs-v0-to-v1 into bin/ go build -cover -covermode=count -o $(MIGRATE_CATALOGS_BIN) ./migration/examples/cmd/migrate-catalogs-v0-to-v1 .PHONY: migration/test-unit -migration/test-unit: ## Run migration unit tests - go test ./migration/... -count=1 +migration/test-unit: ## Run migration unit tests and write a coverage profile + @mkdir -p $(COVERAGE_DIR) + go test ./migration/... -count=1 -covermode=count -coverprofile=$(UNIT_COVERAGE_PROFILE) + go tool cover -func=$(UNIT_COVERAGE_PROFILE) | tee $(UNIT_COVERAGE_REPORT) .PHONY: migration/test-verbose migration/test-verbose: ## Run migration unit tests with verbose output go test ./migration/... -v -count=1 -.PHONY: migration/test-coverage -migration/test-coverage: ## Run migration unit tests and display coverage - @mkdir -p $(COVERAGE_DIR) - go test ./migration/... -count=1 -covermode=count -coverprofile=$(UNIT_COVERAGE_PROFILE) - go tool cover -func=$(UNIT_COVERAGE_PROFILE) | tee $(UNIT_COVERAGE_REPORT) - .PHONY: migration/e2e-setup migration/e2e-setup: $(KIND) ## Create kind and install pinned OLMv0 and OLMv1 releases E2E_KUBECONFIG="$(E2E_KUBECONFIG)" E2E_CLUSTER_NAME="$(E2E_CLUSTER_NAME)" KIND="$(KIND)" OLM_V0_CRDS="$(OLM_V0_CRDS)" OLM_V0_MANIFEST="$(OLM_V0_MANIFEST)" OLM_V1_INSTALL="$(OLM_V1_INSTALL)" OLM_V1_INSTALL_SHA256="$(OLM_V1_INSTALL_SHA256)" ./hack/e2e/migration/setup.sh @@ -115,10 +111,12 @@ migration/test-e2e-real-operator: migration/build ## Run real-operator migration .PHONY: migration/report-coverage-all migration/report-coverage-all: ## Display coverage from existing unit and collected E2E CLI profiles - @coverage_dirs="$$(find "$(E2E_COVERAGE_DIR)" -type f -name 'covmeta.*' -printf '%h\n' 2>/dev/null | sort -u | paste -sd, -)"; test -n "$$coverage_dirs" || { echo "no E2E CLI coverage found; run both E2E matrices before migration/test-coverage-all" >&2; exit 2; }; go tool covdata textfmt -i="$$coverage_dirs" -o="$(E2E_COVERAGE_PROFILE)"; awk 'FNR == 1 { next } { key = $$1 " " $$2; if (!(key in count)) order[++n] = key; count[key] += $$3 } END { print "mode: count"; for (i = 1; i <= n; i++) print order[i] " " count[order[i]] }' "$(UNIT_COVERAGE_PROFILE)" "$(E2E_COVERAGE_PROFILE)" > "$(ALL_COVERAGE_PROFILE)"; go tool cover -func="$(ALL_COVERAGE_PROFILE)" + @mkdir -p $(COVERAGE_DIR) + @test -f "$(UNIT_COVERAGE_PROFILE)" || { echo "unit coverage is missing; run make migration/test-unit first" >&2; exit 2; } + @coverage_dirs="$$(find "$(E2E_COVERAGE_DIR)" -type f -name 'covmeta.*' -printf '%h\n' 2>/dev/null | sort -u | paste -sd, -)"; test -n "$$coverage_dirs" || { echo "no E2E CLI coverage found; run both E2E matrices before migration/report-coverage-all" >&2; exit 2; }; go tool covdata textfmt -i="$$coverage_dirs" -o="$(E2E_COVERAGE_PROFILE)"; awk 'FNR == 1 { next } { key = $$1 " " $$2; if (!(key in count)) order[++n] = key; count[key] += $$3 } END { print "mode: count"; for (i = 1; i <= n; i++) print order[i] " " count[order[i]] }' "$(UNIT_COVERAGE_PROFILE)" "$(E2E_COVERAGE_PROFILE)" > "$(ALL_COVERAGE_PROFILE)"; go tool cover -func="$(ALL_COVERAGE_PROFILE)" .PHONY: migration/test-coverage-all -migration/test-coverage-all: migration/test-coverage migration/report-coverage-all ## Run unit tests and display combined unit and collected E2E CLI coverage +migration/test-coverage-all: migration/test-unit migration/report-coverage-all ## Run unit tests and display combined unit and collected E2E CLI coverage .PHONY: migration/clean migration/clean: ## Remove compiled migration CLI binaries from bin/ diff --git a/specs/20260821-migration-v0-to-v1/e2e.md b/specs/20260821-migration-v0-to-v1/e2e.md index fe66e45..fc48957 100644 --- a/specs/20260821-migration-v0-to-v1/e2e.md +++ b/specs/20260821-migration-v0-to-v1/e2e.md @@ -96,9 +96,11 @@ write diagnostics below `E2E_ARTIFACTS` (default: `artifacts/e2e`). Coverage is optional because the migration binaries run outside the Go test process. E2E CLI binaries are always built with `go build -cover`, and the E2E targets collect their coverage -under `artifacts/e2e/coverage`. After both E2E matrices have run, `make migration/test-coverage-all` -merges that CLI data with a fresh unit-test profile and displays the combined result. It fails -if E2E coverage is absent, preventing a misleading unit-only report. Upload the merged profile +under `artifacts/e2e/coverage`. `make migration/test-unit` always writes the unit profile under +`artifacts/coverage`; after both E2E matrices have run, `make migration/report-coverage-all` +merges the existing profiles and displays the combined result. `make migration/test-coverage-all` +reruns the unit suite before displaying that report. The report fails if unit or E2E coverage is +absent, preventing a misleading partial result. Upload the merged profile and failure artifacts, but do not impose an E2E percentage threshold; the unit suite owns the ≥80% gate. This avoids treating controller waits and external command plumbing as unit coverage while still showing which migration paths the E2E suite executes.