From 6945b3153699fccdc626b28c77ae4daec9a17958 Mon Sep 17 00:00:00 2001 From: Adrien Castex Date: Thu, 3 Aug 2017 12:04:01 +0200 Subject: [PATCH] Added more tests for the 'Range' header --- test/v2/tests.ts/readWrite/getRanged.ts | 46 +++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/test/v2/tests.ts/readWrite/getRanged.ts b/test/v2/tests.ts/readWrite/getRanged.ts index 4868c76b..dc66aee5 100644 --- a/test/v2/tests.ts/readWrite/getRanged.ts +++ b/test/v2/tests.ts/readWrite/getRanged.ts @@ -17,13 +17,31 @@ function go(info : TestInfo, isValid : TestCallback, range : string, callback : }) }) } +function goHead(info : TestInfo, isValid : TestCallback, range : string, callback : (statusCode : number, headers : any) => void) +{ + starter(info.startServer(), info, isValid, content, (r, s) => { + info.req({ + url: 'http://localhost:' + s.options.port + '/file.txt', + method: 'HEAD', + headers: { + 'Range': range + } + }, (res) => { + callback(res.statusCode, res.headers); + }) + }) +} export default ((info, isValid) => { - const server = info.init(15); + const server = info.init(22); go(info, isValid, 'bytes=0-100', (statusCode, headers, body) => { - isValid(headers['content-length'] === content.length.toString(), 'The content length returned must be a maximum the range could retrieve, but instead of ' + content.length + ', got ' + headers['content-length'] + '.'); + isValid(headers['content-length'] === content.length.toString(), 'The content length returned must be the maximum length possible, but instead of ' + content.length + ', got ' + headers['content-length'] + '.'); + }) + + go(info, isValid, 'bytes=-100', (statusCode, headers, body) => { + isValid(headers['content-length'] === content.length.toString(), 'The content length returned must be the maximum length possible, but instead of ' + content.length + ', got ' + headers['content-length'] + '.'); }) go(info, isValid, 'bytes=0-1', (statusCode, headers, body) => { @@ -34,6 +52,30 @@ export default ((info, isValid) => isValid(headers['content-length'] === '1', 'The content length returned must be equals to 1 when 0-0 is asked, but instead of ' + 1 + ', got ' + headers['content-length'] + '.'); }) + go(info, isValid, 'bytes=-1', (statusCode, headers, body) => { + isValid(headers['content-length'] === '1', 'The content length returned must be equals to 1 when 0-0 is asked, but instead of ' + 1 + ', got ' + headers['content-length'] + '.'); + }) + + goHead(info, isValid, 'bytes=0-100', (statusCode, headers) => { + isValid(headers['content-length'] === content.length.toString(), 'The content length returned must be the maximum length possible, but instead of ' + content.length + ', got ' + headers['content-length'] + '.'); + }) + + goHead(info, isValid, 'bytes=-100', (statusCode, headers) => { + isValid(headers['content-length'] === content.length.toString(), 'The content length returned must be the maximum length possible, but instead of ' + content.length + ', got ' + headers['content-length'] + '.'); + }) + + goHead(info, isValid, 'bytes=0-1', (statusCode, headers) => { + isValid(headers['content-length'] === '2', 'The content length returned must be equals to 2 when 0-1 is asked, but instead of ' + 2 + ', got ' + headers['content-length'] + '.'); + }) + + goHead(info, isValid, 'bytes=0-0', (statusCode, headers) => { + isValid(headers['content-length'] === '1', 'The content length returned must be equals to 1 when 0-0 is asked, but instead of ' + 1 + ', got ' + headers['content-length'] + '.'); + }) + + goHead(info, isValid, 'bytes=-1', (statusCode, headers) => { + isValid(headers['content-length'] === '1', 'The content length returned must be equals to 1 when 0-0 is asked, but instead of ' + 1 + ', got ' + headers['content-length'] + '.'); + }) + go(info, isValid, 'bytes=0-100', (statusCode, headers, body) => { isValid(body === content, 'Expected "' + content + '" but got "' + body + '".'); })