Skip to content

Commit

Permalink
Added more tests for the 'Range' header of the 'Get' method
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienCastex committed Aug 3, 2017
1 parent 98d16af commit 25a1cf3
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion test/v2/tests.ts/readWrite/getRanged.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function go(info : TestInfo, isValid : TestCallback, range : string, callback :

export default ((info, isValid) =>
{
const server = info.init(7);
const server = info.init(15);

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'] + '.');
Expand Down Expand Up @@ -49,5 +49,38 @@ export default ((info, isValid) =>
go(info, isValid, 'bytes=' + (content.length - 1) + '-' + (content.length - 1), (statusCode, headers, body) => {
isValid(body === '!', 'Expected "!" but got "' + body + '".');
})

go(info, isValid, 'bytes=0-', (statusCode, headers, body) => {
isValid(body === content, 'Expected "' + content + '" but got "' + body + '".');
})

go(info, isValid, 'bytes=1-', (statusCode, headers, body) => {
const expected = content.substr(1);
isValid(body === expected, 'Expected "' + expected + '" but got "' + body + '".');
})

go(info, isValid, 'bytes=100-', (statusCode, headers, body) => {
isValid(body === '', 'Expected "" but got "' + body + '".');
})

go(info, isValid, 'bytes=-0', (statusCode, headers, body) => {
isValid(body === '', 'Expected "" but got "' + body + '".');
})

go(info, isValid, 'bytes=-1', (statusCode, headers, body) => {
isValid(body === '!', 'Expected "!" but got "' + body + '".');
})

go(info, isValid, 'bytes=-100', (statusCode, headers, body) => {
isValid(body === content, 'Expected "' + content + '" but got "' + body + '".');
})

go(info, isValid, 'bytes=0-0,1-1', (statusCode, headers, body) => {
isValid(/^--[^\n]+\n[^\n]+\n[^\n]+\n\r\nH\r\n--[^\n]+\n[^\n]+\n[^\n]+\n\r\ne\r\n--[^-]+--$/.test(body), 'Expected multipart "H -- e" but got "' + body + '".');
})

go(info, isValid, 'bytes=-1,1-1', (statusCode, headers, body) => {
isValid(/^--[^\n]+\n[^\n]+\n[^\n]+\n\r\n!\r\n--[^\n]+\n[^\n]+\n[^\n]+\n\r\ne\r\n--[^-]+--$/.test(body), 'Expected multipart "! -- e" but got "' + body + '".');
})

}) as Test;

0 comments on commit 25a1cf3

Please sign in to comment.