Skip to content

chore: Move package-local mock files to _test.go so testify stays out of the binary #19374

Description

@skartikey

Follow-up to #19315.

testify is still linked into the shipped binary, because these files are compiled into the regular (non-test) build:

That pulls testify/assert, testify/mock, objx, go-spew and go-difflib into the binary, all of which are still listed in docs/LICENSE_OF_DEPENDENCIES.md, and their init() functions run on every start.

The runtime cost is nothing like testcontainers-go was (mock compiles one regexp, assert does a handful of reflect calls), so this is about layering rather than startup time.

Why these four are grouped

Every symbol each of these files exports is only referenced from inside its own package, so renaming each one to *_test.go should be sufficient with no restructuring. They can be done one plugin at a time.

The fifth leaker, plugins/common/psutil/mock_ps.go, cannot be fixed this way and is tracked separately.

Related

#19373 proposes a CI guard so this class fails the build instead of being found by accident.

Verify

go list -deps ./cmd/telegraf | grep stretchr/testify

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions