A Dagger module that provides comprehensive Go testing capabilities with full control over test execution, build options, and test configurations.
Through the Dagger CLI, you can configure:
- ⚙️
version
: Go version to use (e.g., "1.22.5"). Defaults tolatest
- ⚙️
image
: Custom Go image. Defaults togolang:alpine
- ⚙️
envVarsFromHost
: Environment variables to pass from host - ⚙️
ctr
: Base container for customization
Feature | Description | Example |
---|---|---|
Test Execution | Run Go tests with comprehensive options | dagger call test --source=. --cover=true |
Build Configuration | Control build flags and options | dagger call test --race=true --buildTags="integration" |
Test Filtering | Filter and control test execution | dagger call test --run="TestSpecific" --short=true |
Profiling | CPU, memory, and block profiling | dagger call test --cpuprofile="cpu.prof" |
Benchmarking | Run and configure benchmarks | dagger call test --benchmark="." --benchmem=true |
dagger call test --source=. --enableDefaultOptions=true
dagger call test \
--source=. \
--cover=true \
--coverprofile="coverage.out" \
--cpuprofile="cpu.prof" \
--verbose=true
dagger call test \
--source=. \
--race=true \
--buildTags="integration" \
--ldflags="-X main.version=test"
dagger call test \
--source=. \
--benchmark="." \
--benchmem=true \
--benchtime="1s" \
--testCount=3
Option | Description |
---|---|
race |
Enable race detection |
msan |
Enable memory sanitizer |
asan |
Enable address sanitizer |
buildTags |
Specify build constraints |
ldflags |
Set linker flags |
gcflags |
Set Go compiler flags |
asmflags |
Set assembler flags |
trimpath |
Remove file system paths |
buildMode |
Set build mode |
compiler |
Specify compiler |
mod |
Set module mode |
Option | Description |
---|---|
benchmark |
Run benchmarks matching regexp |
benchmem |
Report memory allocations |
benchtime |
Run time for benchmarks |
cover |
Enable coverage analysis |
coverprofile |
Write coverage profile |
cpuprofile |
Write CPU profile |
testCount |
Run tests multiple times |
failfast |
Stop on first failure |
enableJsonOutput |
Enable JSON output |
parallel |
Set parallel test count |
run |
Run tests matching pattern |
short |
Run in short mode |
timeout |
Set test timeout |
verbose |
Enable verbose output |
The module supports:
- Setting environment variables via
envVars
- Passing secrets securely via
secrets
- Inheriting environment variables from host via
envVarsFromHost
Example:
dagger call test \
--source=. \
--envVars='["GO_ENV=test", "DEBUG=true"]' \
--secrets='["MY_SECRET"]'
Run the test suite:
just test gotest
Development commands:
# Initialize pre-commit hooks
just run-hooks
# Run linting
just lintall gotest
# Run tests
just test gotest
# Run CI pipeline locally
just ci gotest
Executes Go tests with full configuration options:
RunTest(source *dagger.Directory, packages []string, envVars []string, secrets []*dagger.Secret, ...) (*dagger.Container, error)
Executes tests and returns command output:
RunTestCmd(source *dagger.Directory, packages []string, envVars []string, secrets []*dagger.Secret, ...) (string, error)
For detailed API documentation and more examples, see the Dagger documentation.