Documentation ¶
Index ¶
- func CompareImageTypes() cmp.Option
- func GenerateCIArtifactName(prefix string) (string, error)
- func Ignore(what string) cmp.Option
- func IgnoreDates() cmp.Option
- func IgnoreUuids() cmp.Option
- func SendHTTP(api http.Handler, external bool, method, path, body string) *http.Response
- func SetUpTemporaryRepository() (string, error)
- func TearDownTemporaryRepository(dir string) error
- func TestNonJsonRoute(t *testing.T, api http.Handler, external bool, method, path, body string, ...)
- func TestRoute(t *testing.T, api http.Handler, external bool, method, path, body string, ...)
- func TestRouteWithReply(t *testing.T, api http.Handler, external bool, method, path, body string, ...) (replyJSON []byte)
- func TestTOMLRoute(t *testing.T, api http.Handler, external bool, method, path, body string, ...)
- type APICall
- type APICallResult
- type BodyValidator
- type JSONRequestBody
- type JSONValidator
- type RequestBody
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompareImageTypes ¶
CompareImageType considers two image type objects equal if and only if the names of their distro/arch/imagetype are. The thinking is that the objects are static, and resolving by these three keys should always give equivalent objects. Whether we actually have object equality, is an implementation detail, so we don't want to rely on that.
func GenerateCIArtifactName ¶
GenerateCIArtifactName generates a new identifier for CI artifacts which is based on environment variables specified by Jenkins note: in case of migration to sth else like Github Actions, change it to whatever variables GH Action provides
func IgnoreDates ¶
func IgnoreUuids ¶
func SetUpTemporaryRepository ¶
Create a temporary repository
func TearDownTemporaryRepository ¶
Remove the temporary repository
func TestNonJsonRoute ¶
func TestRouteWithReply ¶
func TestRouteWithReply(t *testing.T, api http.Handler, external bool, method, path, body string, expectedStatus int, expectedJSON string, ignoreFields ...string) (replyJSON []byte)
TestRouteWithReply tests the given API endpoint and if the test passes, it returns the raw JSON reply.
Types ¶
type APICall ¶
type APICall struct { // http.Handler to run the call against Handler http.Handler // HTTP method, e.g. http.MethodPatch Method string // Request Path Path string // Request body. If nil, an empty body is sent RequestBody RequestBody // Request header. If nil, default header is sent Header http.Header // Request context. If nil, default context is used Context context.Context // Status that's expected to be received. If set to 0, the status is not checked ExpectedStatus int // Validator for the response body. If set to nil, the body is not validated ExpectedBody BodyValidator }
APICall is a small function object for testing HTTP APIs
func (APICall) Do ¶
func (a APICall) Do(t *testing.T) APICallResult
Do performs the request as defined in the APICall struct.
If any errors occur when doing the request, or any of the validators fail, t.FailNow() is called Note that HTTP error status is not checked if ExpectedStatus == 0
The result of the HTTP call is returned
type APICallResult ¶
type APICallResult struct { // Full body as read from the server Body []byte // Status code returned from the server StatusCode int }
APICallResult holds a parsed response for an APICall
type BodyValidator ¶
type BodyValidator interface { // Validate returns nil if the body is valid. If the body isn't valid, a descriptive error is returned. Validate(body []byte) error }
BodyValidator is an abstract interface for defining validators for response bodies
type JSONRequestBody ¶
type JSONRequestBody string
JSONRequestBody is just a simple wrapper over plain string.
Body is just the string converted to a slice of bytes and content type is set to application/json
func (JSONRequestBody) Body ¶
func (b JSONRequestBody) Body() []byte
func (JSONRequestBody) ContentType ¶
func (b JSONRequestBody) ContentType() string
type JSONValidator ¶
type JSONValidator struct { // Content is the expected json content of the body // // Note that the key order of maps is arbitrary Content string // IgnoreFields is a list of JSON keys that should be removed from both expected body and actual body IgnoreFields []string }
JSONValidator is a simple validator for validating JSON responses
func (JSONValidator) Validate ¶
func (b JSONValidator) Validate(body []byte) error
type RequestBody ¶
type RequestBody interface { // Body returns the intended request body as a slice of bytes Body() []byte // ContentType returns value for Content-Type request header ContentType() string }
RequestBody is an abstract interface for defining request bodies for APICall