Test bodies and files

Technical reference of Cuerpos y archivos de prueba.

This API is used in Snapshots.


Symbols

SymbolClassDescription
RequestBodyValuetypeRequestBodyValue defines a public type of API.
RequestBodyRawtypeRequestBodyRaw defines a public type of API.
RequestBodyQuerytypeRequestBodyQuery defines a public type of API.
RequestBodyFormDatatypeRequestBodyFormData defines a public type of API.
RequestBodyJSONtypeRequestBodyJSON defines a public type of API.
RequestBodyRaw.EncodefuncCodify the body and return content and half type.
RequestBodyQuery.EncodefuncCodify the body and return content and half type.
RequestBodyFormData.EncodefuncCodify the body and return content and half type.
RequestBodyJSON.EncodefuncCodify the body and return content and half type.
RequestBodyvarRequestBody it exposes a shared value of the package.
RequestBody.EmptyfuncIt builds an empty body.
RequestBody.RawfuncIt builds an untransformed textual body.
RequestBody.RawWithTypefuncIt builds a textual body with an explicit half type.
RequestBody.QueryfuncBuild a body application/x-www-form-urlencoded.
RequestBody.FormDatafuncBuild a body multipart/form-data.
RequestBody.JSONfuncIt builds a JSON body.
ExpectedBodyRuletypeExpectedBodyRule defines a public type of API.
ExpectedHTTPBodyRuletypeExpectedHTTPBodyRule defines a public type of API.
ExpectedBodyEqualtypeExpectedBodyEqual defines a public type of API.
ExpectedBodyNotEqualtypeExpectedBodyNotEqual defines a public type of API.
ExpectedBodyContainstypeExpectedBodyContains defines a public type of API.
ExpectedBodyNotContainstypeExpectedBodyNotContains defines a public type of API.
ExpectedBodySnapshottypeExpectedBodySnapshot defines a public type of API.
ExpectedBodyJSONEqualtypeExpectedBodyJSONEqual defines a public type of API.
ExpectedBodyJSONNotEqualtypeExpectedBodyJSONNotEqual defines a public type of API.
ExpectedBodyJSONContainstypeExpectedBodyJSONContains defines a public type of API.
ExpectedBodyJSONNotContainstypeExpectedBodyJSONNotContains defines a public type of API.
ExpectedBodyCustomtypeExpectedBodyCustom defines a public type of API.
ExpectedBodyEqual.MatchBodyfuncCompare the body with the rule.
ExpectedBodyEqual.MatchHTTPBodyfuncCompare metadata and HTTP content.
ExpectedBodyNotEqual.MatchBodyfuncCompare the body with the rule.
ExpectedBodyContains.MatchBodyfuncCompare the body with the rule.
ExpectedBodyNotContains.MatchBodyfuncCompare the body with the rule.
ExpectedBodySnapshot.MatchBodyfuncCompare the body with the rule.
ExpectedBodyJSONEqual.MatchBodyfuncCompare the body with the rule.
ExpectedBodyJSONNotEqual.MatchBodyfuncCompare the body with the rule.
ExpectedBodyJSONContains.MatchBodyfuncCompare the body with the rule.
ExpectedBodyJSONNotContains.MatchBodyfuncCompare the body with the rule.
ExpectedBodyCustom.MatchBodyfuncCompare the body with the rule.
ExpectedBodyvarExpectedBody it exposes a shared value of the package.
ExpectedBody.EqualfuncIt builds a rule of equality.
ExpectedBody.NotEqualfuncIt builds a rule of inequality.
ExpectedBody.ContainsfuncIt indicates whether a key contains a specific value.
ExpectedBody.NotContainsfuncIt builds a rule of absence.
ExpectedBody.SnapshotfuncIt builds a snapshot-based rule.
ExpectedBody.JSONEqualfuncIt builds a JSON equality rule.
ExpectedBody.JSONNotEqualfuncIt builds a rule of JSON inequality.
ExpectedBody.JSONContainsfuncIt builds a JSON inclusion rule.
ExpectedBody.JSONNotContainsfuncIt builds a JSON rule of exclusion.
ExpectedBody.CustomfuncIt builds a composite rule.

