Assertions

Assert on your step's response, inter-service traffic, and console logs.

Each step can have an assertions array of blocks. Block type is determined by shape — there are three kinds:

Self block

Asserts on the step's own response (HTTP response or DB query result). A self block has no match or service field.

{
  "assertions": [
    { "path": "response.status", "operator": "eq", "value": 201 },
    { "path": "response.body.id", "operator": "exists" },
    { "path": "response.body.name", "operator": "eq", "value": "{{userName}}" },
    { "path": "response.header.content-type", "operator": "contains", "value": "application/json" },
    { "path": "responseTime", "operator": "lt", "value": 500 }
  ]
}

HTTP call block

Asserts on inter-service traffic captured by the interceptor sidecar. Identified by the presence of a match field.

{
  "match": {
    "origin": "api-gateway",
    "method": "POST",
    "url": "user-service/api/users"
  },
  "count": { "operator": "eq", "value": 1 },
  "assertionScope": "all",
  "assertions": [
    { "path": "request.body.email", "operator": "eq", "value": "{{email}}" },
    { "path": "response.status", "operator": "eq", "value": 201 },
    { "path": "response.body.id", "operator": "exists" }
  ]
}

Match fields

All optional, all support {{variables}}:

FieldDescription
originService name that made the request
methodHTTP method to match
urlTarget URL: service-name/path, service-name, or /path

assertionScope

Determines which matching traffic entries are validated:

ValueBehavior
all (default)All matching entries must pass all assertions
firstOnly the first matching entry is validated
lastOnly the last matching entry is validated
anyAt least one matching entry must pass all assertions

count

Asserts on the number of matching traffic entries:

"count": { "operator": "eq", "value": 1 }

Operators: eq, gt, gte, lt, lte. Default: { "operator": "gte", "value": 1 } (at least one match expected).

Console log block

Asserts on console output from a specific service during the step group's execution. Identified by the presence of a service field.

{
  "service": "user-service",
  "consoleAssertions": [
    {
      "level": "INFO",
      "message": { "operator": "contains", "value": "User created" },
      "count": { "operator": "gte", "value": 1 }
    },
    {
      "level": "ERROR",
      "count": { "operator": "eq", "value": 0 }
    },
    {
      "message": { "operator": "matches", "value": "Processing order \\d+" },
      "count": { "operator": "gte", "value": 1 }
    }
  ]
}

ConsoleLogAssertion fields

FieldTypeRequiredDescription
levelenumNoFilter by log level: INFO, WARN, ERROR, DEBUG. If omitted, matches all levels.
messageobjectNoFilter by message content. Has operator (eq, contains, matches) and value (supports {{variables}}).
countobjectYesAssert on count of matching logs: { "operator": "eq", "value": 0 }

Assertion paths

HTTP responses (self block or HTTP call block)

PathDescription
response.statusHTTP status code (integer)
response.bodyEntire response body
response.body.fieldTop-level field in response body
response.body.nested.fieldNested field (dot notation)
response.body[0].fieldArray element access
response.header.header-nameResponse header (case-insensitive)
request.methodHTTP method of the request
request.bodyEntire request body
request.body.fieldField in request body
request.header.header-nameRequest header (case-insensitive)
responseTimeResponse time in milliseconds

Database query results (self block only)

PathDescription
successBoolean — did the query succeed?
dataArray of result rows
data[0].columnSpecific column from a result row
rowsAffectedNumber of affected rows (integer)
errorError message if query failed

Operators

OperatorValue required?Value typeDescription
eqYesanyExact equality (case-insensitive for strings)
neYesanyNot equal
gtYesnumberGreater than
gteYesnumberGreater than or equal
ltYesnumberLess than
lteYesnumberLess than or equal
containsYesstringSubstring match (case-insensitive)
notContainsYesstringSubstring does NOT match
matchesYesstring (regex)Regular expression match
existsNoValue exists (defined and not null)
notExistsNoValue does not exist
inYesarrayValue is in the given array
notInYesarrayValue is NOT in the given array
typeYesstringType check: string, number, boolean, object, array, null
lengthYesnumberArray or string length equals value
isEmptyNoValue is empty/null/undefined/empty array/empty object
notEmptyNoValue is not empty
arrayContainsYesanyArray contains the given element
arrayNotContainsYesanyArray does NOT contain the given element