Skip to content

Instantly share code, notes, and snippets.

@mertyildiran
Last active May 17, 2021 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mertyildiran/104379ace5f123a28bf2023aa36b8646 to your computer and use it in GitHub Desktop.
Save mertyildiran/104379ace5f123a28bf2023aa36b8646 to your computer and use it in GitHub Desktop.
Mockintosh: mocks for microservice environments - Part 2: HTTP Request Matching
services:
- port: 8081
endpoints:
- path: "/example/path/{{my_variable}}/lastsegment"
response: "my_variable is captured: {{my_variable}}"
services:
- port: 8081
endpoints:
- path: "/example/path/{{x}}-middle-{{y}}/lastsegment"
response: "x is: {{x}} and y is: {{y}}"
services:
- port: 8081
endpoints:
- path: "/example/path/{{regEx '(\\d)' 'x'}}/lastsegment"
response: "x is: {{x}}"
services:
- port: 8081
endpoints:
- path: "/example"
method: GET
response: "Matched to GET /example"
- path: "/example"
method: POST
response: "Matched to POST /example"
- path: "/example"
method: PUT
response: "Matched to PUT /example"
- path: "/example"
method: PATCH
response: "Matched to PATCH /example"
services:
- port: 8081
endpoints:
- path: "/static-value"
method: GET
queryString:
param1: my Value
response:
body: 'matched with static value: {{request.queryString.param1}}'
status: 200
- path: "/alternative"
method: GET
queryString:
param1: my Value
param2: "{{myVar}}"
param3: "{{regEx 'prefix-(.+)-suffix' 'myCapturedVar'}}"
response:
body: 'query string match: {{request.queryString.param1}} {{myVar}} {{myCapturedVar}}'
status: 201
- path: "/alternative"
method: GET
queryString:
param4: another query string
response:
body: 'param4 request query string: {{request.queryString.param4}}'
services:
- port: 8081
endpoints:
- path: "/alternative"
method: GET
headers:
hdr1: myValue
hdr2: "{{myVar}}"
hdr3: "{{regEx 'prefix-(.+)-suffix' 'myCapturedVar'}}"
response:
body: 'headers match: {{request.headers.hdr1}} {{myVar}} {{myCapturedVar}}'
status: 201
headers:
Set-Cookie:
- name1={{request.headers.hdr2}}
- name2={{request.headers.hdr3}}
- path: "/alternative"
headers:
hdr4: another header
response:
body: 'hdr4 request header: {{request.headers.hdr4}}'
headers:
hdr4: 'hdr4 request header: {{request.headers.hdr4}}'
services:
- name: Mock for Service1
port: 8081
endpoints:
- path: "/example"
method: POST
body:
text: {{regEx 'expectedval-(.+)' 'namedValue'}}
services:
- port: 8081
endpoints:
- path: "/body-urlencoded"
method: POST
body:
urlencoded:
param1: myValue
param2: "{{myVar}}"
param3: "{{regEx 'prefix-(.+)-suffix' 'myCapturedVar'}}"
- path: "/body-multipart"
method: POST
body:
multipart:
param1: myValue
param2: "{{myVar}}"
param3: "{{regEx 'prefix-(.+)-suffix' 'myCapturedVar'}}"
services:
- name: Mock for Service1
port: 8081
endpoints:
- path: "/example"
method: POST
body:
schema:
type: object
properties:
somekey: { }
required:
- somekey
response: 'example: body JSON schema matched'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment