Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ jobs:

- name: Run pre-commit checks
run: just pre-commit

- name: Run end-to-end tests
run: just test-e2e
17 changes: 12 additions & 5 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ build-release:
go build -ldflags="-s -w" -o http-assert .

[doc("Run all pre-commit checks")]
pre-commit: build vet lint test test-race test-cover security
pre-commit: build vet lint test test-race security

[doc("Build and check compilation without creating binary")]
check:
Expand All @@ -25,10 +25,14 @@ vet:
lint:
golangci-lint run ./...

[doc("Run tests")]
[doc("Run unit tests (fast; end-to-end tests are skipped)")]
test:
go test ./...

[doc("Run the end-to-end suite (builds and executes the CLI)")]
test-e2e:
go test ./... -e2e -count=1

[doc("Run tests with race detection")]
test-race:
go test ./... -race
Expand All @@ -43,7 +47,7 @@ test-cover:
set -euo pipefail
unit=$(mktemp -d); e2e=$(mktemp -d)
trap 'rm -rf "$unit" "$e2e"' EXIT
E2E_COVERDIR="$e2e" go test ./... -cover -args -test.gocoverdir="$unit"
E2E_COVERDIR="$e2e" go test ./... -e2e -count=1 -cover -args -test.gocoverdir="$unit"
go tool covdata percent -i="$unit,$e2e"

[doc("Run tests with coverage and generate HTML report")]
Expand All @@ -52,7 +56,7 @@ test-coverage:
set -euo pipefail
unit=$(mktemp -d); e2e=$(mktemp -d)
trap 'rm -rf "$unit" "$e2e"' EXIT
E2E_COVERDIR="$e2e" go test ./... -cover -args -test.gocoverdir="$unit"
E2E_COVERDIR="$e2e" go test ./... -e2e -count=1 -cover -args -test.gocoverdir="$unit"
go tool covdata textfmt -i="$unit,$e2e" -o=coverage.out
go tool cover -html=coverage.out -o coverage.html
echo "Coverage report: coverage.html"
Expand All @@ -63,7 +67,7 @@ test-cover-func:
set -euo pipefail
unit=$(mktemp -d); e2e=$(mktemp -d)
trap 'rm -rf "$unit" "$e2e"' EXIT
E2E_COVERDIR="$e2e" go test ./... -cover -args -test.gocoverdir="$unit" >/dev/null
E2E_COVERDIR="$e2e" go test ./... -e2e -count=1 -cover -args -test.gocoverdir="$unit" >/dev/null
go tool covdata func -i="$unit,$e2e" | sort -k2 -n

[doc("Clean build artifacts")]
Expand All @@ -87,6 +91,9 @@ deps-update:
deps-download:
go mod download

[doc("Run every check CI runs, including the end-to-end suite")]
pre-push: pre-commit test-e2e

[doc("Run a quick development cycle")]
dev: fmt vet test

Expand Down
14 changes: 14 additions & 0 deletions e2e_harness_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main_test

import (
"flag"
"fmt"
"os"
"os/exec"
Expand All @@ -18,6 +19,15 @@ import (
// #55 run() extraction, #56 assertion constructors), which is the property that
// makes those refactors safe to perform.

// runE2E gates the whole suite. It is opt-in: `go test ./...` runs the unit
// tests only, and the end-to-end tests run when explicitly asked for.
//
// A registered flag is used rather than a build tag on purpose. A tagged file
// is invisible to `go vet` and `golangci-lint` unless every invocation passes
// the tag, so tagging would silently drop this file out of both -- verified,
// and the reason the switch lives here instead.
var runE2E = flag.Bool("e2e", false, "run the end-to-end suite (builds and executes the CLI)")

var (
binPath string
buildErr error
Expand All @@ -35,6 +45,10 @@ func coverDir() string { return os.Getenv("E2E_COVERDIR") }
func binary(t *testing.T) string {
t.Helper()

if !*runE2E {
t.Skip("e2e: pass -e2e to run (or use `just test-e2e`)")
}

buildOne.Do(func() {
dir, err := os.MkdirTemp("", "http-assert-e2e")
if err != nil {
Expand Down
Loading