diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index cf16c28..d76792a 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -68,6 +68,7 @@ Possible members of a request object: - `not_cached`: The response is not served from cache; it comes from the origin - `lm_validated`: The response comes from cache, but was validated on the origin with Last-Modified - `etag_validated`: The response comes from cache, but was validated on the origin with an ETag +- `expected_method` - A string HTTP method; checked on the server. - `expected_status` - A numeric HTTP status code; checked on the client. If not set, the value of `response_status[0]` will be used; if that is not set, 200 will be used. @@ -85,9 +86,7 @@ Possible members of a request object: - `[header_name_string, header_value_string]`: headers to check that the response is either missing, or if they're present, that they do _not_ contain the given value string (evaluated against the whole header value). - `expected_response_text` - A string to check the response body against on the client. - `setup` - Boolean to indicate whether this is a setup request; failures don't mean the actual test failed. -- `setup_tests` - Array of values that indicate whether the specified check is part of setup; - failures don't mean the actual test failed. One of: `["expected_type", "expected_status", - "expected_response_headers", "expected_response_text", "expected_request_headers"]` +- `setup_tests` - Array of values that indicate whether the specified check is part of setup; failures don't mean the actual test failed. One of: `["expected_type", "expected_method", "expected_status", "expected_response_headers", "expected_response_text", "expected_request_headers"]` `server.js` stashes an entry containing observed headers for each request it receives. When the test fetches have run, this state is retrieved and the expected_* lists are checked, including diff --git a/client/test.mjs b/client/test.mjs index 6ee0135..e7c26dd 100644 --- a/client/test.mjs +++ b/client/test.mjs @@ -266,5 +266,12 @@ function checkServerRequests (requests, responses, serverState) { `Response ${reqNum} header ${header[0]} is "${received}", not "${header[1]}"`) }) } + if ('expected_method' in reqConfig) { + assert( + setupCheck(reqConfig, 'expected_method'), + serverRequest.request_method === reqConfig.expected_method, + `Request ${reqNum} had method ${serverRequest.request_method}, not ${reqConfig.expected_method}` + ) + } } } diff --git a/lib/testsuite-schema.json b/lib/testsuite-schema.json index 51a1e4f..3adc37c 100644 --- a/lib/testsuite-schema.json +++ b/lib/testsuite-schema.json @@ -195,6 +195,10 @@ "type": "string", "enum": ["cached", "not_cached", "lm_validated", "etag_validated"] }, + "expected_method": { + "description": "Expected request method received by the server", + "type": "string" + }, "expected_status": { "description": "Expected response status received by the client", "$ref": "#/definitions/status-code" @@ -315,7 +319,7 @@ "type": "array", "items": { "type": "string", - "enum": ["expected_type", "expected_status", "expected_response_headers", "expected_response_text", "expected_request_headers"] + "enum": ["expected_type", "expected_method", "expected_status", "expected_response_headers", "expected_response_text", "expected_request_headers"] } } } diff --git a/lib/tpl/checks.liquid b/lib/tpl/checks.liquid index 9ab695d..290d72e 100644 --- a/lib/tpl/checks.liquid +++ b/lib/tpl/checks.liquid @@ -10,6 +10,9 @@ {%- if request.expected_type %} - The client will check that this response {% case request.expected_type %}{% when "cached" %}is cached{% when "not_cached" %}is not cached{% when "lm_validated" %}is validated using `Last-Modified`{% when "etag_validated" %}is validated using `ETag`{% endcase %} {% if test.setup_tests contains "expected_type" %}{{ setup_prop }}{% endif %}{% endif -%} +{%- if request.expected_method %} +- The server will check that the request method is `{{ request.expected_method }}`.{% endif -%} + {%- if request.expected_request_headers.size > 0 %} - The server will check that the following request headers (and values, when specified) are present{% if test.setup_tests contains "expected_request_headers" %}{{ setup_prop }}{% endif %}: {%- render 'header-list' with request.expected_request_headers as headers %}{% endif -%}