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
Property | Description | Type | Required |
---|---|---|---|
<mock-id> | Unique identifier for the mock | string | true |
type | Type of the mock configuration. For HTTP its HTTP::MOCK | string | true |
props | Properties specific to this action. Refer to props section for more details. | object | true |
props
Property | Description | Type | Required |
---|---|---|---|
port | Port number on which the mock server listens | integer | true |
endpoints | List of endpoint configurations defining the behavior of the mock | array | true |
Match Properties
Property | Description | Type |
---|---|---|
method | The HTTP method to match. | String |
path | The path to match. | String |
headers | The headers to match. | Object |
query | The query properties to match. | Object |
body | The body content to match. | Object |
Response Properties
Property | Description | Type |
---|---|---|
statusCode | The HTTP status code of the response. | Integer |
headers | The headers of the response. | Object |
body | The body content of the response. | Object |
Forward Properties
Property | Description | Type |
---|---|---|
host | The host of the actual service to forward the request to. | String |
port | The port of the actual service to forward the request to. | Integer |
Error Properties
Property | Description | Type |
---|---|---|
dropConnection | Determines whether to drop the connection without returning a response. | Boolean |
responseBytes | The response body as a base64-encoded string in case of an error response. | String |