HTTPDo makes an HTTP request and returns a response
(t *testing.T, req *http.Request)
| 114 | |
| 115 | // HTTPDo makes an HTTP request and returns a response |
| 116 | func HTTPDo(t *testing.T, req *http.Request) *http.Response { |
| 117 | hc := http.Client{ |
| 118 | // Do not follow redirects. |
| 119 | // e.g. /logout redirects to a page but we'd like to test the redirect |
| 120 | // itself, not what happens after the redirect |
| 121 | CheckRedirect: func(req *http.Request, via []*http.Request) error { |
| 122 | return http.ErrUseLastResponse |
| 123 | }, |
| 124 | } |
| 125 | |
| 126 | res, err := hc.Do(req) |
| 127 | if err != nil { |
| 128 | t.Fatal(errors.Wrap(err, "performing http request")) |
| 129 | } |
| 130 | |
| 131 | return res |
| 132 | } |
| 133 | |
| 134 | // SetReqAuthHeader sets the authorization header in the given request for the given user with a specific DB |
| 135 | func SetReqAuthHeader(t *testing.T, db *gorm.DB, req *http.Request, user database.User) { |
no outgoing calls