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:
11
.gitignore
vendored
11
.gitignore
vendored
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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" \
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//go:build ignore
|
||||
// +build ignore
|
||||
//go:build !coverage
|
||||
// +build !coverage
|
||||
|
||||
// SMTP connection generator, for testing purposes.
|
||||
package main
|
||||
@@ -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
|
||||
@@ -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.
|
||||
//
|
||||
@@ -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.
|
||||
4
test/util/gocovcat.go → test/util/gocovcat/gocovcat.go
Executable file → Normal file
4
test/util/gocovcat.go → test/util/gocovcat/gocovcat.go
Executable file → Normal file
@@ -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>
|
||||
//
|
||||
@@ -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() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//go:build ignore
|
||||
// +build ignore
|
||||
//go:build !coverage
|
||||
// +build !coverage
|
||||
|
||||
// SMTP load generator, for testing purposes.
|
||||
package main
|
||||
@@ -1,5 +1,5 @@
|
||||
//go:build ignore
|
||||
// +build ignore
|
||||
//go:build !coverage
|
||||
// +build !coverage
|
||||
|
||||
// minidns is a trivial DNS server used for testing.
|
||||
//
|
||||
Reference in New Issue
Block a user