mockhttp

package
v0.0.0-...-5f25c38 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMockResponse

func NewMockResponse(body string, statusCode int) *http.Response

Utility function to create a mock HTTP response

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) Do

func (m HTTPClient) Do(req *http.Request) (*http.Response, error)

func (HTTPClient) Download

func (m HTTPClient) Download(_ string, _ io.Writer, _ func(size int64) *pb.ProgressBar) error

func (HTTPClient) Get

func (m HTTPClient) Get(_ string) (*http.Response, error)

func (HTTPClient) GetBinaryFile

func (m HTTPClient) GetBinaryFile(_ string) (*http.Response, error)

func (HTTPClient) GetClient

func (m HTTPClient) GetClient() *http.Client

func (HTTPClient) GetJSON

func (m HTTPClient) GetJSON(url string) (*http.Response, error)

func (HTTPClient) GetText

func (m HTTPClient) GetText(_ string) (*http.Response, error)

func (HTTPClient) Reset

func (m HTTPClient) Reset()

func (HTTPClient) ResetJSONResponsesForURL

func (m HTTPClient) ResetJSONResponsesForURL(url string)

func (HTTPClient) RoundTrip

func (m HTTPClient) RoundTrip(_ *http.Request) (*http.Response, error)

type JSONResponse

type JSONResponse struct {
	Body       string
	StatusCode int
}

type RequestData

type RequestData struct {
	Method string
	URL    string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL