podman/test/apiv2
Matej Vasek dd98e70302 fix: use UTC Time Stamps in response JSON
Signed-off-by: Matej Vasek <mvasek@redhat.com>
2021-05-10 11:21:14 +02:00
..
rest_api migrate Podman to containers/common/libimage 2021-05-05 11:30:12 +02:00
00-TEMPLATE
01-basic.at APIv2 basic test: relax APIVersion check 2021-03-29 15:32:01 -06:00
10-images.at fix: compat API "images/get" for multiple images 2021-05-07 20:35:03 +02:00
12-imagesMore.at apiv2 tests: finally fix POST as originally intended 2021-03-10 05:24:44 -07:00
20-containers.at fix: use UTC Time Stamps in response JSON 2021-05-10 11:21:14 +02:00
22-stop.at apiv2 tests: finally fix POST as originally intended 2021-03-10 05:24:44 -07:00
23-containersArchive.at APIv2 tests: lots of cleanup 2021-02-09 10:43:54 -07:00
25-containersMore.at Trim white space from /top endpoint results 2021-03-30 10:42:06 -07:00
26-containersWait.at apiv2 tests: finally fix POST as originally intended 2021-03-10 05:24:44 -07:00
30-volumes.at Allow docker volume create API to pass without name 2021-04-27 10:32:06 -04:00
35-networks.at Http api tests for network prune with until filter 2021-04-04 23:33:14 +02:00
40-pods.at Fix list pods filter handling in libpod api 2021-03-26 20:19:12 +01:00
44-mounts.at System test cleanup 2021-03-15 15:27:06 -06:00
45-system.at apiv2 tests: finally fix POST as originally intended 2021-03-10 05:24:44 -07:00
50-secrets.at apiv2 tests: finally fix POST as originally intended 2021-03-10 05:24:44 -07:00
60-auth.at fix use with localhost (testing) 2021-03-12 10:48:03 -08:00
README.md apiv2 tests: finally fix POST as originally intended 2021-03-10 05:24:44 -07:00
test-apiv2 apiv2 tests: finally fix POST as originally intended 2021-03-10 05:24:44 -07:00

API v2 tests

This directory contains tests for the podman version 2 API (HTTP).

Tests themselves are in files of the form 'NN-NAME.at' where NN is a two-digit number, NAME is a descriptive name, and '.at' is just an extension I picked.

Running Tests

The main test runner is test-apiv2. Usage is:

$ sudo ./test-apiv2 [NAME [...]]

...where NAME is one or more optional test names, e.g. 'image' or 'pod' or both. By default, test-apiv2 will invoke all *.at tests.

test-apiv2 connects to localhost only and via TCP. There is no support here for remote hosts or for UNIX sockets. This is a framework for testing the API, not all possible protocols.

test-apiv2 will start the service if it isn't already running.

Writing Tests

The main test function is t. It runs curl against the server, with POST parameters if present, and compares return status and (optionally) string results from the server:

t GET /_ping 200 OK
  ^^^ ^^^^^^ ^^^ ^^
  |   |      |   +--- expected string result
  |   |      +------- expected return code
  |   +-------------- endpoint to access
  +------------------ method (GET, POST, DELETE, HEAD)


t POST libpod/volumes/create name=foo 201 .ID~[0-9a-f]\\{12\\}
       ^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^^
       |                     |        |   JSON '.ID': expect 12-char hex
       |                     |        +-- expected code
       |                     +----------- POST params
       +--------------------------------- note the missing slash

Notes:

  • If the endpoint has a leading slash (/_ping), t leaves it unchanged. If there's no leading slash, t prepends /v1.40. This is a simple convenience for simplicity of writing tests.

  • When method is POST, the argument(s) after the endpoint may be a series of POST parameters in the form 'key=value', separated by spaces: t POST myentrypoint 200 ! no params t POST myentrypoint id=$id 200 ! just one t POST myentrypoint id=$id filter='{"foo":"bar"}' 200 ! two, with json t POST myentrypoint name=$name badparam='["foo","bar"]' 500 ! etc... t will convert the param list to JSON form for passing to the server. A numeric status code terminates processing of POST parameters.

  • The final arguments are one or more expected string results. If an argument starts with a dot, t will invoke jq on the output to fetch that field, and will compare it to the right-hand side of the argument. If the separator is = (equals), t will require an exact match; if ~ (tilde), t will use expr to compare.