Let's create a binary-based imposter with multiple stubs:
POST /imposters HTTP/1.1
Host: localhost:<%= port %>
Accept: application/json
Content-Type: application/json
{
"port": 4549,
"protocol": "tcp",
"mode": "binary",
"stubs": [
{
"responses": [{ "is": { "data": "Zmlyc3QgcmVzcG9uc2U=" } }],
"predicates": [{ "endsWith": { "data": "AwQ=" } }]
},
{
"responses": [{ "is": { "data": "c2Vjb25kIHJlc3BvbnNl" } }],
"predicates": [{ "endsWith": { "data": "BQY=" } }]
},
{
"responses": [{ "is": { "data": "dGhpcmQgcmVzcG9uc2U=" } }],
"predicates": [{ "endsWith": { "data": "BQY=" } }]
}
]
}
We'll use the command line base64
tool to decode the
request to binary before sending to the imposter. We're sending a
base64-encoded version of four bytes: 0x1, 0x2, 0x3, and 0x4. Our
first predicate is a base64 encoded version of 0x3 and 0x4. The
response is a base64-encoded version of the string "first response":
echo 'AQIDBA==' | base64 --decode | nc localhost 4549
first response
Next we'll send 0x1, 0x2, 0x4, 0x5, and 0x6, matching on a predicate encoding 0x5 and 0x6:
echo 'AQIDBAUG' | base64 --decode | nc localhost 4549
second response
The third stub will never run, since it matches the same requests as the
second stub. mountebank always chooses the first stub that matches based on
the order you add them to the stubs
array when creating the
imposter.
DELETE /imposters/4549 HTTP/1.1
Host: localhost:<%= port %>
Accept: application/json