Comparing version 0.1.5 to 0.1.6
@@ -7,2 +7,5 @@ // fileserver | ||
var path = require('path'); | ||
var mw = require('dat-middleware'); | ||
var flow = require('middleware-flow'); | ||
/* used to modify format out output of data; | ||
@@ -12,2 +15,4 @@ input of function is full filepath | ||
var modifyOut = null; | ||
var isJson = mw.req('headers[\'content-type\']').matches(/application\/json/); | ||
var fileserver = function(app) { | ||
@@ -18,3 +23,7 @@ if (!app) { | ||
app.use(bodyParser.json()); | ||
app.use(flow.mwIf(isJson) | ||
.then(bodyParser.json()) | ||
.else(bodyParser.raw())); | ||
app.use(bodyParser.urlencoded({ | ||
@@ -117,3 +126,3 @@ extended: true | ||
res.set('Content-Type', mime.lookup(filePath)); | ||
res.set('content-type', mime.lookup(filePath)); | ||
res.status(200).send(data); | ||
@@ -144,2 +153,7 @@ }); | ||
var postFileOrDir = function (req, res, next) { | ||
var isJson = false; | ||
if (req.headers['content-type'] === 'string') { | ||
isJson = req.headers['content-type'].matches(/application\/json/); | ||
} | ||
var dirPath = decodeURI(url.parse(req.url).pathname); | ||
@@ -163,3 +177,7 @@ var isDir = dirPath.substr(-1) == '/'; | ||
options.encoding = req.body.encoding || 'utf8'; | ||
options.mode = req.body.mode || 438; | ||
options.mode = req.body.mode || 438; | ||
if (!isJson) { | ||
return fileDriver.writeFileStream(dirPath, req); | ||
} | ||
var data = req.body.content || ''; | ||
@@ -166,0 +184,0 @@ fileDriver.writeFile(dirPath, data, options, |
@@ -91,2 +91,15 @@ // fsDriver | ||
/* | ||
write file with stream | ||
*/ | ||
var writeFileStream = function(filepath, stream, options, cb) { | ||
try { | ||
var file = fs.createWriteStream(filepath, options); | ||
stream.pipe(file); | ||
cb(); | ||
} catch(err) { | ||
cb(err); | ||
} | ||
}; | ||
/* | ||
delete file | ||
@@ -142,1 +155,2 @@ */ | ||
module.exports.move = move; | ||
module.exports.writeFileStream = writeFileStream; |
{ | ||
"name": "rest-fs", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"description": "restful fileserver", | ||
@@ -33,3 +33,6 @@ "main": "fileserver.js", | ||
"rimraf": "^2.2.8", | ||
"mime": "^1.2.11" | ||
"mime": "^1.2.11", | ||
"request": "^2.40.0", | ||
"dat-middleware": "^1.8.1", | ||
"middleware-flow": "^0.5.1" | ||
}, | ||
@@ -36,0 +39,0 @@ "devDependencies": { |
var Lab = require('lab'); | ||
var lab = exports.lab = Lab.script(); | ||
var fs = require('fs'); | ||
@@ -36,6 +37,6 @@ var express = require('express'); | ||
Lab.before(function (done) { | ||
lab.before(function (done) { | ||
cleanBase(done); | ||
}); | ||
Lab.after(function (done) { | ||
lab.after(function (done) { | ||
rimraf(baseDir, done); | ||
@@ -186,19 +187,19 @@ }); | ||
Lab.experiment('create tests', function () { | ||
Lab.beforeEach(function (done) { | ||
lab.experiment('create tests', function () { | ||
lab.beforeEach(function (done) { | ||
cleanBase(done); | ||
}); | ||
Lab.test('create dir POST', function (done) { | ||
lab.test('create dir POST', function (done) { | ||
var dirpath = baseDir+'/dir2/'; | ||
createDirPost(dirpath, done); | ||
}); | ||
Lab.test('create dir POST with mode 400', function (done) { | ||
lab.test('create dir POST with mode 400', function (done) { | ||
var dirpath = baseDir+'/dir2/'; | ||
createDirPost(dirpath, {mode: 400}, done); | ||
}); | ||
Lab.test('create dir PUT', function (done) { | ||
lab.test('create dir PUT', function (done) { | ||
var dirpath = baseDir+'/dir2/'; | ||
createDir(dirpath, done); | ||
}); | ||
Lab.test('create dir PUT with mode 400', function (done) { | ||
lab.test('create dir PUT with mode 400', function (done) { | ||
var dirpath = baseDir+'/dir2/'; | ||
@@ -210,7 +211,7 @@ createDir(dirpath, {mode: 400}, done); | ||
Lab.experiment('delete tests', function () { | ||
Lab.beforeEach(function (done) { | ||
lab.experiment('delete tests', function () { | ||
lab.beforeEach(function (done) { | ||
cleanBase(done); | ||
}); | ||
Lab.test('delete dir', function (done) { | ||
lab.test('delete dir', function (done) { | ||
var dirpath = baseDir+'/dir2/'; | ||
@@ -242,3 +243,3 @@ createDir(dirpath, function(err) { | ||
Lab.test('delete nonexiting dir', function (done) { | ||
lab.test('delete nonexiting dir', function (done) { | ||
var dirpath = baseDir+'/dir2/fake/'; | ||
@@ -265,3 +266,3 @@ supertest(server) | ||
Lab.test('attempt to delete file with trailing slash', function (done) { | ||
lab.test('attempt to delete file with trailing slash', function (done) { | ||
var filePath = baseDir+'/file'; | ||
@@ -277,3 +278,3 @@ createFile(filePath, "test", function (err) { | ||
Lab.test('attempt to a folder with files and folders in it without clobber', function (done) { | ||
lab.test('attempt to a folder with files and folders in it without clobber', function (done) { | ||
var dir1 = baseDir+'/dir1/'; | ||
@@ -333,3 +334,3 @@ var file1 = dir1+'/file1'; | ||
Lab.test('attempt to a folder with files and folders in it with clobber', function (done) { | ||
lab.test('attempt to a folder with files and folders in it with clobber', function (done) { | ||
var dir1 = baseDir+'/dir1/'; | ||
@@ -391,3 +392,3 @@ var file1 = dir1+'/file1'; | ||
Lab.experiment('read tests', function () { | ||
lab.experiment('read tests', function () { | ||
var dir2R = baseDir+'/dir2'; | ||
@@ -401,3 +402,3 @@ var dir2 = dir2R+'/'; | ||
Lab.beforeEach(function (done) { | ||
lab.beforeEach(function (done) { | ||
async.series([ | ||
@@ -422,3 +423,3 @@ function(cb) { | ||
Lab.test('get dir ls', function (done) { | ||
lab.test('get dir ls', function (done) { | ||
supertest(server) | ||
@@ -437,3 +438,3 @@ .get(dir2) | ||
Lab.test('test setModifyOut', function (done) { | ||
lab.test('test setModifyOut', function (done) { | ||
var server2 = express(); | ||
@@ -462,3 +463,3 @@ server2.use(function(req, res, next) { | ||
Lab.test('get filled dir ls', function (done) { | ||
lab.test('get filled dir ls', function (done) { | ||
supertest(server) | ||
@@ -477,3 +478,3 @@ .get(baseDir+'/') | ||
Lab.test('get dir ls recursive', function (done) { | ||
lab.test('get dir ls recursive', function (done) { | ||
supertest(server) | ||
@@ -493,3 +494,3 @@ .get(baseDir+'/') | ||
Lab.test('get empty dir ls', function (done) { | ||
lab.test('get empty dir ls', function (done) { | ||
supertest(server) | ||
@@ -508,3 +509,3 @@ .get(dir1) | ||
Lab.test('get dir ls with redirect', function (done) { | ||
lab.test('get dir ls with redirect', function (done) { | ||
supertest(server) | ||
@@ -523,3 +524,3 @@ .get(dir2R) | ||
Lab.test('get empty dir ls with redirect', function (done) { | ||
lab.test('get empty dir ls with redirect', function (done) { | ||
supertest(server) | ||
@@ -538,3 +539,3 @@ .get(dir1D) | ||
Lab.test('get dir which does not exist', function (done) { | ||
lab.test('get dir which does not exist', function (done) { | ||
supertest(server) | ||
@@ -547,3 +548,3 @@ .get(dir1D+"/fake/") | ||
Lab.experiment('move tests', function () { | ||
lab.experiment('move tests', function () { | ||
var dir1 = baseDir+'/dir1/'; | ||
@@ -561,3 +562,3 @@ var dir2 = baseDir+'/dir2/'; // empty | ||
Lab.beforeEach(function (done) { | ||
lab.beforeEach(function (done) { | ||
async.series([ | ||
@@ -591,9 +592,9 @@ function(cb) { | ||
Lab.test('move empty dir in same dir (rename) with trailing slash', function (done) { | ||
lab.test('move empty dir in same dir (rename) with trailing slash', function (done) { | ||
moveDir(dir2, baseDir+'/new/', false, false, done); | ||
}); | ||
Lab.test('move empty dir in same dir (rename) without trailing slash', function (done) { | ||
lab.test('move empty dir in same dir (rename) without trailing slash', function (done) { | ||
moveDir(dir2, baseDir+'/new', false, false, done); | ||
}); | ||
Lab.test('move empty dir to itself', function (done) { | ||
lab.test('move empty dir to itself', function (done) { | ||
moveDir(dir2, dir2, false, false, function(err) { | ||
@@ -609,12 +610,12 @@ if(err) { | ||
}); | ||
Lab.test('move empty dir to same dir with similar name', function (done) { | ||
lab.test('move empty dir to same dir with similar name', function (done) { | ||
moveDir(dir2, dir2.substr(0, dir2.length - 1)+"add", false, false, done); | ||
}); | ||
Lab.test('move empty dir into a dir with trailing slash', function (done) { | ||
lab.test('move empty dir into a dir with trailing slash', function (done) { | ||
moveDir(dir2, dir1+'new/', false, false, done); | ||
}); | ||
Lab.test('move empty dir into a dir without trailing slash', function (done) { | ||
lab.test('move empty dir into a dir without trailing slash', function (done) { | ||
moveDir(dir2, dir1+'new', false, false, done); | ||
}); | ||
Lab.test('move empty dir into itself', function (done) { | ||
lab.test('move empty dir into itself', function (done) { | ||
moveDir(dir2, dir2+'new/', false, false, function(err) { | ||
@@ -631,3 +632,3 @@ if(err) { | ||
Lab.test('move empty dir out of dir', function (done) { | ||
lab.test('move empty dir out of dir', function (done) { | ||
moveDir(dir2, dir1+'new/', false, false, function(err) { | ||
@@ -639,3 +640,3 @@ if (err) return done(err); | ||
Lab.test('move empty dir onto existing dir', function (done) { | ||
lab.test('move empty dir onto existing dir', function (done) { | ||
moveDir(dir2, dir1, false, false, function(err) { | ||
@@ -652,7 +653,7 @@ if(err) { | ||
Lab.test('move empty dir onto existing dir with clobber', function (done) { | ||
lab.test('move empty dir onto existing dir with clobber', function (done) { | ||
moveDir(dir2, dir1, true, false, done); | ||
}); | ||
Lab.test('move empty dir into non existing dir', function (done) { | ||
lab.test('move empty dir into non existing dir', function (done) { | ||
moveDir(dir2, dir1+'fake/dir/', false, false, function(err) { | ||
@@ -669,3 +670,3 @@ if(err) { | ||
Lab.test('move non existing dir into existing dir', function (done) { | ||
lab.test('move non existing dir into existing dir', function (done) { | ||
moveDir(dir2+'fake/dir/', dir1, false, false, function(err) { | ||
@@ -682,3 +683,3 @@ if(err) { | ||
Lab.test('move non existing dir into non existing dir', function (done) { | ||
lab.test('move non existing dir into non existing dir', function (done) { | ||
moveDir(dir2+'fake/dir/', dir1+'fake/dir/', false, false, function(err) { | ||
@@ -695,7 +696,7 @@ if(err) { | ||
Lab.test('move empty dir into non existing dir with mkdirp', function (done) { | ||
lab.test('move empty dir into non existing dir with mkdirp', function (done) { | ||
moveDir(dir2, dir1+'fake/dir/', false, true, done); | ||
}); | ||
Lab.test('move empty dir into non existing long dir with mkdirp', function (done) { | ||
lab.test('move empty dir into non existing long dir with mkdirp', function (done) { | ||
moveDir(dir2, dir1+'fake/long/long/long/dir/', false, true, done); | ||
@@ -705,15 +706,15 @@ }); | ||
// now try with full dir | ||
Lab.test('move dir in same dir (rename) with trailing slash', function (done) { | ||
lab.test('move dir in same dir (rename) with trailing slash', function (done) { | ||
moveDir(dir1, baseDir+'/new/', false, false, done); | ||
}); | ||
Lab.test('move dir in same dir (rename) without trailing slash', function (done) { | ||
lab.test('move dir in same dir (rename) without trailing slash', function (done) { | ||
moveDir(dir1, baseDir+'/new', false, false, done); | ||
}); | ||
Lab.test('move dir into a dir with trailing slash', function (done) { | ||
lab.test('move dir into a dir with trailing slash', function (done) { | ||
moveDir(dir1, dir2+'new/', false, false, done); | ||
}); | ||
Lab.test('move dir into a dir without trailing slash', function (done) { | ||
lab.test('move dir into a dir without trailing slash', function (done) { | ||
moveDir(dir1, dir2+'new', false, false, done); | ||
}); | ||
Lab.test('move dir to itself', function (done) { | ||
lab.test('move dir to itself', function (done) { | ||
moveDir(dir1, dir1, false, false, function(err) { | ||
@@ -729,6 +730,6 @@ if(err) { | ||
}); | ||
Lab.test('move dir to same dir with similar name', function (done) { | ||
lab.test('move dir to same dir with similar name', function (done) { | ||
moveDir(dir1, dir1.substr(0, dir2.length - 1)+"add", false, false, done); | ||
}); | ||
Lab.test('move dir to itself', function (done) { | ||
lab.test('move dir to itself', function (done) { | ||
moveDir(dir1, dir1, false, false, function(err) { | ||
@@ -745,3 +746,3 @@ if(err) { | ||
Lab.test('move dir into itself', function (done) { | ||
lab.test('move dir into itself', function (done) { | ||
moveDir(dir1, dir1+'new/', false, false, function(err) { | ||
@@ -758,3 +759,3 @@ if(err) { | ||
Lab.test('move dir out of dir', function (done) { | ||
lab.test('move dir out of dir', function (done) { | ||
moveDir(dir1, dir2+'new/', false, false, function(err) { | ||
@@ -766,3 +767,3 @@ if (err) return done(err); | ||
Lab.test('move dir onto existing dir', function (done) { | ||
lab.test('move dir onto existing dir', function (done) { | ||
moveDir(dir1, dir2, false, false, function(err) { | ||
@@ -779,7 +780,7 @@ if(err) { | ||
Lab.test('move dir onto existing dir with clobber', function (done) { | ||
lab.test('move dir onto existing dir with clobber', function (done) { | ||
moveDir(dir1, dir2, true, false, done); | ||
}); | ||
Lab.test('move dir into non existing dir', function (done) { | ||
lab.test('move dir into non existing dir', function (done) { | ||
moveDir(dir1, dir2+'fake/dir/', false, false, function(err) { | ||
@@ -796,11 +797,11 @@ if(err) { | ||
Lab.test('move dir into non existing dir with mkdirp', function (done) { | ||
lab.test('move dir into non existing dir with mkdirp', function (done) { | ||
moveDir(dir1, dir2+'fake/dir/', false, true, done); | ||
}); | ||
Lab.test('move dir into non existing long dir with mkdirp', function (done) { | ||
lab.test('move dir into non existing long dir with mkdirp', function (done) { | ||
moveDir(dir1, dir2+'fake/long/long/long/dir/', false, true, done); | ||
}); | ||
Lab.test('clober from inside dir to an empty one above it', function (done) { | ||
lab.test('clober from inside dir to an empty one above it', function (done) { | ||
moveDir(dir1_dir1, dir2, false, false, function(err) { | ||
@@ -817,7 +818,7 @@ if(err) { | ||
Lab.test('clober from inside dir to an empty one above it with clober', function (done) { | ||
lab.test('clober from inside dir to an empty one above it with clober', function (done) { | ||
moveDir(dir1_dir1, dir2, true, false, done); | ||
}); | ||
Lab.test('clober from inside dir to an full one above it', function (done) { | ||
lab.test('clober from inside dir to an full one above it', function (done) { | ||
moveDir(dir1_dir1, dir3, false, false, function(err) { | ||
@@ -834,3 +835,3 @@ if(err) { | ||
Lab.test('clober from inside dir to an full one above it with clobber', function (done) { | ||
lab.test('clober from inside dir to an full one above it with clobber', function (done) { | ||
moveDir(dir1_dir1, dir3, true, false, done); | ||
@@ -837,0 +838,0 @@ }); |
var Lab = require('lab'); | ||
var lab = exports.lab = Lab.script(); | ||
var fs = require('fs'); | ||
@@ -11,6 +12,8 @@ var express = require('express'); | ||
var rimraf = require('rimraf'); | ||
Lab.before(function (done) { | ||
var request = require('request'); | ||
lab.before(function (done) { | ||
cleanBase(done); | ||
}); | ||
Lab.after(function (done) { | ||
lab.after(function (done) { | ||
rimraf(baseFolder, done); | ||
@@ -24,3 +27,3 @@ }); | ||
} | ||
var testPort = 52232; | ||
function createFile(filepath, opts, cb) { | ||
@@ -124,8 +127,8 @@ if(typeof opts === 'function') { | ||
Lab.experiment('basic create tests', function () { | ||
Lab.beforeEach(function (done) { | ||
lab.experiment('basic create tests', function () { | ||
lab.beforeEach(function (done) { | ||
cleanBase(done); | ||
}); | ||
Lab.test('create empty file PUT', function (done) { | ||
lab.test('create empty file PUT', function (done) { | ||
var filepath = baseFolder+'/test_file.txt'; | ||
@@ -135,3 +138,3 @@ createFile(filepath, done); | ||
Lab.test('create empty file POST', function (done) { | ||
lab.test('create empty file POST', function (done) { | ||
var filepath = baseFolder+'/test_file.txt'; | ||
@@ -141,3 +144,3 @@ createFilePost(filepath, done); | ||
Lab.test('create empty file POST w/ encoding', function (done) { | ||
lab.test('create empty file POST w/ encoding', function (done) { | ||
var filepath = baseFolder+'/test_file.txt'; | ||
@@ -147,3 +150,3 @@ createFilePost(filepath, {encoding: "utf8"}, done); | ||
Lab.test('create empty file POST w/ mode', function (done) { | ||
lab.test('create empty file POST w/ mode', function (done) { | ||
var filepath = baseFolder+'/test_file.txt'; | ||
@@ -153,3 +156,3 @@ createFilePost(filepath, {mode: 777}, done); | ||
Lab.test('create empty file POST w/ content', function (done) { | ||
lab.test('create empty file POST w/ content', function (done) { | ||
var filepath = baseFolder+'/test_file.txt'; | ||
@@ -159,3 +162,3 @@ createFilePost(filepath, {content: "testText"}, done); | ||
Lab.test('create empty file PUT w/ encoding', function (done) { | ||
lab.test('create empty file PUT w/ encoding', function (done) { | ||
var filepath = baseFolder+'/test_file.txt'; | ||
@@ -165,3 +168,3 @@ createFile(filepath, {encoding: "utf8"}, done); | ||
Lab.test('create empty file PUT w/ mode', function (done) { | ||
lab.test('create empty file PUT w/ mode', function (done) { | ||
var filepath = baseFolder+'/test_file.txt'; | ||
@@ -171,3 +174,3 @@ createFile(filepath, {mode: 777}, done); | ||
Lab.test('create file with spaces in filename PUT', function (done) { | ||
lab.test('create file with spaces in filename PUT', function (done) { | ||
var filepath = baseFolder+'/test file.txt'; | ||
@@ -177,3 +180,3 @@ createFile(filepath, done); | ||
Lab.test('create file with text PUT', function (done) { | ||
lab.test('create file with text PUT', function (done) { | ||
var filepath = baseFolder+'/test_file.txt'; | ||
@@ -196,3 +199,3 @@ var testText = "test"; | ||
Lab.test('create file with text and spaces in file name PUT', function (done) { | ||
lab.test('create file with text and spaces in file name PUT', function (done) { | ||
var filepath = baseFolder+'/test file.txt'; | ||
@@ -215,3 +218,3 @@ var testText = "test"; | ||
Lab.test('create file in path that does not exist PUT', function (done) { | ||
lab.test('create file in path that does not exist PUT', function (done) { | ||
var filepath = baseFolder+'/fake/test_file.txt'; | ||
@@ -229,3 +232,3 @@ createFile(filepath, | ||
Lab.test('overwrite file PUT', function (done) { | ||
lab.test('overwrite file PUT', function (done) { | ||
var filepath = baseFolder+'/test_file.txt'; | ||
@@ -274,8 +277,8 @@ var testText = "test"; | ||
} | ||
Lab.experiment('basic delete tests', function () { | ||
Lab.beforeEach(function (done) { | ||
lab.experiment('basic delete tests', function () { | ||
lab.beforeEach(function (done) { | ||
cleanBase(done); | ||
}); | ||
Lab.test('delete file', function (done) { | ||
lab.test('delete file', function (done) { | ||
var filepath = baseFolder+'/test_file.txt'; | ||
@@ -290,3 +293,3 @@ createFile(filepath, function(err) { | ||
Lab.test('delete file with trailing slash', function (done) { | ||
lab.test('delete file with trailing slash', function (done) { | ||
var filepath = baseFolder+'/test_file.txt'; | ||
@@ -305,3 +308,3 @@ createFile(filepath, function(err) { | ||
Lab.test('delete file that does not exist', function (done) { | ||
lab.test('delete file that does not exist', function (done) { | ||
rmFile(baseFolder+'/fake.txt', function (err, res) { | ||
@@ -316,3 +319,3 @@ if (err) { | ||
Lab.test('try to delete folder with file api', function (done) { | ||
lab.test('try to delete folder with file api', function (done) { | ||
rmFile(baseFolder, function (err, res) { | ||
@@ -330,3 +333,3 @@ if (err) { | ||
Lab.experiment('read tests', function () { | ||
lab.experiment('read tests', function () { | ||
var file1path = baseFolder+'/test_file1.txt'; | ||
@@ -336,3 +339,3 @@ var file2path = baseFolder+'/test_file2.txt'; | ||
Lab.before(function (done) { | ||
lab.before(function (done) { | ||
async.series([ | ||
@@ -351,7 +354,7 @@ function(cb) { | ||
Lab.after(function (done) { | ||
lab.after(function (done) { | ||
cleanBase(done); | ||
}); | ||
Lab.test('read file', function (done) { | ||
lab.test('read file', function (done) { | ||
supertest(server) | ||
@@ -370,3 +373,3 @@ .get(file2path) | ||
Lab.test('read file utf8', function (done) { | ||
lab.test('read file utf8', function (done) { | ||
supertest(server) | ||
@@ -386,3 +389,3 @@ .get(file2path) | ||
Lab.test('read empty file', function (done) { | ||
lab.test('read empty file', function (done) { | ||
supertest(server) | ||
@@ -401,3 +404,3 @@ .get(file1path) | ||
Lab.test('read file with redirect', function (done) { | ||
lab.test('read file with redirect', function (done) { | ||
supertest(server) | ||
@@ -416,3 +419,3 @@ .get(file2path+'/') | ||
Lab.test('read empty file with redirect', function (done) { | ||
lab.test('read empty file with redirect', function (done) { | ||
supertest(server) | ||
@@ -431,3 +434,3 @@ .get(file1path+'/') | ||
Lab.test('read file that does not exist', function (done) { | ||
lab.test('read file that does not exist', function (done) { | ||
supertest(server) | ||
@@ -445,3 +448,3 @@ .get(file1path+'.fake.txt') | ||
Lab.experiment('move tests', function () { | ||
lab.experiment('move tests', function () { | ||
var dir1path = baseFolder+'/test_dir1/'; | ||
@@ -453,3 +456,3 @@ var dir2path = baseFolder+'/test_dir2/'; | ||
Lab.before(function (done) { | ||
lab.before(function (done) { | ||
async.series([ | ||
@@ -470,23 +473,23 @@ function(cb) { | ||
}); | ||
Lab.after(function (done) { | ||
lab.after(function (done) { | ||
cleanBase(done); | ||
}); | ||
Lab.test('move file in same directory (rename)', function (done) { | ||
lab.test('move file in same directory (rename)', function (done) { | ||
moveFile(file1path, file1path+'.test', false, false, done); | ||
}); | ||
Lab.test('move file into directory', function (done) { | ||
lab.test('move file into directory', function (done) { | ||
moveFile(file1path+'.test', dir1path+'/test_file1.txt.test', false, false, done); | ||
}); | ||
Lab.test('move file into another directory', function (done) { | ||
lab.test('move file into another directory', function (done) { | ||
moveFile(dir1path+'/test_file1.txt.test', dir2path+'/test_file1.txt.test', false, false, done); | ||
}); | ||
Lab.test('move file out of directory', function (done) { | ||
lab.test('move file out of directory', function (done) { | ||
moveFile(dir2path+'/test_file1.txt.test', file1path, false, false, done); | ||
}); | ||
Lab.test('move file over existing file', function (done) { | ||
lab.test('move file over existing file', function (done) { | ||
moveFile(file1path, file2path, false, false, function(err) { | ||
@@ -503,7 +506,7 @@ if(err) { | ||
Lab.test('move file over existing file with clobber', function (done) { | ||
lab.test('move file over existing file with clobber', function (done) { | ||
moveFile(file1path, file2path, true, false, done); | ||
}); | ||
Lab.test('move file to nonexisting path', function (done) { | ||
lab.test('move file to nonexisting path', function (done) { | ||
moveFile(file2path, baseFolder+'/fake/path.txt', false, false, function(err) { | ||
@@ -520,3 +523,3 @@ if(err) { | ||
Lab.test('move file to nonexisting path with clober', function (done) { | ||
lab.test('move file to nonexisting path with clober', function (done) { | ||
moveFile(file2path, baseFolder+'/fake/path.txt', true, false, function(err) { | ||
@@ -533,5 +536,54 @@ if(err) { | ||
Lab.test('move file to nonexisting path with mkdirp', function (done) { | ||
lab.test('move file to nonexisting path with mkdirp', function (done) { | ||
moveFile(file2path, baseFolder+'/new/test.txt', false, true, done); | ||
}); | ||
}); | ||
lab.experiment('stream tests', function () { | ||
lab.test('POST - stream file', function (done) { | ||
var dataFile = baseFolder+'/data.txt'; | ||
var testText = 'lots of text'; | ||
var testFile = baseFolder+'/stream_test.txt'; | ||
fs.writeFileSync(dataFile, testText); | ||
var app = server.listen(testPort, | ||
function() { | ||
fs.createReadStream(dataFile) | ||
.pipe(request.post('http://localhost:'+testPort+testFile)) | ||
.on('end', function(err, res) { | ||
app.close(function() { | ||
if (err) { | ||
return done(err); | ||
} | ||
var data = fs.readFileSync(testFile); | ||
Lab.expect(data.toString()).to.equal(testText); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
lab.test('POST - stream existing file', function (done) { | ||
var dataFile = baseFolder+'/data.txt'; | ||
var testText = 'lots of text'; | ||
var testFile = baseFolder+'/stream_test.txt'; | ||
fs.writeFileSync(dataFile, testText); | ||
fs.writeFileSync(testFile, testText); | ||
var app = server.listen(testPort, | ||
function() { | ||
fs.createReadStream(dataFile) | ||
.pipe(request.post('http://localhost:'+testPort+testFile)) | ||
.on('end', function(err, res) { | ||
app.close(function() { | ||
if (err) { | ||
return done(err); | ||
} | ||
var data = fs.readFileSync(testFile); | ||
Lab.expect(data.toString()).to.equal(testText); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
var Lab = require('lab'); | ||
var lab = exports.lab = Lab.script(); | ||
var restfs = require('../fileserver.js'); | ||
@@ -7,4 +8,4 @@ var express = require('express'); | ||
Lab.experiment('create tests', function () { | ||
Lab.test('try to create without express app', function (done) { | ||
lab.experiment('create tests', function () { | ||
lab.test('try to create without express app', function (done) { | ||
try { | ||
@@ -11,0 +12,0 @@ restfs(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59104
1665
9
+ Addeddat-middleware@^1.8.1
+ Addedmiddleware-flow@^0.5.1
+ Addedrequest@^2.40.0
+ Added101@0.6.01.6.3(transitive)
+ Addedajv@6.12.6(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedboom@2.4.2(transitive)
+ Addedcallback-count@0.0.3(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedclone@0.1.191.0.4(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddat-middleware@1.10.4(transitive)
+ Addeddeep-eql@0.1.3(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhoek@2.16.3(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedkeypather@1.10.2(transitive)
+ Addedmiddleware-flow@0.5.10.6.1(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedpsl@1.15.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.5.3(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addedtype-detect@0.1.1(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedverror@1.10.0(transitive)