Skip to main content

HTTP::MOCK

HTTP::MOCK allows you to define HTTP mocks for your tests. With HTTP mocks, you can simulate responses from external services, test different scenarios, and validate your system's behavior.

info

Only one of response, error, or forward can be set for each endpoint. If you specify multiple properties, Tesmon will prioritize them in the following order: response takes precedence over forward, and forward takes precedence over error. Therefore, make sure to configure your mock accordingly to ensure the desired behavior for your test scenario.

Syntax

mocks:
<mock-id>:
type: HTTP::MOCK
props:
port: <port>
endpoints:
- match: <match-properties-1>
response: <response-properties-1>
- match: <match-properties-2>
forward: <forward-properties-2>
- match: <match-properties-3>
error: <error-properties-3>

Properties

PropertyDescriptionTypeRequired
<mock-id>Unique identifier for the mockstringtrue
typeType of the mock configuration. For HTTP its HTTP::MOCKstringtrue
propsProperties specific to this action. Refer to props section for more details.objecttrue

props

PropertyDescriptionTypeRequired
portPort number on which the mock server listensintegertrue
endpointsList of endpoint configurations defining the behavior of the mockarraytrue

Match Properties

PropertyDescriptionType
methodThe HTTP method to match.String
pathThe path to match.String
headersThe headers to match.Object
queryThe query properties to match.Object
bodyThe body content to match.Object

Response Properties

PropertyDescriptionType
statusCodeThe HTTP status code of the response.Integer
headersThe headers of the response.Object
bodyThe body content of the response.Object

Forward Properties

PropertyDescriptionType
hostThe host of the actual service to forward the request to.String
portThe port of the actual service to forward the request to.Integer

Error Properties

PropertyDescriptionType
dropConnectionDetermines whether to drop the connection without returning a response.Boolean
responseBytesThe response body as a base64-encoded string in case of an error response.String