Skip to content

test: put the Docker acceptance bootstrap behind an acc build tag - #171

Open
fdcastel wants to merge 1 commit into
alexklibisz:mainfrom
fdcastel:fix/f03-testcontainers-build-tag
Open

test: put the Docker acceptance bootstrap behind an acc build tag#171
fdcastel wants to merge 1 commit into
alexklibisz:mainfrom
fdcastel:fix/f03-testcontainers-build-tag

Conversation

@fdcastel

Copy link
Copy Markdown
Contributor

Follows up on the testcontainers point from #159, which you said seemed worth fixing.

What was happening

testcontainers-go/modules/compose is imported only by TestMain in provider_test.go, but nothing gated that import — so the Docker/containerd/compose-go tree got compiled into the test binary on every go test run, including plain unit runs that never start a container.

Measured with go list -deps -test ./internal/provider/:

docker/containerd/compose-go packages
before 138
after (untagged) 0
after (-tags=acc) 138

What changed

  • The Docker bootstrap (runDockerTests, waitForAPI) moves to provider_docker_acc_test.go behind //go:build acc.
  • provider_docker_stub_test.go (//go:build !acc) provides a runDockerTests that prints how to enable the tag.
  • TestMain stays untagged, so target dispatch and unit runs behave exactly as before.
  • Taskfile.yml: test:acc gains -tags=acc. test:acc:hardware deliberately does not — it talks to an existing controller, so leaving the tag off keeps the Docker tree out of that build too.
  • vet gains a second tagged pass, otherwise the acc file rots silently until someone runs test:acc.

CI needs no change — ci-local.yaml goes through task test:unit / task test:acc.

One thing this does not do

Since #159 raised go.mod specifically, I want to be straight about this: it does not move the dependency out of the main require block. I tried it and checked rather than assuming — go mod tidy evaluates all build configurations, so a tagged test import is still a direct requirement and tidy leaves it exactly where it is.

Demoting it for real would mean putting the bootstrap in a separate Go module, which feels disproportionate for what it buys. The part that was actually costing something — compiling 138 packages to run unit tests — is gone, and consumers importing the provider package never had compose in their build anyway, since it was always test-only.

Happy to go the separate-module route instead if you'd rather have the go.mod line gone; just didn't want to make that call unilaterally.

Side effect: it should make Dependabot's compose bumps (#169 currently) cheaper to reason about, since the dependency is now visibly test-only in the source tree.

Written with Claude Code, reviewed by me.

testcontainers-go/modules/compose is imported only by provider_test.go's
TestMain, but nothing gated that import, so the Docker/containerd/
compose-go tree was compiled into the test binary for every `go test`
run -- including plain unit runs that never start a container.

Measured on this package with `go list -deps -test`:

  before   138 docker/containerd/compose-go packages
  after      0 (untagged); the 138 move behind -tags=acc

The bootstrap moves to provider_docker_acc_test.go (//go:build acc) with
a stub in provider_docker_stub_test.go (//go:build !acc) that explains
how to enable it. TestMain stays untagged, so target dispatch and unit
runs are unchanged.

Taskfile: test:acc gains -tags=acc. test:acc:hardware deliberately does
not -- it talks to an existing controller, so leaving the tag off keeps
the Docker tree out of that build too. vet gains a second tagged pass so
the acc file cannot rot silently.

One thing this does NOT do, since alexklibisz#159 raised it specifically: it does
not move the dependency out of go.mod's main require block. `go mod tidy`
evaluates all build configurations, so a tagged test import is still a
direct requirement -- I verified this rather than assuming it. Demoting
it for real would need the bootstrap in a separate module, which seems
disproportionate. The compile-time cost is the part that was actually
hurting, and that part is gone.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant