-
-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Labels
enhancementNew feature or requestNew feature or request
Description
🚀 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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request