From a0a6909272c900ee0a67a1ee0624638ef5fd3b46 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Tue, 5 Jul 2022 09:28:45 +0200 Subject: golangci-lint: Disable use of `os.Setenv()` and `os.Unsetenv()` in tests Disallow use of `os.Setenv()` and `os.Unsetenv()` in tests. Callers should instead use `testhelper.ModifyEnvironment()`. Adjust existing callers to do so. Note: the log tests cannot use the testhelper package due to a cyclic import and thus use `t.Setenv()` directly. --- .golangci.yml | 6 ++++++ 1 file changed, 6 insertions(+) (limited to '.golangci.yml') diff --git a/.golangci.yml b/.golangci.yml index 4ef4e7da7..db6ed2d7e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -58,6 +58,12 @@ linters-settings: # they're tested as expected. - ^context.Background$ - ^context.TODO$ + # Tests should not set the bare environment functions, but instead use + # `testhelper.ModifyEnvironment()`. This function has sanity checks to + # verify we don't use `t.Parallel()` when setting envvars by using the + # `t.Setenv()` helper. + - ^os.Setenv$ + - ^os.Unsetenv$ stylecheck: # ST1000 checks for missing package comments. We don't use these for most # packages, so let's disable this check. -- cgit v1.2.3