Skip to content

Commit

Permalink
Adapted the tests to the 'stream.Readable' and the 'stream.Writable' …
Browse files Browse the repository at this point in the history
…addings
  • Loading branch information
AdrienCastex committed May 30, 2017
1 parent b88370a commit 2d30e39
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
4 changes: 2 additions & 2 deletions test/tests/persistence.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = (test, options, index) => test('persistence', (isValid, server)
const server2 = new webdav.WebDAVServer();
const f1 = new webdav.VirtualFile('file1.txt');
const f1Content = 'ok, This content is the test';
f1.write(f1Content, true, e => _(e, () => {
f1.write(true, (e, stream) => _(e, () => stream.end(f1Content, (e) => _(e, () => {
server2.rootResource.addChild(f1, e => _(e, () => {
server2.rootResource.addChild(new webdav.VirtualFile('file2.txt'), e => _(e, () => {
const folder1 = new webdav.VirtualFolder('folder1');
Expand Down Expand Up @@ -56,5 +56,5 @@ module.exports = (test, options, index) => test('persistence', (isValid, server)
}));
}));
}));
}))
}))))
})
4 changes: 2 additions & 2 deletions test/tests/readVirtualFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = (test, options, index) => test('read a virtual file', (isValid,
for(const fileName in files)
{
const file = new webdav.VirtualFile(fileName);
file.write(files[fileName].toString(), true, e => _(e, () => {
file.write(true, (e, stream) => _(e, () => stream.end(files[fileName].toString(), (e) => _(e, () => {
server.rootResource.addChild(file, e => _(e, () => {
wfs.readFile('/' + fileName, (e, content) => {
if(e)
Expand All @@ -39,7 +39,7 @@ module.exports = (test, options, index) => test('read a virtual file', (isValid,
})

}));
}))
}))))
}

wfs.readFile('/fileNotFound.txt', (e, content) => {
Expand Down
36 changes: 20 additions & 16 deletions test/tests/source.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use strict";
var webdav = require('../../lib/index.js'),
request = require('request');
request = require('request'),
stream = require('stream');

module.exports = (test, options, index) => test('source', (isValid, server) =>
{
Expand Down Expand Up @@ -28,25 +29,28 @@ module.exports = (test, options, index) => test('source', (isValid, server) =>
let unprocessed = 'unprocessed content';

server.rootResource.addChild({
append(data, targetSource, callback)
write(targetSource, callback)
{
if(targetSource)
unprocessed += data;
else
processed += data;
callback(null);
},
write(data, targetSource, callback)
{
if(targetSource)
unprocessed = data;
else
processed = data;
callback(null);
callback(null, new stream.Writable({
write: (chunk, encoding, callback) => {
if(targetSource)
unprocessed = chunk;
else
processed = chunk;

callback(null);
}
}));
},
read(targetSource, callback)
{
callback(null, targetSource ? unprocessed : processed);
callback(null, new stream.Readable({
read: function(size)
{
this.push(targetSource ? unprocessed : processed);
this.push(null);
}
}));
},
webName(callback)
{
Expand Down
4 changes: 2 additions & 2 deletions test/tests/statVirtual.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = (test, options, index) => test('stat of virtual resources', (is
const folder = new webdav.VirtualFolder('testFolder');
server.rootResource.addChild(folder, e => _(e, () => {
const file = new webdav.VirtualFile('testFile.txt');
file.write(content, true, e => _(e, () => {
file.write(true, (e, stream) => _(e, () => stream.end(content, (e) => _(e, () => {
folder.addChild(file, e => _(e, () => {

var wfs = Client(
Expand All @@ -36,6 +36,6 @@ module.exports = (test, options, index) => test('stat of virtual resources', (is
isValid(!!e);
})
}));
}))
}))))
}));
})

0 comments on commit 2d30e39

Please sign in to comment.