AppDoctor provides a complex assertion engine powering both proxy rules and tests. We do not yet have a public knowledge wiki so we are doing a post covering AppDoctor Assertions in detail.
AppDoctor allows basic assertions against the following set of fields:
url: The url of the request
status: The status returned from the request
size: The size of the response of the request
time: How long the request took to complete
health_check: boolean if this request was an AppDoctor webhook
name: The name of the bin the request was from
success_percentage: The percentage in float of requests that were of status less than 201
requests_per_second: The float amount of requests per second over a period of the previous 10 minutes
appdoctor_url: The non decoded url of this request. Example may be google-com-ACCOUNT.appdoctor.io
path: the path of the request. Example of /v1/users/userid
webhook: boolean of if the request is a AppDoctor sent webhook
request_query, request_header,request_body,response_body,response_header: In dot notation you have access to any part of the request/response. An example might be request_body.user.name
= : equals
> : greater then
> = : greater then or equal
< : less then
< = : less then or equal
!= : not equal
empty : if something is empty. This operation works differently depending on the data type. An example is you can check if an array in the response is empty or not
not empty : the inverse of empty
contains : the operation works differently depending on the data type it is ran against. An example may be a string contains a substring
starts with: This checks if the string starts with a substring
valid: This checks if a string is valid binary
similar: this will return true or false if the string is similar to the string your checking against
is even: checks if a value is even
is odd: checks if a value is odd
If you find yourself needing some additional power over the normal form assertion you can write AAL. This is the textual format of what you see above. An example of an AAL rule for the above image:
(equal(ad_info.decodedUrl, cast_string(/users)) || greater_equal(ad_info.status, cast_integer(200)) && equal(ad_info.method, cast_string(post)))
We suggest experimenting with creating your assertion in the Normal style and then switching to AAL tab and seeing how it is translated. After becoming familiar to the AAL syntax you can do things like complex nesting in order to have some more complex rules.
If you still feel you need more power in your assertions you can write limited Lua code that returns a boolean value if the assertion passed of failed. You are provided 2 functions that you can use to access any part of the request/response.
get(val.val.val) : The get function allows you to grab any bit of data from the request response object and run assertions against it. An example might be return get(request.user.name) == “jordan”
get_val(val.val.val) : The get_val function allows you to grab data from the current value object. This is only applicable in the Tests section of AppDoctor.
As with anything else we do if anything above needs a better explanation then you can reach out to us at firstname.lastname@example.org.
Our hope is with the AppDoctor assertion engine you can have the complexity at your fingertips to get notified the minute something of interest happens.
Follow us on twitter to learn more about our development and receive future discounts for being along for the ride.
If you are interested in joining our closed beta, shoot us an email at email@example.com
Until next time. ✌️