git » chasquid » commit 21e8d50

test: Improve layout of helper binaries

author Alberto Bertogli
2022-08-27 17:33:33 UTC
committer Alberto Bertogli
2022-08-27 17:46:54 UTC
parent 567ad3512201958880bbe505ec23bce1f785d39d

test: Improve layout of helper binaries

This patch moves the test helper binaries to a "one directory per
helper" layout, and also makes them to be ignored in the coverage build
instead of all builds.

With this change, "go build ./..." will build all binaries including the
test helpers, which helps make sure that module manage automation also
considers them. In particular, this makes "go mod tidy" work fine.

.gitignore +9 -2
test/Dockerfile +1 -1
test/cover.sh +3 -3
test/util/{ => conngen}/conngen.go +2 -2
test/util/{ => coverhtml}/coverhtml.go +2 -2
test/util/{ => fexp}/fexp.go +2 -2
test/util/{ => generate_cert}/generate_cert.go +2 -2
test/util/{ => gocovcat}/gocovcat.go +2 -2
test/util/lib.sh +10 -7
test/util/{ => loadgen}/loadgen.go +2 -2
test/util/{ => minidns}/minidns.go +2 -2

diff --git a/.gitignore b/.gitignore
index 7ba3f32..36d9955 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,8 +17,15 @@ cmd/chasquid-util/chasquid-util
 cmd/smtp-check/smtp-check
 cmd/mda-lmtp/mda-lmtp
 cmd/dovecot-auth-cli/dovecot-auth-cli
-test/util/minidns
-test/util/fexp
+
+# Test util binaries.
+test/util/conngen/conngen
+test/util/coverhtml/coverhtml
+test/util/fexp/fexp
+test/util/generate_cert/generate_cert
+test/util/gocovcat/gocovcat
+test/util/loadgen/loadgen
+test/util/minidns/minidns
 
 # Test binary, generated during coverage tests.
 chasquid.test
diff --git a/test/Dockerfile b/test/Dockerfile
index 6b2cc52..d0803f2 100644
--- a/test/Dockerfile
+++ b/test/Dockerfile
@@ -60,7 +60,7 @@ ENV GOPATH=
 RUN go get -v ${GO_GET_ARGS} ./... && go mod download
 
 # Build the minidns server, which will be run from within the entrypoint.
-RUN go build -o /tmp/minidns ./test/util/minidns.go
+RUN go build -o /tmp/minidns ./test/util/minidns/minidns.go
 USER root
 
 # Custom entry point, which uses our own DNS server.
diff --git a/test/cover.sh b/test/cover.sh
index 583ce5e..c212c24 100755
--- a/test/cover.sh
+++ b/test/cover.sh
@@ -27,7 +27,7 @@ export COVER_DIR="$PWD/.coverage"
 # the single-binary tests to fail: cross-package expvars confuse the expvarom
 # tests, which don't expect any expvars to exists besides the one registered
 # in the tests themselves.
-for pkg in $(go list ./... | grep -v chasquid/cmd/); do
+for pkg in $(go list ./... | grep -v -E 'chasquid/cmd/|chasquid/test'); do
 	OUT_FILE="$COVER_DIR/pkg-`echo $pkg | sed s+/+_+g`.out"
 	go test -tags coverage \
 		-covermode=count \
@@ -45,14 +45,14 @@ setsid -w ./cmd/dovecot-auth-cli/test.sh
 
 # Merge all coverage output into a single file.
 # Ignore protocol buffer-generated files, as they are not relevant.
