Crates.io | upcake |
lib.rs | upcake |
version | 0.1.6 |
source | src |
created_at | 2021-10-12 14:12:48.158529 |
updated_at | 2021-11-02 20:46:34.661991 |
description | Fast, easy and consistent testing for HTTP APIs |
homepage | |
repository | https://github.com/johnnynotsolucky/upcake |
max_upload_size | |
id | 464003 |
size | 138,748 |
Cupcakes for your API
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 using the handlebars crate.
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.
cargo install upcake
git clone https://github.com/johnnynotsolucky/upcake.git
cd upcake
cargo install --path .
--env-var-prefix
- An optional prefix to filter environment variables
injected into the template context-k
, --insecure
- Allow insecure server connections when using SSL-E
, --cert
- Client certificate file--key
- Client private key file--cacert
- CA certificate to verify against-L
, --location
- Follow redirects-v
, --verbose
- Verbose output--fail-request
- Fail request on HTTP error response codes-s
, --max-response-size
- Maximum response size in bytes-e
, --extra-vars
Set additional variables as key=value or YAML. To use a
file, prepend the value with "@". Available in the template context in the user
property.--connect-timeout
- Maximum time allowed for connection in milliseconds-c
, --config-file
- Path to the request config file. Defaults to
"Upcakefile.yaml".Note: Configuration set from the command line will override configuration for that property set in the Upcakefile.
env_var_prefix
- An optional prefix to filter environment variables.
Overridden by --env-var-prefix
.location
- Follow redirects. Overridden by --insecure
.insecure
- Allow insecure server connections when using SSL. Overridden by
--insecure
.client_cert
- Client certificate file. Overridden by --cert
. Unless
absolute, path is relative to the directory of the config file.client_key
- Client private key file. Overridden by --key
. Unless
absolute, path is relative to the directory of the config file.ca_cert
- CA certificate to verify against. Overridden by --cacert
. Unless
absolute, path is relative to the directory of the config file.connect_timeout
- Maximum time allowed for connection. Overridden by
--connect-timeout
.extra_vars
- Set additional variables from YAML mapping. Merged with vars
set with --extra-vars
. Available in the template context in the user
property.verbose
- Verbose output. Overridden by --verbose
.fail_request
- Fail request on HTTP error response codesmax_response_size
- Maximum response size in bytes. Overridden by
--max-response-size
.requests
- List of request configurations.location: false
insecure: false
ca_cert: ca.pem
client_cert: client.pem
client_key: key.pem
connect_timeout: 100
extra_vars:
my_var: Some Value
verbose: true
max_response_size: 32000
requests:
- url: "http://localhost:8888/post"
name
optional - Name of the request.requires
optional - List of named requests this request depends upon.request_method
optional - The HTTP method to use. Defaults to "GET".data
optional - Data to send with the request. Send the contents of a file by prefixing the value with an "@", for example "@path/to/body/template.hbs". Relative paths are relative to the directory of the loaded configuration file.headers
optional - Either a list of headers or a template to render raw headers from.url
- The URL to make the request to.assertions
optional - A list of assertions to perform on the response. Defaults to a HTTP 200 assertion.- name: "Request B"
requires: ["Request A"]
request_method: "POST"
data: "@data.hbs"
headers:
- name: Accept
value: application/json
- name: Content-Type
value: application/json
url: "http://localhost:8888/post"
assertions:
- type: equal
path: ."response_code"
value: 200
- name: "Request B"
requires: ["Request A"]
request_method: "GET"
url: "http://localhost:8888/get"
headers: |
Accept: application/json
{{#each requests.[Request A].headers}}
{{#if (eqi name "Set-Cookie")}}
Cookie: {{value}}
{{/if}}
{{/each}}
type
- The type of assertion to use. See available assertions.
path
- The jql path to the field the assertion should run against. Defaults to .
. path
is ignored on inner assertions, for example the length assertion.
skip
optional - Whether to skip the assertion. If set, requires a string value for the reason.
assertion
- The assertion to apply
- type: length
path: ."content"."slideshow"."slides".[]
skip: Some reason for skipping the assertion
assertion:
type: equal
value: 2
In addition to the top-level assertion configuartion, each assertion has its own properties which are required to be set.
Type: between
Assert that a value is within a range.
min
- Start of range.max
- End of range.inclusive
optional - Whether to include min
and max
in the assertion.- type: between
path: ."response_code"
min: 200
max: 399
inclusive: true
Type: equal
Assert that a value equals the given value.
value
- Value to assert.- type: equal
path: ."response_code"
value: 200
Type: not-equal
Assert that a value is not equal to the given value.
value
- Value to assert.- type: not-equal
path: ."response_code"
value: 204
Type: length
Assert that the length of a value passes the given assertion
assertion
- Any assertion with the same configuration defined in assertion configuration.- type: length
path: ."headers".[]
assertion:
- type: equal
value: 5
Type: contains
Assert that a response value contains the given value.
For strings, it asserts that the substring is present in the value;
For arrays, it asserts that the value is present in the array;
For mappings (dictionary/object types), asserts that the input map is present in the response map.
value
- The value to assert is contained in the given value.
Assert mapping contains all key/value pairs
- type: contains
path: ."content".{}
value:
key: Value
another_property: Some other value
Assert array contains a value
- type: contains
path: ."content"."my_integer_array".[]
value: 10
or
- type: contains
path: ."content"."my_object_array".[]
value:
id: item_10
value: Item Value
Assert substring appears in response value
- type: contains
path: ."content"."my_string"
value: "value"
Type: exists
Assert that the given value exists as a key in the response value.
value
- The value to assert exists in the given mapping.- type: exists
path: ."content"."my_object".{}
value: id
Type: greater-than
Assert that a value is greater than the given value.
value
- Value to assert.- type: greater-than
path: ."response_code"
value: 200
Type: greater-than-equal
Assert that a value is greater or equal to the given value.
value
- Value to assert.- type: greater-than-equal
path: ."response_code"
value: 200
Type: less-than
Assert that a value is less than the given value
value
- Value to assert.- type: less-than
path: ."response_code"
value: 400
Type: less-than-equal
Assert that a value is less than or equal to the given value
value
- Value to assert.- type: less-than-equal
path: ."timing"."starttransfer"
value: 100
http_version
- The HTTP version used for the request.response_code
- The HTTP response code returned.response_message
- A HTTP response message returned from the host, if any.headers
- A list of response headers.timing
- Response timing data. See timing results.content
- Response content, either formatted as JSON, or raw content if it
couldn't be parsed as JSON.namelookup
- Duration in milliseconds from the start of the request until
name lookup resolved.connect
- Duration in milliseconds from the start of the request until a
connection to the remote host is established.pretransfer
- Duration in milliseconds from the start of the request until
file transfer was about to begin.starttransfer
- Duration in milliseconds from the start of the request until
the first byte was received. AKA TTFB.total
- Duration in milliseconds from the start of the request until the
request ended.dns_resolution
- Alias for namelookup
.tcp_connection
- Difference of connect
and namelookup
.tls_connection
- Difference of pretransfer
and connect
.server_processing
- Difference of starttransfer
and pretransfer
.content_transfer
- Difference of total
and starttransfer
.The request URL, headers and content support template rendering with Handlebars using the handlebars crate.
The response headers and content of a request is made available as part of the template context for dependent requests.
user
Optional user-provided context. This is set via the
--extra-vars
flag and/or with the
extra_vars
configuration property in the config file.
env
A map of the environment variables available to the program at runtime. Setting
a prefix with --env-var-prefix
or the
env_var_prefix
config option will remove any environment
variables which are not prefixed with that value.
requests
A map of requests keyed by request name. Only requests which are set in the
requires
property of the request configuration are
included. Requests which have not yet executed or completed will not be
available until they have completed.
eqi
- Case-insensitive equalsnei
- Case-insensitive not equalsExamples are in examples.
They are configured to run against a local httpbin server.
docker run -p 8888:80 kennethreitz/httpbin
docker-compose --file examples/docker-compose.yaml up
upcake --config-file examples/basic.yaml
AUTH_TOKEN=my_token upcake --config-file ./examples/pipeline.yaml
upcake --config-file examples/mtls.yaml