Skip to content

Does not work in table-driven testsΒ #19

@vankleefjim

Description

@vankleefjim

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions