[now-python] Fix headers with multiple values (#3053)

* [now-python] Add format_headers()

* Add tests

* Fix filenames

* Fix test probes
This commit is contained in:
Steven
2019-09-20 17:55:39 -04:00
parent e0b3e9606a
commit 8253e76ec0
8 changed files with 107 additions and 27 deletions

View File

@@ -93,9 +93,7 @@ async function testDeployment (
if (probe.status) {
if (probe.status !== resp.status) {
throw new Error(
`Fetched page ${probeUrl} does not return the status ${
probe.status
} Instead it has ${resp.status}`
`Fetched page ${probeUrl} does not return the status ${probe.status} Instead it has ${resp.status}`
);
}
}
@@ -107,23 +105,22 @@ async function testDeployment (
.map(([ k, v ]) => ` ${k}=${v}`)
.join('\n');
throw new Error(
`Fetched page ${probeUrl} does not contain ${probe.mustContain}.`
+ ` Instead it contains ${text.slice(0, 60)}`
+ ` Response headers:\n ${headers}`
`Fetched page ${probeUrl} does not contain ${probe.mustContain}.` +
` Instead it contains ${text.slice(0, 60)}` +
` Response headers:\n ${headers}`
);
}
} else if (probe.responseHeaders) {
// eslint-disable-next-line no-loop-func
Object.keys(probe.responseHeaders).forEach((header) => {
if (resp.headers.get(header) !== probe.responseHeaders[header]) {
const headers = Array.from(resp.headers.entries())
.map(([ k, v ]) => ` ${k}=${v}`)
.join('\n');
const actual = resp.headers.get(header);
const expected = probe.responseHeaders[header];
const isEqual = Array.isArray(expected)
? expected.every((h) => actual.includes(h))
: expected === actual;
if (!isEqual) {
throw new Error(
`Fetched page ${probeUrl} does not contain header ${header}: \`${
probe.responseHeaders[header]
}\`.\n\nResponse headers:\n ${headers}`
`Page ${probeUrl} does not have header ${header}.\n\nExpected: ${expected}.\nActual: ${headers}`
);
}
});