steinfletcher / apitest

A simple and extensible behavioural testing library for Go. You can use api test to simplify REST API, HTTP handler and e2e tests.
https://apitest.dev
MIT License
795 stars 55 forks source link

Provide an ability to define a remote address for a test #117

Closed axispx closed 2 years ago

axispx commented 2 years ago

Is your feature request related to a problem? Please describe. I didn't find a way to set the RemoteAddr when running tests which breaks my code where I need to split host and port.

Describe the solution you'd like Provide a builder method that sets a custom address for the test.

Describe alternatives you've considered I use http.Request to set the remote address as a workaround.

steinfletcher commented 2 years ago

Hi @anarchyrucks. I am thinking the Intercept method might be a bit more convenient instead of defining a http.Request, e.g.

apitest.Handler(handler).
        Intercept(func(request *http.Request) {
            request.RemoteAddr = "..."
        }).
        Get("/message").
        Body(`{"message": "hi"}`).
        Header("Content-Type", "application/json").
        Expect(t).
        Status(http.StatusOK).
        End()

If you need to set RemoteAddr globally you could do it in your own builder method.

steinfletcher commented 2 years ago

Closing due to inactivity.