Documentation
¶
Index ¶
- func NewMockResponse(body string, statusCode int) *http.Response
- type HTTPClient
- func (m HTTPClient) AddJSONResponse(url string, json string, statusCode int)
- func (m HTTPClient) Do(req *http.Request) (*http.Response, error)
- func (m HTTPClient) Download(_ string, _ io.Writer, _ func(size int64) *pb.ProgressBar) error
- func (m HTTPClient) Get(_ string) (*http.Response, error)
- func (m HTTPClient) GetBinaryFile(_ string) (*http.Response, error)
- func (m HTTPClient) GetClient() *http.Client
- func (m HTTPClient) GetJSON(url string) (*http.Response, error)
- func (m HTTPClient) GetText(_ string) (*http.Response, error)
- func (m HTTPClient) Reset()
- func (m HTTPClient) ResetJSONResponsesForURL(url string)
- func (m HTTPClient) RoundTrip(_ *http.Request) (*http.Response, error)
- type JSONResponse
- type RequestData
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type HTTPClient ¶
type HTTPClient struct { Requests []RequestData BaseURL string DoFunc func(req *http.Request) (*http.Response, error) Responses map[string][]JSONResponse download.ClientContract }
func NewMockHTTPClient ¶
func NewMockHTTPClient() HTTPClient
func (HTTPClient) AddJSONResponse ¶
func (m HTTPClient) AddJSONResponse(url string, json string, statusCode int)
func (HTTPClient) Download ¶
func (m HTTPClient) Download(_ string, _ io.Writer, _ func(size int64) *pb.ProgressBar) error
func (HTTPClient) GetBinaryFile ¶
func (m HTTPClient) GetBinaryFile(_ string) (*http.Response, error)
func (HTTPClient) GetClient ¶
func (m HTTPClient) GetClient() *http.Client
func (HTTPClient) Reset ¶
func (m HTTPClient) Reset()
func (HTTPClient) ResetJSONResponsesForURL ¶
func (m HTTPClient) ResetJSONResponsesForURL(url string)
type JSONResponse ¶
type RequestData ¶
* * // basic usage example (in some_file_test.go):
client = mockhttp.NewMockHTTPClient()
client.DoFunc = func(req *http.Request) (*http.Response, error) { // }
client.AddJSONResponse("https://api.github.com/repos/testRepo/releases/v1.0.0", `{"tag_name": "v1.0.0", "prerelease": false, "assets": [{"name": "exampleTool.tar.gz", "browser_download_url": "https://github.com/example/repo/tarball/v1.0.0/exampleTool.tar.gz"}], "created_at": "2020-01-01T00:00:00Z"}`, 200)
Click to show internal directories.
Click to hide internal directories.