Skip to content

Commit 25a1cf3

Browse files
committed
Added more tests for the 'Range' header of the 'Get' method
1 parent 98d16af commit 25a1cf3

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

test/v2/tests.ts/readWrite/getRanged.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function go(info : TestInfo, isValid : TestCallback, range : string, callback :
2020

2121
export default ((info, isValid) =>
2222
{
23-
const server = info.init(7);
23+
const server = info.init(15);
2424

2525
go(info, isValid, 'bytes=0-100', (statusCode, headers, body) => {
2626
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'] + '.');
@@ -49,5 +49,38 @@ export default ((info, isValid) =>
4949
go(info, isValid, 'bytes=' + (content.length - 1) + '-' + (content.length - 1), (statusCode, headers, body) => {
5050
isValid(body === '!', 'Expected "!" but got "' + body + '".');
5151
})
52+
53+
go(info, isValid, 'bytes=0-', (statusCode, headers, body) => {
54+
isValid(body === content, 'Expected "' + content + '" but got "' + body + '".');
55+
})
56+
57+
go(info, isValid, 'bytes=1-', (statusCode, headers, body) => {
58+
const expected = content.substr(1);
59+
isValid(body === expected, 'Expected "' + expected + '" but got "' + body + '".');
60+
})
61+
62+
go(info, isValid, 'bytes=100-', (statusCode, headers, body) => {
63+
isValid(body === '', 'Expected "" but got "' + body + '".');
64+
})
65+
66+
go(info, isValid, 'bytes=-0', (statusCode, headers, body) => {
67+
isValid(body === '', 'Expected "" but got "' + body + '".');
68+
})
69+
70+
go(info, isValid, 'bytes=-1', (statusCode, headers, body) => {
71+
isValid(body === '!', 'Expected "!" but got "' + body + '".');
72+
})
73+
74+
go(info, isValid, 'bytes=-100', (statusCode, headers, body) => {
75+
isValid(body === content, 'Expected "' + content + '" but got "' + body + '".');
76+
})
77+
78+
go(info, isValid, 'bytes=0-0,1-1', (statusCode, headers, body) => {
79+
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 + '".');
80+
})
81+
82+
go(info, isValid, 'bytes=-1,1-1', (statusCode, headers, body) => {
83+
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 + '".');
84+
})
5285

5386
}) as Test;

0 commit comments

Comments
 (0)