🧁 Upcake

Cupcakes for your API

Overview

Upcake enables assertions to be performed against HTTP requests. Requests and their assertions are defined in a YAML file and can have dependencies on each other, provided that dependency requests are named. Assertions can be against request timing data and any response data including headers, content and response code.

The request URL, headers and content support template rendering with Handlebars syntax.

Requests are run in parallel except where they have a dependency to another request in which case they will wait until their dependencies have completed before starting.

The response headers and content of a request is made available as part of the template context for dependent requests.

Installation

With cargo

bash cargo install upcake

From source

bash git clone https://github.com/johnnynotsolucky/upcake.git cd upcake cargo install --path .

Usage

Command-line options

Note: Configuration set from the command line will override configuration for that property set in the Upcakefile.

Configuration

Request configuration

Assertion configuration

Available assertions

In addition to the top-level assertion configuartion, each assertion has its own properties which are required to be set.

Between

Type: between

Assert that a value is within a range.

Example

yaml - type: between path: ."response_code" min: 200 max: 399 inclusive: true

Equal

Type: equal

Assert that a value equals the given value.

Example

yaml - type: equal path: ."response_code" value: 200

Not Equal

Type: not-equal

Assert that a value is not equal to the given value.

Example

yaml - type: not-equal path: ."response_code" value: 204

Length

Type: length

Assert that the length of a value passes the given assertion

Example

yaml - type: length path: ."headers".[] assertion: - type: equal value: 5

Contains

Type: contains

Assert that a response value contains the given value.

Examples

Assert mapping contains all key/value pairs

yaml - type: contains path: ."content".{} value: key: Value another_property: Some other value

Assert array contains a value

yaml - type: contains path: ."content"."my_integer_array".[] value: 10

or

yaml - type: contains path: ."content"."my_object_array".[] value: id: item_10 value: Item Value

Assert substring appears in response value

yaml - type: contains path: ."content"."my_string" value: "value"

Exists

Type: exists

Assert that the given value exists as a key in the response value.

Example

yaml - type: exists path: ."content"."my_object".{} value: id

Greater than

Type: greater-than

Assert that a value is greater than the given value.

Example

yaml - type: greater-than path: ."response_code" value: 200

Greater than equal

Type: greater-than-equal

Assert that a value is greater or equal to the given value.

Example

yaml - type: greater-than-equal path: ."response_code" value: 200

Less than

Type: less-than

Assert that a value is less than the given value

Example

yaml - type: less-than path: ."response_code" value: 400

Less than equal

Type: less-than-equal

Assert that a value is less than or equal to the given value

Example

yaml - type: less-than-equal path: ."timing"."starttransfer" value: 100

Response data

Request result

Timing results

Examples

Examples are in examples.

They are configured to run against a local httpbin server.

httpbin Server

Start with docker

bash docker run -p 8888:80 kennethreitz/httpbin

Start with docker-compose

bash docker-compose --file examples/docker-compose.yaml up

Run the examples

bash upcake --config-file examples/basic.yaml