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

Ignore requests in tests #6

Open
cloudlena opened this issue Jul 4, 2020 · 5 comments
Open

Ignore requests in tests #6

cloudlena opened this issue Jul 4, 2020 · 5 comments
Labels
enhancement New feature or request

Comments

@cloudlena
Copy link

cloudlena commented Jul 4, 2020

As described in the docs, http.NewRequest uses the context.Background context which is supposed to be used in tests according to the docs. Therefore, it is cleaner to use http.NewContext in tests where we make HTTP requests against test servers.

Therefore, I think the linter should allow the usage of http.NewRequest, http.Get, http.Header and all similar functions in tests because it's the recommended way and provides much simpler code than having to explicitly use http.NewRequestWithContext with context.Background each time.

@sonatard sonatard added the enhancement New feature or request label Jul 8, 2020
@sonatard
Copy link
Owner

sonatard commented Jul 8, 2020

Thank you for opening your issue! I'll fix it.

@sonatard
Copy link
Owner

sonatard commented Jul 8, 2020

@cloudlena
Copy link
Author

Thanks for the hint. I actually do want to lint my test files. Just not for the usage of the context :) For now, I just excluded noctx in .golangci.yml and will activate it again as soon as this issue is fixed.

@sonatard
Copy link
Owner

sonatard commented Jul 8, 2020

I understand your situation.

Can you try again golangci-lint with following .golangci.yml ?

issues:
  exclude-rules:
    - path: _test\.go
      linters:
        - noctx

@cloudlena
Copy link
Author

Thanks, @sonatard. That's a good temporary workaround!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants