1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-17 14:37:02 +00:00

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.
This commit is contained in:
Alberto Bertogli
2022-08-27 18:33:33 +01:00
parent 567ad35122
commit 21e8d50df6
11 changed files with 37 additions and 27 deletions

11
.gitignore vendored
View File

@@ -17,8 +17,15 @@ cmd/chasquid-util/chasquid-util
cmd/smtp-check/smtp-check cmd/smtp-check/smtp-check
cmd/mda-lmtp/mda-lmtp cmd/mda-lmtp/mda-lmtp
cmd/dovecot-auth-cli/dovecot-auth-cli 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. # Test binary, generated during coverage tests.
chasquid.test chasquid.test

View File

@@ -60,7 +60,7 @@ ENV GOPATH=
RUN go get -v ${GO_GET_ARGS} ./... && go mod download RUN go get -v ${GO_GET_ARGS} ./... && go mod download
# Build the minidns server, which will be run from within the entrypoint. # 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 USER root
# Custom entry point, which uses our own DNS server. # Custom entry point, which uses our own DNS server.

View File

@@ -27,7 +27,7 @@ export COVER_DIR="$PWD/.coverage"
# the single-binary tests to fail: cross-package expvars confuse the expvarom # 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 # tests, which don't expect any expvars to exists besides the one registered
# in the tests themselves. # 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" OUT_FILE="$COVER_DIR/pkg-`echo $pkg | sed s+/+_+g`.out"
go test -tags coverage \ go test -tags coverage \
-covermode=count \ -covermode=count \
@@ -45,14 +45,14 @@ setsid -w ./cmd/dovecot-auth-cli/test.sh
# Merge all coverage output into a single file. # Merge all coverage output into a single file.
# Ignore protocol buffer-generated files, as they are not relevant. # 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:" \ | grep -v ".pb.go:" \
> .coverage/all.out > .coverage/all.out
# Generate reports based on the merged output. # 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 -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 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 \ -input="$COVER_DIR/all.out" -strip=3 \
-output="$COVER_DIR/coverage.html" \ -output="$COVER_DIR/coverage.html" \
-title="chasquid coverage report" \ -title="chasquid coverage report" \

View File

@@ -1,5 +1,5 @@
//go:build ignore //go:build !coverage
// +build ignore // +build !coverage
// SMTP connection generator, for testing purposes. // SMTP connection generator, for testing purposes.
package main package main

View File

@@ -1,5 +1,5 @@
//go:build ignore //go:build !coverage
// +build ignore // +build !coverage
// Generate an HTML visualization of a Go coverage profile. // Generate an HTML visualization of a Go coverage profile.
// Serves a similar purpose to "go tool cover -html", but has a different // Serves a similar purpose to "go tool cover -html", but has a different

View File

@@ -1,5 +1,5 @@
//go:build ignore //go:build !coverage
// +build ignore // +build !coverage
// Fetch an URL, and check if the response matches what we expect. // Fetch an URL, and check if the response matches what we expect.
// //

View File

@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
//go:build ignore //go:build !coverage
// +build ignore // +build !coverage
// Generate a self-signed X.509 certificate for a TLS server. Outputs to // Generate a self-signed X.509 certificate for a TLS server. Outputs to
// 'cert.pem' and 'key.pem' and will overwrite existing files. // 'cert.pem' and 'key.pem' and will overwrite existing files.

View File

@@ -2,8 +2,8 @@
// //
// From: https://git.lukeshu.com/go/cmd/gocovcat/ // From: https://git.lukeshu.com/go/cmd/gocovcat/
// //
//go:build ignore //go:build !coverage
// +build ignore // +build !coverage
// Copyright 2017 Luke Shumaker <lukeshu@parabola.nu> // Copyright 2017 Luke Shumaker <lukeshu@parabola.nu>
// //

View File

@@ -101,26 +101,29 @@ function chamuyero() {
} }
function generate_cert() { function generate_cert() {
go run ${UTILDIR}/generate_cert.go "$@" ( cd ${UTILDIR}/generate_cert/; go build )
${UTILDIR}/generate_cert/generate_cert "$@"
} }
function loadgen() { function loadgen() {
go run ${UTILDIR}/loadgen.go "$@" ( cd ${UTILDIR}/loadgen/; go build )
${UTILDIR}/loadgen/loadgen "$@"
} }
function conngen() { function conngen() {
go run ${UTILDIR}/conngen.go "$@" ( cd ${UTILDIR}/conngen/; go build )
${UTILDIR}/conngen/conngen "$@"
} }
function minidns_bg() { function minidns_bg() {
( cd ${UTILDIR}; go build minidns.go ) ( cd ${UTILDIR}/minidns; go build )
${UTILDIR}/minidns "$@" & ${UTILDIR}/minidns/minidns "$@" &
MINIDNS=$! MINIDNS=$!
} }
function fexp() { function fexp() {
( cd ${UTILDIR}; go build fexp.go ) ( cd ${UTILDIR}/fexp/; go build )
${UTILDIR}/fexp "$@" ${UTILDIR}/fexp/fexp "$@"
} }
function timeout() { function timeout() {

View File

@@ -1,5 +1,5 @@
//go:build ignore //go:build !coverage
// +build ignore // +build !coverage
// SMTP load generator, for testing purposes. // SMTP load generator, for testing purposes.
package main package main

View File

@@ -1,5 +1,5 @@
//go:build ignore //go:build !coverage
// +build ignore // +build !coverage
// minidns is a trivial DNS server used for testing. // minidns is a trivial DNS server used for testing.
// //