Advanced Configuration
This page covers advanced configuration options for complex workflows.
Integration Test Coverage
Section titled “Integration Test Coverage”For projects with separate integration tests, coverctl can build test binaries and run them with GOCOVERDIR:
integration: enabled: true packages: ["./internal/integration/..."] run_args: ["-test.run", "TestIntegration"] cover_dir: ".cover/integration" profile: ".cover/integration.out"Options
Section titled “Options”| Field | Description | Default |
|---|---|---|
enabled | Enable integration test coverage | false |
packages | Package patterns to build | ["./..."] |
run_args | Arguments passed to test binary | [] |
cover_dir | Directory for raw coverage data | .cover/integration |
profile | Output profile path | .cover/integration.out |
How It Works
Section titled “How It Works”- Builds test binaries with
go test -c -covermode=atomic - Runs binaries with
GOCOVERDIRenvironment variable - Converts raw data to profile with
go tool covdata - Merges with unit test coverage
Example
Section titled “Example”integration: enabled: true packages: - "./test/integration/..." - "./test/e2e/..." run_args: - "-test.run" - "TestIntegration" - "-test.v" cover_dir: ".cover/integration-data" profile: ".cover/integration.out"Diff-Based Coverage
Section titled “Diff-Based Coverage”Only check coverage for files changed since a git ref:
diff: enabled: true base: origin/mainOptions
Section titled “Options”| Field | Description | Default |
|---|---|---|
enabled | Enable diff-based filtering | false |
base | Git ref to compare against | origin/main |
Use Cases
Section titled “Use Cases”- Pull requests: Only check files in the PR
- Feature branches: Focus on changed code
- Incremental improvement: Don’t fail on legacy code
CLI Override
Section titled “CLI Override”# Override config diff settingcoverctl report --diff origin/developExample Workflow
Section titled “Example Workflow”diff: enabled: false # Disabled by default base: origin/main
# CI for PRs enables diff mode# coverctl check --diff origin/mainProfile Merging
Section titled “Profile Merging”Combine multiple coverage profiles into a single analysis:
merge: profiles: - ".cover/unit.out" - ".cover/integration.out" - ".cover/e2e.out"CLI Merging
Section titled “CLI Merging”coverctl report \ -p unit.out \ --merge integration.out \ --merge e2e.outMerge Behavior
Section titled “Merge Behavior”- Profiles are merged by file and line
- Higher coverage wins (if both profiles cover a line, it’s counted as covered)
- All profiles must use the same coverage mode (
atomicorset)
Code Annotations
Section titled “Code Annotations”Enable in-code annotations to override coverage behavior:
annotations: enabled: trueIgnore Annotation
Section titled “Ignore Annotation”Exclude a file from coverage:
// coverctl:ignorepackage generated
// This entire file is excluded from coverage analysisDomain Annotation
Section titled “Domain Annotation”Assign a file to a specific domain:
// coverctl:domain=criticalpackage validator
// This file is assigned to the "critical" domain// regardless of its pathAnnotation Placement
Section titled “Annotation Placement”Annotations must be at the package level (before the package declaration):
// coverctl:ignore// coverctl:domain=corepackage mypackage
import "fmt"Complete Advanced Example
Section titled “Complete Advanced Example”version: 1
policy: default: min: 75 domains: - name: core match: ["./internal/core/..."] min: 85 - name: api match: ["./internal/api/..."] min: 80
files: - match: ["internal/core/payments/*.go"] min: 95
exclude: - "**/generated/**" - "**/mocks/**"
# Diff-based coverage for PRsdiff: enabled: false base: origin/main
# Integration test coverageintegration: enabled: true packages: ["./test/integration/..."] run_args: ["-test.v"] cover_dir: ".cover/integration" profile: ".cover/integration.out"
# Merge unit and integration profilesmerge: profiles: - ".cover/integration.out"
# Enable code annotationsannotations: enabled: trueEnvironment-Specific Configs
Section titled “Environment-Specific Configs”Use different configs for different environments:
# Development: lenientcoverctl check -c .coverctl.dev.yaml
# CI: strictcoverctl check -c .coverctl.ci.yamlDevelopment Config
Section titled “Development Config”version: 1policy: default: min: 50 domains: - name: core match: ["./internal/core/..."] min: 70CI Config
Section titled “CI Config”version: 1policy: default: min: 75 domains: - name: core match: ["./internal/core/..."] min: 85diff: enabled: true base: origin/mainSee Also
Section titled “See Also”- CI Integration - GitHub Actions setup
- Build Flags - Test customization