Skip to content

Commit

Permalink
expected_method
Browse files Browse the repository at this point in the history
  • Loading branch information
mnot committed Oct 17, 2020
1 parent 02d6da8 commit c0ad544
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
5 changes: 2 additions & 3 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions client/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
)
}
}
}
6 changes: 5 additions & 1 deletion lib/testsuite-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"]
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions lib/tpl/checks.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%}
Expand Down

0 comments on commit c0ad544

Please sign in to comment.