Skip to content

chore: Make the psutil mock available to tests without shipping it in the binary #19375

Closed

Description

@skartikey

Follow-up to #19315, and the one remaining testify leaker that is not a simple file rename.

plugins/common/psutil/mock_ps.go is a non-test file, so it is compiled into the shipped binary and brings testify with it.

It cannot just be renamed to *_test.go, because the symbols it exports (MockPS, MockPSDisk, MockDiskUsage) are used by tests in eight other packages:

  • plugins/inputs/conntrack
  • plugins/inputs/disk
  • plugins/inputs/diskio
  • plugins/inputs/mem
  • plugins/inputs/net
  • plugins/inputs/netstat
  • plugins/inputs/swap

A _test.go file is not importable across package boundaries, so this needs one of:

  1. Move the mock into its own package, for example plugins/common/psutil/psutiltest, and have the consumers import that. The mock stays in the module but is no longer reachable from ./cmd/telegraf, which is what matters here. Smallest diff.
  2. Give each consumer its own local mock. Removes the shared dependency but duplicates it eight times.

Option 1 looks right, but it touches eight test files, so worth agreeing on before someone writes it.

Related

testutil/plugin_input/plugin.go is the same shape waiting to happen: a non-test file importing testutil. It is harmless only for as long as nothing reachable from the binary imports it.

#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

Activity

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

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