basichttp

package
v1.3.3-0...-f31c912 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2024 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	*http.Client
}

Client extends the regular http.Client by adding a GetContent method that does a GET query to a given URL and returns an error if the status is non-200. This is typically used to retrieve small files stored in a S3 bucket like the maintenance.BasicHTTPMaintenanceTrigger or the version.BasicHTTPVersionGetter are doing.

func (*Client) GetContent

func (c *Client) GetContent(ctx context.Context, targetURL url.URL) ([]byte, error)

GetContent sends a GET HTTP request and fails if the response is not 200.

type ServerMock

type ServerMock struct {
	Srv *httptest.Server
	// contains filtered or unexported fields
}

ServerMock is a HTTP server whose response can be controlled from the tests. This is used to mock external dependencies like s3 buckets or a remote HTTP server.

func NewServerMock

func NewServerMock(path string) *ServerMock

NewServerMock builds and returns a

func (*ServerMock) ServeHTTP

func (m *ServerMock) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface.

func (*ServerMock) SetResponse

func (m *ServerMock) SetResponse(t *testing.T, code int, response string)

SetResponse sets the ServerMock's response.

Jump to

Keyboard shortcuts

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