podman/test/apiv2
Ed Santiago e33f523907 apiv2 tests: add helpers to start/stop a local registry
...and a rudimentary set of /auth tests for PR#9589 (disabled).

This simply adds a new start_registry() helper function that
allocates a random unused port, pulls a registry image, creates
a local certificate + random username + random password, and
fires everything up. Since none of this is (yet) used in CI,
this is very low risk.

The only infinitessimally-risky change is using a dedicated
subdirectory of $WORKDIR (instead of $WORKDIR itself) as
the podman root. This fixes a dumb oversight on my part:
the workdir has grown to be used for much more than just
podman root; this change removes clutter and makes it
easier for humans to debug in cases of problems.

Signed-off-by: Ed Santiago <santiago@redhat.com>
2021-03-08 18:08:17 -07:00
..
rest_api Refactor python tests to run against python3.9 2021-03-01 13:15:59 -07:00
00-TEMPLATE Tests for API v2 2020-01-17 09:59:22 -07:00
01-basic.at Use version package to track all versions 2021-03-03 17:03:19 -07:00
10-images.at Correct compat images/create?fromImage response 2021-02-26 03:08:10 +01:00
12-imagesMore.at Correct compat images/{name}/push response 2021-03-07 02:38:01 +01:00
20-containers.at Respect NanoCpus in Compat Create 2021-03-04 12:32:09 -05:00
22-stop.at APIv2 tests: add tests for stop 2020-03-03 06:40:27 -07:00
23-containersArchive.at APIv2 tests: lots of cleanup 2021-02-09 10:43:54 -07:00
25-containersMore.at Merge pull request #8581 from baude/kubegen 2020-12-07 16:16:15 -05:00
26-containersWait.at Add test for Docker APIv2 wait 2021-02-03 22:10:27 +01:00
30-volumes.at APIv2 tests: make more maintainable 2021-03-01 10:47:48 -07:00
35-networks.at APIv2 tests: make more maintainable 2021-03-01 10:47:48 -07:00
40-pods.at APIv2 tests: get them passing again 2020-10-12 08:45:39 -06:00
44-mounts.at Compat API: create volume source dirs on the host 2021-03-03 16:22:31 -05:00
45-system.at APIv2 tests: make more maintainable 2021-03-01 10:47:48 -07:00
50-secrets.at Add version field to secret compat list/inspect api 2021-03-02 16:55:21 -05:00
60-auth.at apiv2 tests: add helpers to start/stop a local registry 2021-03-08 18:08:17 -07:00
README.md Tests for API v2 2020-01-17 09:59:22 -07:00
test-apiv2 apiv2 tests: add helpers to start/stop a local registry 2021-03-08 18:08:17 -07:00

README.md

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 after the endpoint must be a series of POST arguments in the form 'key=value', separated by commas. t will convert those to JSON form for passing to the server.

  • 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.