-go run "${UTILDIR}/gocovcat.go" .coverage/*.out \
+go run "${UTILDIR}/gocovcat/gocovcat.go" .coverage/*.out \
 	| grep -v ".pb.go:" \
 	> .coverage/all.out
 
 # Generate reports based on the merged output.
 go tool cover -func="$COVER_DIR/all.out" | sort -k 3 -n > "$COVER_DIR/func.txt"
 go tool cover -html="$COVER_DIR/all.out" -o "$COVER_DIR/classic.html"
-go run "${UTILDIR}/coverhtml.go" \
+go run "${UTILDIR}/coverhtml/coverhtml.go" \
 	-input="$COVER_DIR/all.out"  -strip=3 \
 	-output="$COVER_DIR/coverage.html" \
 	-title="chasquid coverage report" \
diff --git a/test/util/conngen.go b/test/util/conngen/conngen.go
similarity index 97%
rename from test/util/conngen.go
rename to test/util/conngen/conngen.go
index 9270dae..e7f1764 100644
--- a/test/util/conngen.go
+++ b/test/util/conngen/conngen.go
@@ -1,5 +1,5 @@
-//go:build ignore
-// +build ignore
+//go:build !coverage
+// +build !coverage
 
 // SMTP connection generator, for testing purposes.
 package main
diff --git a/test/util/coverhtml.go b/test/util/coverhtml/coverhtml.go
similarity index 99%
rename from test/util/coverhtml.go
rename to test/util/coverhtml/coverhtml.go
index ed4cace..f9340ea 100644
--- a/test/util/coverhtml.go
+++ b/test/util/coverhtml/coverhtml.go
@@ -1,5 +1,5 @@
-//go:build ignore
-// +build ignore
+//go:build !coverage
+// +build !coverage
 
 // Generate an HTML visualization of a Go coverage profile.
 // Serves a similar purpose to "go tool cover -html", but has a different
diff --git a/test/util/fexp.go b/test/util/fexp/fexp.go
similarity index 99%
rename from test/util/fexp.go
rename to test/util/fexp/fexp.go
index 2e67d90..4aa40ea 100644
--- a/test/util/fexp.go
+++ b/test/util/fexp/fexp.go
@@ -1,5 +1,5 @@
-//go:build ignore
-// +build ignore
+//go:build !coverage
+// +build !coverage
 
 // Fetch an URL, and check if the response matches what we expect.
 //
diff --git a/test/util/generate_cert.go b/test/util/generate_cert/generate_cert.go
similarity index 99%
rename from test/util/generate_cert.go
rename to test/util/generate_cert/generate_cert.go
index f6372c4..1fe2249 100644
--- a/test/util/generate_cert.go
+++ b/test/util/generate_cert/generate_cert.go
@@ -2,8 +2,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-//go:build ignore
-// +build ignore
+//go:build !coverage
+// +build !coverage
 
 // Generate a self-signed X.509 certificate for a TLS server. Outputs to
 // 'cert.pem' and 'key.pem' and will overwrite existing files.
diff --git a/test/util/gocovcat.go b/test/util/gocovcat/gocovcat.go
old mode 100755
new mode 100644
similarity index 98%
rename from test/util/gocovcat.go
rename to test/util/gocovcat/gocovcat.go
index 4018912..23cee08
--- a/test/util/gocovcat.go
+++ b/test/util/gocovcat/gocovcat.go
@@ -2,8 +2,8 @@
 //
 // From: https://git.lukeshu.com/go/cmd/gocovcat/
 //
-//go:build ignore
-// +build ignore
+//go:build !coverage
+// +build !coverage
 
 // Copyright 2017 Luke Shumaker <lukeshu@parabola.nu>
 //
diff --git a/test/util/lib.sh b/test/util/lib.sh
index c949a5c..560de12 100644
--- a/test/util/lib.sh
+++ b/test/util/lib.sh
@@ -101,26 +101,29 @@ function chamuyero() {
 }
 
 function generate_cert() {
-	go run ${UTILDIR}/generate_cert.go "$@"
+	( cd ${UTILDIR}/generate_cert/; go build )
+	${UTILDIR}/generate_cert/generate_cert "$@"
 }
 
 function loadgen() {
-	go run ${UTILDIR}/loadgen.go "$@"
+	( cd ${UTILDIR}/loadgen/; go build )
+	${UTILDIR}/loadgen/loadgen "$@"
 }
 
 function conngen() {
-	go run ${UTILDIR}/conngen.go "$@"
+	( cd ${UTILDIR}/conngen/; go build )
+	${UTILDIR}/conngen/conngen "$@"
 }
 
 function minidns_bg() {
-	( cd ${UTILDIR}; go build minidns.go )
-	${UTILDIR}/minidns "$@" &
+	( cd ${UTILDIR}/minidns; go build )
+	${UTILDIR}/minidns/minidns "$@" &
 	MINIDNS=$!
 }
 
 function fexp() {
-	( cd ${UTILDIR}; go build fexp.go )
-	${UTILDIR}/fexp "$@"
+	( cd ${UTILDIR}/fexp/; go build )
+	${UTILDIR}/fexp/fexp "$@"
 }
 
 function timeout() {
diff --git a/test/util/loadgen.go b/test/util/loadgen/loadgen.go
similarity index 98%
rename from test/util/loadgen.go
rename to test/util/loadgen/loadgen.go
index ec7fb03..6ff98ec 100644
--- a/test/util/loadgen.go
+++ b/test/util/loadgen/loadgen.go
@@ -1,5 +1,5 @@
-//go:build ignore
-// +build ignore
+//go:build !coverage
+// +build !coverage
 
 // SMTP load generator, for testing purposes.
 package main
diff --git a/test/util/minidns.go b/test/util/minidns/minidns.go
similarity index 99%
rename from test/util/minidns.go
rename to test/util/minidns/minidns.go
index e2da6e0..4e1c818 100644
--- a/test/util/minidns.go
+++ b/test/util/minidns/minidns.go
@@ -1,5 +1,5 @@
-//go:build ignore
-// +build ignore
+//go:build !coverage
+// +build !coverage
 
 // minidns is a trivial DNS server used for testing.
 //