sivchari / tenv

tenv detects environment variable not using t.Setenv
MIT License
23 stars 7 forks source link

Support Test Suites #23

Closed mvrahden closed 1 week ago

mvrahden commented 2 years 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 5 months ago

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

sivchari commented 1 week ago

Close it since the activity is no longer available.