Skip to content

Commit 647a8c3

Browse files
committed
Added tests for the ranged GET
1 parent 10f0e51 commit 647a8c3

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed

test/v2/tests.ts/readWrite/.createFileTxt.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { TestCallback, TestInfo } from '../Type'
22
import { v2 } from '../../../../lib/index.js'
33

4-
export function starter(server : v2.WebDAVServer, info : TestInfo, isValid : TestCallback, content : string | Buffer, _type ?: v2.ResourceType | ((r ?: v2.Resource) => void), _callback ?: (r ?: v2.Resource) => void) : void
4+
export function starter(server : v2.WebDAVServer, info : TestInfo, isValid : TestCallback, content : string | Buffer, _type ?: v2.ResourceType | ((r ?: v2.Resource, server ?: v2.WebDAVServer) => void), _callback ?: (r ?: v2.Resource, server ?: v2.WebDAVServer) => void) : void
55
{
6-
const callback = _callback ? _callback : _type as (r ?: v2.Resource) => void;
6+
const callback = _callback ? _callback : _type as (r ?: v2.Resource, server ?: v2.WebDAVServer) => void;
77
const type = _callback ? _type as v2.ResourceType : v2.ResourceType.File;
88

99
const name = 'file.txt';
@@ -17,14 +17,14 @@ export function starter(server : v2.WebDAVServer, info : TestInfo, isValid : Tes
1717
if(e) return isValid(false, 'Could not find //' + name, e);
1818

1919
if(!type.isFile)
20-
return callback(r);
20+
return callback(r, server);
2121

2222
r.openWriteStream((e, wStream) => {
2323
if(e) return isValid(false, 'Could not open the resource for writing.', e);
2424
wStream.end(content, (e) => {
2525
if(e) return isValid(false, 'Could not write content to the resource.', e);
2626

27-
callback(r);
27+
callback(r, server);
2828
});
2929
})
3030
})
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { Test, TestCallback, TestInfo } from '../Type'
2+
import { v2 } from '../../../../lib/index.js'
3+
import { starter } from './.createFileTxt'
4+
5+
const content = 'Helio!';
6+
function go(info : TestInfo, isValid : TestCallback, range : string, callback : (statusCode : number, headers : any, body : string) => void)
7+
{
8+
starter(info.startServer(), info, isValid, content, (r, s) => {
9+
info.req({
10+
url: 'http://localhost:' + s.options.port + '/file.txt',
11+
method: 'GET',
12+
headers: {
13+
'Range': range
14+
}
15+
}, (res, body) => {
16+
callback(res.statusCode, res.headers, body);
17+
})
18+
})
19+
}
20+
21+
export default ((info, isValid) =>
22+
{
23+
const server = info.init(7);
24+
25+
go(info, isValid, 'bytes=0-100', (statusCode, headers, body) => {
26+
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'] + '.');
27+
})
28+
29+
go(info, isValid, 'bytes=0-1', (statusCode, headers, body) => {
30+
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'] + '.');
31+
})
32+
33+
go(info, isValid, 'bytes=0-0', (statusCode, headers, body) => {
34+
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'] + '.');
35+
})
36+
37+
go(info, isValid, 'bytes=0-100', (statusCode, headers, body) => {
38+
isValid(body === content, 'Expected "' + content + '" but got "' + body + '".');
39+
})
40+
41+
go(info, isValid, 'bytes=0-0', (statusCode, headers, body) => {
42+
isValid(body === 'H', 'Expected "H" but got "' + body + '".');
43+
})
44+
45+
go(info, isValid, 'bytes=1-1', (statusCode, headers, body) => {
46+
isValid(body === 'e', 'Expected "e" but got "' + body + '".');
47+
})
48+
49+
go(info, isValid, 'bytes=' + (content.length - 1) + '-' + (content.length - 1), (statusCode, headers, body) => {
50+
isValid(body === '!', 'Expected "!" but got "' + body + '".');
51+
})
52+
53+
}) as Test;

0 commit comments

Comments
 (0)