Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not work in table-driven tests #19

Closed
vankleefjim opened this issue Jun 8, 2022 · 0 comments
Closed

Does not work in table-driven tests #19

vankleefjim opened this issue Jun 8, 2022 · 0 comments

Comments

@vankleefjim
Copy link
Contributor

One standard pattern in go is to used table driven tests, see https://dave.cheney.net/2019/05/07/prefer-table-driven-tests

This linter does not work if os.Setenv is used in these tests.

Example:

func TestLintShouldFailButDoesnt(t *testing.T) {
	tests := map[string]struct {
		fooValue string
	}{
		"does something": {fooValue: "bar"},
	}

	for name, tc := range tests {
		t.Run(name, func(t *testing.T) {
			os.Setenv("foo", tc.fooValue)
		})
	}
}

I created this on my repo with the github-action version of the golang-ci linter:
vankleefjim/tenv-bug@10f12e4 with successful CI run
vankleefjim/tenv-bug@f01c689 with failing CI run, but only in the test that directly runs os.Setenv without a table-driven test.

vankleefjim added a commit to vankleefjim/tenv that referenced this issue Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant