Skip to content

Commit d76f60c

Browse files
authored
Merge pull request #3030 from psturc/improve-acceptance-tests
feat: improve acceptance tests
2 parents 454bb13 + 783e7d2 commit d76f60c

File tree

8 files changed

+24
-467
lines changed

8 files changed

+24
-467
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 & 6 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,13 @@ 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 && \
128-
export COVERAGE_FILEPATH="$$ACCEPTANCE_WORKDIR"; \
129-
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"
129+
export GOCOVERDIR="$${ACCEPTANCE_WORKDIR}/coverage"; \
130+
cd acceptance && go test -timeout $(ACCEPTANCE_TIMEOUT) ./... ; go tool covdata textfmt -i=$${GOCOVERDIR} -o="$(ROOT_DIR)/coverage-acceptance.out"
132131

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

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@ run `make dist` to build for all supported architectures.
1818

1919
## Testing
2020

21-
Run `make test` to run the unit tests, and `make acceptance` to run the
21+
Run `make test` to run the unit tests, and `E2E_INSTRUMENTATION=true make acceptance` to run the
2222
acceptance tests.
2323

24+
The purpose of the `E2E_INSTRUMENTATION=true` environment variable is to pass
25+
extra flags to the build command. This instruments the resulting binary,
26+
allowing for the collection of coverage data during the acceptance test run.
27+
(more information here: https://go.dev/doc/build-cover).
28+
2429
## Linting
2530

2631
Run `make lint` to check for linting issues, and `make lint-fix` to fix linting

acceptance/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ uses the established Go test to launch Godog.
1414

1515
To run the acceptance tests either run:
1616

17-
$ make acceptance
17+
$ E2E_INSTRUMENTATION=true make acceptance
1818

1919
from the root of the repository.
2020

@@ -64,7 +64,7 @@ Docker website how to accomplish that.
6464
## Debugging
6565

6666
The acceptance tests execute the `ec` binary during test execution. (For this
67-
reason `make acceptance` builds the binary prior to running the tests.)
67+
reason `E2E_INSTRUMENTATION=true make acceptance` builds the binary prior to running the tests.)
6868

6969
To use a debugger, like [delve](https://github.com/go-delve/delve), you must
7070
determine what part of the code is being debugged. If it's part of the

acceptance/cli/cli.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ func variables(ctx context.Context) (context.Context, []string, map[string]strin
8787
// fail if it can't locate the git command
8888
environment := []string{
8989
"PATH=" + os.Getenv("PATH"),
90-
"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
91-
"COVERAGE_FILENAME=" + os.Getenv("COVERAGE_FILENAME"), // suffix for the coverage file
90+
"GOCOVERDIR=" + os.Getenv("GOCOVERDIR"), // directory where the Go coverage raw data is stored
9291
"HOME=/tmp",
9392
}
9493

0 commit comments

Comments
 (0)