Skip to content

Commit e442826

Browse files
committed
feat: improve acceptance tests
* use native Go instrumentation * report test results per flag (one coverage output file per flag
1 parent 81bcf73 commit e442826

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

.github/workflows/checks-codecov.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ jobs:
9191
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
9292
with:
9393
files: ./coverage-unit.out
94+
disable_search: true
9495
flags: unit
9596

9697
- name: Upload generative test coverage report
@@ -99,6 +100,7 @@ jobs:
99100
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
100101
with:
101102
files: ./coverage-generative.out
103+
disable_search: true
102104
flags: generative
103105

104106
- name: Upload integration test coverage report
@@ -107,6 +109,7 @@ jobs:
107109
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
108110
with:
109111
files: ./coverage-integration.out
112+
disable_search: true
110113
flags: integration
111114

112115
Acceptance:
@@ -143,12 +146,16 @@ jobs:
143146
run: git log --oneline -n1
144147

145148
- name: Acceptance test
146-
run: make acceptance
149+
id: acceptance_test
150+
run: E2E_INSTRUMENTATION=true make acceptance
147151

148152
- name: Upload coverage report
149153
uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
154+
env:
155+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
150156
with:
151157
files: ./coverage-acceptance.out
158+
disable_search: true
152159
flags: acceptance
153160

154161
Tools:

Makefile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ SHELL=$(if $@,$(info ❱ $@))$(_SHELL)
1313
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
1414
COPY:=The Conforma Contributors
1515
COSIGN_VERSION=$(shell go list -f '{{.Version}}' -m github.com/sigstore/cosign/v2)
16+
E2E_INSTRUMENTATION_FLAGS := $(if $(filter $(E2E_INSTRUMENTATION),true),-cover -covermode atomic)
1617

1718
##@ Information
1819

@@ -54,7 +55,7 @@ BUILD_BIN_SUFFIX=$(if $(DEBUG_BUILD),_debug,)
5455
$(ALL_SUPPORTED_OS_ARCH): generate ## Build binaries for specific platform/architecture, e.g. make dist/ec_linux_amd64
5556
@GOOS=$(word 2,$(subst _, ,$(notdir $@))); \
5657
GOARCH=$(word 3,$(subst _, ,$(notdir $@))); \
57-
GOOS=$${GOOS} GOARCH=$${GOARCH} CGO_ENABLED=0 go build $(BUILD_TRIMPATH) $(BUILD_GC_FLAGS) -ldflags="$(BUILD_LD_FLAGS) -X github.com/conforma/cli/internal/version.Version=$(VERSION)" -o dist/ec_$${GOOS}_$${GOARCH}$(BUILD_BIN_SUFFIX); \
58+
GOOS=$${GOOS} GOARCH=$${GOARCH} CGO_ENABLED=0 go build $(E2E_INSTRUMENTATION_FLAGS) $(BUILD_TRIMPATH) $(BUILD_GC_FLAGS) -ldflags="$(BUILD_LD_FLAGS) -X github.com/conforma/cli/internal/version.Version=$(VERSION)" -o dist/ec_$${GOOS}_$${GOARCH}$(BUILD_BIN_SUFFIX); \
5859
sha256sum -b dist/ec_$${GOOS}_$${GOARCH}$(BUILD_BIN_SUFFIX) > dist/ec_$${GOOS}_$${GOARCH}$(BUILD_BIN_SUFFIX).sha256
5960

6061
.PHONY: dist
@@ -120,15 +121,15 @@ acceptance: ## Run all acceptance tests
120121
cleanup() { \
121122
cp "$${ACCEPTANCE_WORKDIR}"/features/__snapshots__/* "$(ROOT_DIR)"/features/__snapshots__/; \
122123
}; \
124+
mkdir -p "$${ACCEPTANCE_WORKDIR}/coverage"; \
123125
trap cleanup EXIT; \
124126
cp -R . "$$ACCEPTANCE_WORKDIR"; \
125127
cd "$$ACCEPTANCE_WORKDIR" && \
126-
go run acceptance/coverage/coverage.go && \
127128
$(MAKE) build && \
128129
export COVERAGE_FILEPATH="$$ACCEPTANCE_WORKDIR"; \
129130
export COVERAGE_FILENAME="-acceptance"; \
130-
cd acceptance && go test -coverprofile "$$ACCEPTANCE_WORKDIR/coverage-acceptance.out" -timeout $(ACCEPTANCE_TIMEOUT) ./... && \
131-
go run -modfile "$$ACCEPTANCE_WORKDIR/tools/go.mod" github.com/wadey/gocovmerge "$$ACCEPTANCE_WORKDIR/coverage-acceptance.out" > "$(ROOT_DIR)/coverage-acceptance.out"
131+
export GOCOVERDIR="$${ACCEPTANCE_WORKDIR}/coverage"; \
132+
cd acceptance && go test ./... ; go tool covdata textfmt -i=$${GOCOVERDIR} -o="$(ROOT_DIR)/coverage-acceptance.out"
132133

133134
# Add @focus above the feature you're hacking on to use this
134135
# (Mainly for use with the feature-% target below)

acceptance/cli/cli.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ func variables(ctx context.Context) (context.Context, []string, map[string]strin
8989
"PATH=" + os.Getenv("PATH"),
9090
"COVERAGE_FILEPATH=" + os.Getenv("COVERAGE_FILEPATH"), // where to put the coverage file, $COVERAGE_FILEPATH is provided by the Makefile, if empty it'll be $TMPDIR
9191
"COVERAGE_FILENAME=" + os.Getenv("COVERAGE_FILENAME"), // suffix for the coverage file
92+
"GOCOVERDIR=" + os.Getenv("GOCOVERDIR"), // directory where the Go coverage raw data is stored
9293
"HOME=/tmp",
9394
}
9495

0 commit comments

Comments
 (0)