RequestBodyValue

Declaration:

gox
type RequestBodyValue interface {
	isRequestBody()
	Encode() ([]byte, string, error)
}

RequestBodyValue defines a public type of API.


RequestBodyRaw

Declaration:

gox
type RequestBodyRaw struct {
	Content          string
	ContentTypeValue string
}

RequestBodyRaw defines a public type of API.

Fields

FieldTypeDescription
ContentstringAssociated content.
ContentTypeValuestringAssociated value.

RequestBodyQuery

Declaration:

gox
type RequestBodyQuery struct {
	Values map[string]string
}

RequestBodyQuery defines a public type of API.

Fields

FieldTypeDescription
Valuesmap[string]stringAssociated value.

RequestBodyFormData

Declaration:

gox
type RequestBodyFormData struct {
	Values FormData
}

RequestBodyFormData defines a public type of API.

Fields

FieldTypeDescription
ValuesFormDataAssociated value.

RequestBodyJSON

Declaration:

gox
type RequestBodyJSON struct {
	Value any
}

RequestBodyJSON defines a public type of API.

Fields

FieldTypeDescription
ValueanyValue stored.

RequestBodyRaw.Encode

Declaration:

gox
func (b RequestBodyRaw) Encode() ([]byte, string, error)

Codify the body and return content and half type.

Returns

ReturnTypeDescription
value[]byteResult collection; can be nil when there are no values.
valuestringTextual value produced by the operation; its zero value is an empty string.
errerrornil if the operation ends correctly; otherwise, the error produced.

Behavior

The operation returns an error when it cannot complete the above contract.

Errors

Encode returns an error when the arguments, the status of the receiver or the underlying operation make it impossible to complete the call.

Usage syntax

gox
value, value, err := requestBodyRaw.Encode()

RequestBodyQuery.Encode

Declaration:

gox
func (b RequestBodyQuery) Encode() ([]byte, string, error)

Codify the body and return content and half type.

Returns

ReturnTypeDescription
value[]byteResult collection; can be nil when there are no values.
valuestringTextual value produced by the operation; its zero value is an empty string.
errerrornil if the operation ends correctly; otherwise, the error produced.

Behavior

The operation returns an error when it cannot complete the above contract.

Errors

Encode returns an error when the arguments, the status of the receiver or the underlying operation make it impossible to complete the call.

Usage syntax

gox
value, value, err := requestBodyQuery.Encode()

RequestBodyFormData.Encode

Declaration:

gox
func (b RequestBodyFormData) Encode() ([]byte, string, error)

Codify the body and return content and half type.

Returns

ReturnTypeDescription
value[]byteResult collection; can be nil when there are no values.
valuestringTextual value produced by the operation; its zero value is an empty string.
errerrornil if the operation ends correctly; otherwise, the error produced.

Behavior

The operation returns an error when it cannot complete the above contract.

Errors

Encode returns an error when the arguments, the status of the receiver or the underlying operation make it impossible to complete the call.

Usage syntax

gox
value, value, err := requestBodyFormData.Encode()

RequestBodyJSON.Encode

Declaration:

gox
func (b RequestBodyJSON) Encode() ([]byte, string, error)

Codify the body and return content and half type.

Returns

ReturnTypeDescription
value[]byteResult collection; can be nil when there are no values.
valuestringTextual value produced by the operation; its zero value is an empty string.
errerrornil if the operation ends correctly; otherwise, the error produced.

Behavior

The operation returns an error when it cannot complete the above contract.

Errors

Encode returns an error when the arguments, the status of the receiver or the underlying operation make it impossible to complete the call.

Usage syntax

gox
value, value, err := requestBodyJSON.Encode()

RequestBody

Declaration:

gox
var RequestBody requestBodyFactory

RequestBody it exposes a shared value of the package.


RequestBody.Empty

Declaration:

