Skip to content

Do not link test dependencies into main binary#108

Draft
majst01 wants to merge 1 commit intomainfrom
seperate-tests-from-binary
Draft

Do not link test dependencies into main binary#108
majst01 wants to merge 1 commit intomainfrom
seperate-tests-from-binary

Conversation

@majst01
Copy link
Contributor

@majst01 majst01 commented Dec 28, 2025

Description

Imports in go files which are not named according to the go test naming convention _test.go will be included in the main binary. OTOH exported funcs in _test.go files can not be imported in other packages.

To circumvent this a build flag is introduced, which separates test code from production code.

This saves ~1Mb from the resulting binary and the testcontainers dependency can no longer be found like so:

$ strings bin/server | grep testcontainers

dep     github.com/testcontainers/testcontainers-go     v0.40.0 h1:pSdJYLOVgLE8YdUY2FHQ1Fxu+aMnb6JfVz1mxk7OeMU=
dep     github.com/testcontainers/testcontainers-go/modules/postgres    v0.38.0 h1:KFdx9A0yF94K70T6ibSuvgkQQeX1xKlZVF3hEagXEtY=
dep     github.com/testcontainers/testcontainers-go/modules/valkey      v0.40.0 h1:V0zwJVnN8fOT++ySwo/P5cwd3pmXI7O4VdA7kQ+5OiM=
github.com/testcontainers/testcontainers-go/internal/config.init
github.com/testcontainers/testcontainers-go/internal/core.init
github.com/testcontainers/testcontainers-go/internal/core.init.0
github.com/testcontainers/testcontainers-go/internal/core.init.1
github.com/testcontainers/testcontainers-go/log.init.0
github.com/testcontainers/testcontainers-go/log.noopLogger.Printf
github.com/testcontainers/testcontainers-go/log.(*noopLogger).Printf
github.com/testcontainers/testcontainers-go/wait.init
github.com/testcontainers/testcontainers-go.init
/home/stefan/go/pkg/mod/github.com/testcontainers/testcontainers-go@v0.40.0/internal/config/config.go
/home/stefan/go/pkg/mod/github.com/testcontainers/testcontainers-go@v0.40.0/internal/core/docker_host.go
/home/stefan/go/pkg/mod/github.com/testcontainers/testcontainers-go@v0.40.0/internal/core/docker_socket.go
/home/stefan/go/pkg/mod/github.com/testcontainers/testcontainers-go@v0.40.0/internal/core/images.go
/home/stefan/go/pkg/mod/github.com/testcontainers/testcontainers-go@v0.40.0/internal/core/bootstrap.go
/home/stefan/go/pkg/mod/github.com/testcontainers/testcontainers-go@v0.40.0/log/logger.go
/home/stefan/go/pkg/mod/github.com/testcontainers/testcontainers-go@v0.40.0/wait/walk.go
/home/stefan/go/pkg/mod/github.com/testcontainers/testcontainers-go@v0.40.0/docker.go
/home/stefan/go/pkg/mod/github.com/testcontainers/testcontainers-go@v0.40.0/docker_mounts.go
/home/stefan/go/pkg/mod/github.com/testcontainers/testcontainers-go@v0.40.0/docker_auth.go
/home/stefan/go/pkg/mod/github.com/testcontainers/testcontainers-go@v0.40.0/port_forwarding.go
/home/stefan/go/pkg/mod/github.com/testcontainers/testcontainers-go@v0.40.0/testing.go
dep     github.com/testcontainers/testcontainers-go     v0.40.0 h1:pSdJYLOVgLE8YdUY2FHQ1Fxu+aMnb6JfVz1mxk7OeMU=
dep     github.com/testcontainers/testcontainers-go/modules/postgres    v0.38.0 h1:KFdx9A0yF94K70T6ibSuvgkQQeX1xKlZVF3hEagXEtY=
dep     github.com/testcontainers/testcontainers-go/modules/valkey      v0.40.0 h1:V0zwJVnN8fOT++ySwo/P5cwd3pmXI7O4VdA7kQ+5OiM=

@metal-robot metal-robot bot added the area: control-plane Affects the metal-stack control-plane area. label Dec 28, 2025
@codecov
Copy link

codecov bot commented Dec 28, 2025

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 69.74%. Comparing base (d05d29f) to head (40e477e).

Files with missing lines Patch % Lines
cmd/server/serve-cmd.go 0.00% 1 Missing ⚠️

❌ Your patch check has failed because the patch coverage (0.00%) is below the target coverage (25.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #108   +/-   ##
=======================================
  Coverage   69.74%   69.74%           
=======================================
  Files         130      130           
  Lines       10071    10071           
=======================================
  Hits         7024     7024           
  Misses       2329     2329           
  Partials      718      718           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: control-plane Affects the metal-stack control-plane area.

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant