-
Notifications
You must be signed in to change notification settings - Fork 0
/
testing.go
30 lines (25 loc) · 989 Bytes
/
testing.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package akumu
import (
"net/http"
"net/http/httptest"
)
// RecordServer records what a given [http.Server] would give as a reponse to a [http.Request].
//
// The response is recorded using a [httptest.ResponseRecorder].
func RecordServer(server *http.Server, request *http.Request) *httptest.ResponseRecorder {
return RecordHandler(server.Handler, request)
}
// Record records what a given [Handler] would give as a reponse to a [http.Request].
//
// The response is recorded using a [httptest.ResponseRecorder].
func Record(handler Handler, request *http.Request) *httptest.ResponseRecorder {
return RecordHandler(handler, request)
}
// Record records what a given [http.Handler] would give as a reponse to a [http.Request].
//
// The response is recorded using a [httptest.ResponseRecorder].
func RecordHandler(handler http.Handler, request *http.Request) *httptest.ResponseRecorder {
recorder := httptest.NewRecorder()
handler.ServeHTTP(recorder, request)
return recorder
}