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

Assertion: http.DefaultTransport.(*http.Transport) ... makes mocking impossible #94

Open
sylnsr opened this issue May 17, 2024 · 1 comment

Comments

@sylnsr
Copy link

sylnsr commented May 17, 2024

Regarding

httpTransport := http.DefaultTransport.(*http.Transport)

I was using github.com/jarcoal/httpmock with the old (now deprecated) API client our app. We have a test suite must run mocking tests before running integration tests as the next step. Upon upgrading to the this new OpenAPI client, I discovered that at this point, we're running into a panic caused by that line of code:

interface conversion: net/http.RoundTripper is *github.com/jarcoal/http.MockTransport, 
not *net/http.Transport

It seems like an overly opinionated or short sighted requirement, that the transport MUST be *net/http.Transport. For one thing this breaks mocking. Looking at it another way, whats the point of allowing the user to set TransportConfig if down the line you're making an assertion that its a specific thing?

@sylnsr sylnsr changed the title Assertion makes mocking impossible Assertion: http.DefaultTransport.(*http.Transport) ... makes mocking impossible May 17, 2024
@sylnsr
Copy link
Author

sylnsr commented May 17, 2024

On a side note, for any one else running into this, the work around for the issue with that particular mocking framework is not to use httpmock.Activate() to activate the framework, but instead to use httpmock.ActivateNonDefault(&http.Client{}). (Correction, there is no solution)

However, that should not detract from the larger issue .. I still think the issue for taking a custom TransportConfig, then asserting its something specific, is misleading.

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