37 lines
686 B
Go
37 lines
686 B
Go
package test
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"crypto/rsa"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
)
|
|
|
|
func mustGeneratePrivateKey() *rsa.PrivateKey {
|
|
privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return privateKey
|
|
}
|
|
|
|
type HTTPClientMock struct {
|
|
handler http.Handler
|
|
recorder *httptest.ResponseRecorder
|
|
}
|
|
|
|
func (c *HTTPClientMock) Do(r *http.Request) (*http.Response, error) {
|
|
w := httptest.NewRecorder()
|
|
c.recorder = w
|
|
c.handler.ServeHTTP(w, r)
|
|
return w.Result(), nil
|
|
}
|
|
|
|
func (c *HTTPClientMock) Recorder() *httptest.ResponseRecorder {
|
|
return c.recorder
|
|
}
|
|
|
|
func NewHTTPClientMock(h http.Handler) *HTTPClientMock {
|
|
return &HTTPClientMock{h, nil}
|
|
}
|