Skip to content

Commit 52a3ba5

Browse files
committed
Don't allow testsignal to pick up non-stdlib dependencies
This one's aimed at producing a more permanent structural fix for #1342 by keeping an eye out for the same problematic condition using the depguard lint. As a summary of the problem corrected by #1342: * We use the `testsignal` package in all kinds of non-test code, so packages including River always build against it. * `testsignal` was importing `riversharedtest`, which imports Testify, Goleak, YAML (through Testify). * This was causing all packages built against River to pick up an extra ~10 kB worth of dependencies in their production builds, which is bad. Here, add some new rules for depguard: * Don't allow test packages like Goleak or Testify to be imported by any non-test Go files. We make an exception for internal test support packages like `riverdbtest` and `riverdrivertest`. * Don't allow `testsignal` to have any dependencies beyond stdlib and `testutil`. * Don't allow `testutil` to have any non-stdlib dependencies. This rule is so that `testsignal` doesn't pick up unexpected dependencies transitively through `testutil`.
1 parent 60435dc commit 52a3ba5

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

.golangci.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,28 @@ linters:
5252
- desc: Don't use `riverinternaltest` package outside of test environments.
5353
pkg: github.com/riverqueue/river/internal/riverinternaltest
5454

55+
# The next two blocks have the same intent: don't allow testsignal,
56+
# which is used in non-test code, to have non-stdlib dependencies.
57+
# Previously, we ran into a problem where it was accidentally importing
58+
# riversharedtest, which was importing Goleak, Testify, YAML (through
59+
# Testify), etc. which added 10 kB overhead to all binaries built with
60+
# River. testsignal does use testutil, so the second block makes sure
61+
# that testutil has no stdlib dependencies so that testsignal doesn't
62+
# pick one up transitively.
63+
testsignal-no-test-deps:
64+
files:
65+
- "**/testsignal/*.go"
66+
- "!$test"
67+
allow:
68+
- $gostd
69+
- "github.com/riverqueue/river/rivershared/util/testutil$"
70+
testutil-no-test-deps:
71+
files:
72+
- "**/util/testutil/*.go"
73+
- "!$test"
74+
allow:
75+
- $gostd
76+
5577
forbidigo:
5678
forbid:
5779
- msg: Use `require` variants instead.

0 commit comments

Comments
 (0)