gox
func (requestBodyFactory) Empty() RequestBodyRaw             { return RequestBodyRaw

It builds an empty body.

Returns

ReturnTypeDescription
RequestBodyRaw { returnRequestBodyRawType value RequestBodyRaw produced by the operation.

Usage syntax

gox
RequestBodyRaw             { return := test.RequestBody.Empty()

RequestBody.Raw

Declaration:

gox
func (requestBodyFactory) Raw(content string) RequestBodyRaw { return RequestBodyRaw

It builds an untransformed textual body.

Parameters

ParameterTypeDescription
contentstringType value string required by the operation.

Returns

ReturnTypeDescription
RequestBodyRaw { returnRequestBodyRawType value RequestBodyRaw produced by the operation.

Usage syntax

gox
RequestBodyRaw { return := test.RequestBody.Raw(value)

RequestBody.RawWithType

Declaration:

gox
func (requestBodyFactory) RawWithType(content, contentType string) RequestBodyRaw

It builds a textual body with an explicit half type.

Parameters

ParameterTypeDescription
``contentType value content required by the operation.
contentTypestringMIME type of content.

Returns

ReturnTypeDescription
valueRequestBodyRawType value RequestBodyRaw produced by the operation.

Usage syntax

gox
value := test.RequestBody.RawWithType(value, value)

RequestBody.Query

Declaration:

gox
func (requestBodyFactory) Query(values map[string]string) RequestBodyQuery

Build a body application/x-www-form-urlencoded.

Parameters

ParameterTypeDescription
valuesmap[string]stringValues provided to the operation.

Returns

ReturnTypeDescription
valueRequestBodyQueryType value RequestBodyQuery produced by the operation.

Usage syntax

gox
value := test.RequestBody.Query(value)

RequestBody.FormData

Declaration:

gox
func (requestBodyFactory) FormData(values FormData) RequestBodyFormData

Build a body multipart/form-data.

Parameters

ParameterTypeDescription
valuesFormDataValues provided to the operation.

Returns

ReturnTypeDescription
valueRequestBodyFormDataType value RequestBodyFormData produced by the operation.

Usage syntax

gox
value := test.RequestBody.FormData(value)

RequestBody.JSON

Declaration:

gox
func (requestBodyFactory) JSON(value any) RequestBodyJSON { return RequestBodyJSON

It builds a JSON body.

Parameters

ParameterTypeDescription
valueanyValue to be stored or issued.

Returns

ReturnTypeDescription
RequestBodyJSON { returnRequestBodyJSONType value RequestBodyJSON produced by the operation.

Usage syntax

gox
RequestBodyJSON { return := test.RequestBody.JSON(value)

ExpectedBodyRule

Declaration:

gox
type ExpectedBodyRule interface {
	MatchBody(body []byte) BodyMatchResult
}

ExpectedBodyRule defines a public type of API.


ExpectedHTTPBodyRule

Declaration:

gox
type ExpectedHTTPBodyRule interface {
	ExpectedBodyRule
	MatchHTTPBody(contentType, disposition string, body []byte) BodyMatchResult
}

ExpectedHTTPBodyRule defines a public type of API.


ExpectedBodyEqual

Declaration:

gox
type ExpectedBodyEqual struct {
	Content any `json:"content"`
}

ExpectedBodyEqual defines a public type of API.

Fields

FieldTypeDescription
Contentanyjson: "content" "Associated content.

ExpectedBodyNotEqual

Declaration:

gox
type ExpectedBodyNotEqual struct {
	Content string `json:"content"`
}

ExpectedBodyNotEqual defines a public type of API.

Fields

FieldTypeDescription
Contentstringjson: "content" "Associated content.

ExpectedBodyContains

Declaration:

gox
type ExpectedBodyContains struct {
	Patterns []string `json:"patterns"`
}

ExpectedBodyContains defines a public type of API.

Fields

FieldTypeDescription
Patterns[]stringjson: "patterns" "Pattern used for coincidence.

ExpectedBodyNotContains

Declaration:

gox
type ExpectedBodyNotContains struct {
	Patterns []string `json:"patterns"`
}

ExpectedBodyNotContains defines a public type of API.

Fields

FieldTypeDescription
Patterns[]stringjson: "patterns" "Pattern used for coincidence.

ExpectedBodySnapshot

Declaration:

gox
type ExpectedBodySnapshot struct {
	File string `json:"file"`
	Content string `json:"-"`
	Error   string `json:"-"`
}

ExpectedBodySnapshot defines a public type of API.

Fields

FieldTypeDescription
Filestringjson: "file" "Associated file.
Contentstringjson: "-"Associated content.
Errorstringjson: "-"Associated error.

ExpectedBodyJSONEqual

Declaration:

gox
type ExpectedBodyJSONEqual struct {
	Value any `json:"value,omitempty"`
}

ExpectedBodyJSONEqual defines a public type of API.

Fields

FieldTypeDescription
Valueanyjson: "value, omitempty" "Value stored.

ExpectedBodyJSONNotEqual

Declaration:

gox
type ExpectedBodyJSONNotEqual struct {
	Value any `json:"value,omitempty"`
}

ExpectedBodyJSONNotEqual defines a public type of API.

Fields

FieldTypeDescription
Valueanyjson: "value, omitempty" "Value stored.

ExpectedBodyJSONContains

Declaration:

gox
type ExpectedBodyJSONContains struct {
	Value any `json:"value,omitempty"`
}

ExpectedBodyJSONContains defines a public type of API.

Fields

FieldTypeDescription
Valueanyjson: "value, omitempty" "Value stored.

ExpectedBodyJSONNotContains

Declaration:

gox
type ExpectedBodyJSONNotContains struct {
	Value any `json:"value,omitempty"`
}

ExpectedBodyJSONNotContains defines a public type of API.

Fields

FieldTypeDescription
Valueanyjson: "value, omitempty" "Value stored.

ExpectedBodyCustom

Declaration:

gox
type ExpectedBodyCustom struct {
	Rules []ExpectedBodyRule `json:"-"`
}

ExpectedBodyCustom defines a public type of API.

Fields

FieldTypeDescription
Rules[]ExpectedBodyRulejson: "-"Rules set.

ExpectedBodyEqual.MatchBody

Declaration:

gox
func (r ExpectedBodyEqual) MatchBody(body []byte) BodyMatchResult

Compare the body with the rule.

Parameters

ParameterTypeDescription
body[]byteType value []byte required by the operation.

Returns

ReturnTypeDescription
valueBodyMatchResultType value BodyMatchResult produced by the operation.

Usage syntax

gox
value := expectedBodyEqual.MatchBody(value)

ExpectedBodyEqual.MatchHTTPBody

Declaration:

gox
func (r ExpectedBodyEqual) MatchHTTPBody(contentType, disposition string, body []byte) BodyMatchResult

Compare metadata and HTTP content.

Parameters

ParameterTypeDescription
``contentTypeType value contentType required by the operation.
dispositionstringType value string required by the operation.
body[]byteType value []byte required by the operation.

Returns

ReturnTypeDescription
valueBodyMatchResultType value BodyMatchResult produced by the operation.

Usage syntax

gox
value := expectedBodyEqual.MatchHTTPBody(value, value, value)

ExpectedBodyNotEqual.MatchBody

Declaration:

gox
func (r ExpectedBodyNotEqual) MatchBody(body []byte) BodyMatchResult

Compare the body with the rule.

Parameters

ParameterTypeDescription
body[]byteType value []byte required by the operation.

Returns

ReturnTypeDescription
valueBodyMatchResultType value BodyMatchResult produced by the operation.

Usage syntax

gox
value := expectedBodyNotEqual.MatchBody(value)

ExpectedBodyContains.MatchBody

Declaration:

gox
func (r ExpectedBodyContains) MatchBody(body []byte) BodyMatchResult

Compare the body with the rule.

Parameters

ParameterTypeDescription
body[]byteType value []byte required by the operation.

Returns

ReturnTypeDescription
valueBodyMatchResultType value BodyMatchResult produced by the operation.

Usage syntax

gox
value := expectedBodyContains.MatchBody(value)

ExpectedBodyNotContains.MatchBody

Declaration:

gox
func (r ExpectedBodyNotContains) MatchBody(body []byte) BodyMatchResult

Compare the body with the rule.

Parameters

ParameterTypeDescription
body[]byteType value []byte required by the operation.

Returns

ReturnTypeDescription
valueBodyMatchResultType value BodyMatchResult produced by the operation.

Usage syntax

gox
value := expectedBodyNotContains.MatchBody(value)

ExpectedBodySnapshot.MatchBody

Declaration:

gox
func (r ExpectedBodySnapshot) MatchBody(body []byte) BodyMatchResult

Compare the body with the rule.

Parameters

ParameterTypeDescription
body[]byteType value []byte required by the operation.

Returns

ReturnTypeDescription
valueBodyMatchResultType value BodyMatchResult produced by the operation.

Usage syntax

gox
value := expectedBodySnapshot.MatchBody(value)

ExpectedBodyJSONEqual.MatchBody

Declaration:

gox
func (r ExpectedBodyJSONEqual) MatchBody(body []byte) BodyMatchResult

Compare the body with the rule.

Parameters

ParameterTypeDescription
body[]byteType value []byte required by the operation.

Returns

ReturnTypeDescription
valueBodyMatchResultType value BodyMatchResult produced by the operation.

Usage syntax

gox
value := expectedBodyJSONEqual.MatchBody(value)

ExpectedBodyJSONNotEqual.MatchBody

Declaration:

gox
func (r ExpectedBodyJSONNotEqual) MatchBody(body []byte) BodyMatchResult

Compare the body with the rule.

Parameters

ParameterTypeDescription
body[]byteType value []byte required by the operation.

Returns

ReturnTypeDescription
valueBodyMatchResultType value BodyMatchResult produced by the operation.

Usage syntax

gox
value := expectedBodyJSONNotEqual.MatchBody(value)

ExpectedBodyJSONContains.MatchBody

Declaration:

gox
func (r ExpectedBodyJSONContains) MatchBody(body []byte) BodyMatchResult

Compare the body with the rule.

Parameters

ParameterTypeDescription
body[]byteType value []byte required by the operation.

Returns

ReturnTypeDescription
valueBodyMatchResultType value BodyMatchResult produced by the operation.

Usage syntax

gox
value := expectedBodyJSONContains.MatchBody(value)

ExpectedBodyJSONNotContains.MatchBody

Declaration:

gox
func (r ExpectedBodyJSONNotContains) MatchBody(body []byte) BodyMatchResult

Compare the body with the rule.

Parameters

ParameterTypeDescription
body[]byteType value []byte required by the operation.

Returns

ReturnTypeDescription
valueBodyMatchResultType value BodyMatchResult produced by the operation.

Usage syntax

gox
value := expectedBodyJSONNotContains.MatchBody(value)

ExpectedBodyCustom.MatchBody

Declaration:

gox
func (r ExpectedBodyCustom) MatchBody(body []byte) BodyMatchResult

Compare the body with the rule.

Parameters

ParameterTypeDescription
body[]byteType value []byte required by the operation.

Returns

ReturnTypeDescription
valueBodyMatchResultType value BodyMatchResult produced by the operation.

Usage syntax

gox
value := expectedBodyCustom.MatchBody(value)

ExpectedBody

Declaration:

gox
var ExpectedBody expectedBodyFactory

ExpectedBody it exposes a shared value of the package.


ExpectedBody.Equal

Declaration:

gox
func (expectedBodyFactory) Equal(content any) ExpectedBodyEqual

It builds a rule of equality.

Parameters

ParameterTypeDescription
contentanyType value any required by the operation.

Returns

ReturnTypeDescription
valueExpectedBodyEqualType value ExpectedBodyEqual produced by the operation.

Usage syntax

gox
value := test.ExpectedBody.Equal(nil)

ExpectedBody.NotEqual

Declaration:

gox
func (expectedBodyFactory) NotEqual(content string) ExpectedBodyNotEqual

It builds a rule of inequality.

Parameters

ParameterTypeDescription
contentstringType value string required by the operation.

Returns

ReturnTypeDescription
valueExpectedBodyNotEqualType value ExpectedBodyNotEqual produced by the operation.

Usage syntax

gox
value := test.ExpectedBody.NotEqual(value)

ExpectedBody.Contains

Declaration:

gox
func (expectedBodyFactory) Contains(patterns ...string) ExpectedBodyContains

It indicates whether a key contains a specific value.

Parameters

ParameterTypeDescription
patterns...stringType value ...string required by the operation.

Returns

ReturnTypeDescription
valueExpectedBodyContainsType value ExpectedBodyContains produced by the operation.

Usage syntax

gox
value := test.ExpectedBody.Contains(value)

ExpectedBody.NotContains

Declaration:

gox
func (expectedBodyFactory) NotContains(patterns ...string) ExpectedBodyNotContains

It builds a rule of absence.

Parameters

ParameterTypeDescription
patterns...stringType value ...string required by the operation.

Returns

ReturnTypeDescription
valueExpectedBodyNotContainsType value ExpectedBodyNotContains produced by the operation.

Usage syntax

gox
value := test.ExpectedBody.NotContains(value)

ExpectedBody.Snapshot

Declaration:

gox
func (expectedBodyFactory) Snapshot(file string) ExpectedBodySnapshot

It builds a snapshot-based rule.

Parameters

ParameterTypeDescription
filestringType value string required by the operation.

Returns

ReturnTypeDescription
valueExpectedBodySnapshotType value ExpectedBodySnapshot produced by the operation.

Usage syntax

gox
value := test.ExpectedBody.Snapshot(value)

ExpectedBody.JSONEqual

Declaration:

gox
func (expectedBodyFactory) JSONEqual(value any) ExpectedBodyJSONEqual

It builds a JSON equality rule.

Parameters

ParameterTypeDescription
valueanyValue to be stored or issued.

Returns

ReturnTypeDescription
valueExpectedBodyJSONEqualType value ExpectedBodyJSONEqual produced by the operation.

Usage syntax

gox
value := test.ExpectedBody.JSONEqual(value)

ExpectedBody.JSONNotEqual

Declaration:

gox
func (expectedBodyFactory) JSONNotEqual(value any) ExpectedBodyJSONNotEqual

It builds a rule of JSON inequality.

Parameters

ParameterTypeDescription
valueanyValue to be stored or issued.

Returns

ReturnTypeDescription
valueExpectedBodyJSONNotEqualType value ExpectedBodyJSONNotEqual produced by the operation.

Usage syntax

gox
value := test.ExpectedBody.JSONNotEqual(value)

ExpectedBody.JSONContains

Declaration:

gox
func (expectedBodyFactory) JSONContains(value any) ExpectedBodyJSONContains

It builds a JSON inclusion rule.

Parameters

ParameterTypeDescription
valueanyValue to be stored or issued.

Returns

ReturnTypeDescription
valueExpectedBodyJSONContainsType value ExpectedBodyJSONContains produced by the operation.

Usage syntax

gox
value := test.ExpectedBody.JSONContains(value)

ExpectedBody.JSONNotContains

Declaration:

gox
func (expectedBodyFactory) JSONNotContains(value any) ExpectedBodyJSONNotContains

It builds a JSON rule of exclusion.

Parameters

ParameterTypeDescription
valueanyValue to be stored or issued.

Returns

ReturnTypeDescription
valueExpectedBodyJSONNotContainsType value ExpectedBodyJSONNotContains produced by the operation.

Usage syntax

gox
value := test.ExpectedBody.JSONNotContains(value)

ExpectedBody.Custom

Declaration:

gox
func (expectedBodyFactory) Custom(rules ...ExpectedBodyRule) ExpectedBodyCustom

It builds a composite rule.

Parameters

ParameterTypeDescription
rules...ExpectedBodyRuleType value ...ExpectedBodyRule required by the operation.

Returns

ReturnTypeDescription
valueExpectedBodyCustomType value ExpectedBodyCustom produced by the operation.

Usage syntax

gox
value := test.ExpectedBody.Custom(value)

See also

Next step

Continue with rules of expectations.

Expectations