tests/testthat/sample_responses/README.md

Sample responses

These provide integration tests for the docker responses. The idea is to provide curated json responses from the docker daemon to particular responses. The comments at the top of the file are in json-like format (within an R comment), and then arbitrary R code that produces a single object (perhaps after intermediate computation), for example:

## version: v1.29
## method: get
## path: /_ping
## code: 200
## response: "OK"
"OK"

The version, method, path, code and response tags are all mandatory:

Comments after the first non-comment line are not parsed as headers.

The response string (response) can get very long but it must be preserved as a single line. This is obviously not very readable.

Generate response strings with (for example)

read_sample_response_str("get", "/volumes/{name}", 200, spec_1_29)

Or generate whole files with

add_sample_response("sample_responses/system_df.R", "get", "/system/df",
                    "200", "1.29")

When porting to a new version of the spec, the simplest thing to is to run:

create_sample_responses("1.99", "1.98")

which will create a new set of responses for version 1.99 by: cloning the data for 1.98 and then adding the new JSON responses from the spec set up testing by creating a file like test-spec-responses-1.30.R for the new version * iterate through testing these while patching the spec and the expected responses, as required

For a failure in v1.xx path foo_bar try

dat <- read_sample_response("sample_responses/v1.31/foo_bar.R")
ans1 <- dat$handler(dat$response, FALSE)
all.equal(ans1, dat$reference)

Adding a new set

The easy bit; to generate responses for 1.39, from 1.38, do:

./generate.sh 1.38 1.39

Then, go to the spec page, e.g. https://docs.docker.com/engine/api/v1.39/

Open rewrite.md

For each endpoint in rewrite.md, identify the docker endpoint and copy the response sample into a json file.

Edit tests/testthat/helper-stevedore.R and lower the max version in audit_spec_response to your last good version

Run the tests:

test_file("test-spec-responses-1.39.R")

Inspect any failures, fix, repeat

Things to try:

Tickling individual failures is helpful:

dat <- read_sample_response("sample_responses/v1.39/system_df.R")
opts <- list(as_is_names = FALSE, data_frame = identity)
ans <- dat$handler(dat$response, opts)
ref <- dat$reference
all.equal(ans, ref)


richfitz/stevedore documentation built on July 22, 2023, 1:13 p.m.