Skip to content

[Feature Request]: Support for HTTP Response  #115

@amir20

Description

@amir20

🚀 Feature Proposal

Hello, I have been using https://github.com/beme/abide and would like to move to a new, more maintained alternative. One of the features that is very helpful is to directly test again and http response like:

rr := httptest.NewRecorder()
handler.ServeHTTP(rr, req)
abide.AssertHTTPResponse(t, t.Name(), rr.Result()) // <--

This would be very helpful. Internally, I would expect go-snaps to dump the headers and body.

Motivation

Replace abide and make testing http easier.

Example

I would expect validators to also work. Currently, I have something this:

/* snapshot: Test_handler_streamEvents_happy */
HTTP/1.1 200 OK
Connection: close
Cache-Control: no-transform
Cache-Control: no-cache
Connection: keep-alive

event: container-event
data: {"name":"start","host":"localhost","actorId":"1234","time":"0001-01-01T00:00:00Z"}

However, time can change. I would imagine this wouldn't work as-is since this is not valid JSON. But if there was a way to use regular expression that would be even better. I currently do this:

rr := httptest.NewRecorder()
handler.ServeHTTP(rr, req)
reader := strings.NewReader(regexp.MustCompile(`"time":"[^"]*"`).ReplaceAllString(rr.Body.String(), `"time":"<removed>"`))
abide.AssertReader(t, t.Name(), reader)

I would prefer to just have the snapshot library handle this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions