sivchari / tenv

tenv detects environment variable not using t.Setenv
MIT License
19 stars 6 forks source link

Support Test Suites #23

Open mvrahden opened 1 year ago

mvrahden commented 1 year ago

I believe the linter fails on detecting os.Setenv calls in more advanced scenarios. Here's one:

func TestModelSuite(t *testing.T) {
    suite.Run(t, &MySuite{})
}

func (s *MySuite) SetupTest() {
    // ... some setup code

    s.NoError(os.Setenv("AWS_XRAY_SDK_DISABLED", "true")) // want "some linting error to detect this"

    // ... more setup code
}

FIY: The test suite here is from stretchr/testify should that help you pinpoint the issue.

The solution should look like this:

    s.T().Setenv("AWS_XRAY_SDK_DISABLED", "true")

As you can see, T() will return the *testing.T instance. So your linter should be sensible to this case as well :)

And just for clarity: I have the configuration parameter all set to true

sivchari commented 1 month ago

Are you still annoyed with this problem? If so, I'll take the time to resolve this issue.