Skip to content

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

Open
@sylnsr

Description

@sylnsr

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions