diff --git a/lib/glob.js b/lib/glob.js index e6805aa..0a8becf 100644 --- a/lib/glob.js +++ b/lib/glob.js @@ -16,7 +16,7 @@ function statList(fsm, list, callback) { var stats = []; var total = list.length; - for (var i = 0; i < CONC; ++i) { + for (var i = 0; i < list.length && i < CONC; ++i) { handleFile(); } diff --git a/test/lib/common.js b/test/lib/common.js index e41847b..3edb0b2 100644 --- a/test/lib/common.js +++ b/test/lib/common.js @@ -73,7 +73,7 @@ var common = module.exports = { }); connection.on('command:pass', function(pass, success, failure) { if (pass === customOptions.pass) { - success(username); + success(username, customOptions.fs); } else { failure(); } diff --git a/test/list.js b/test/list.js index 31e0773..1764bf3 100644 --- a/test/list.js +++ b/test/list.js @@ -1,4 +1,5 @@ var common = require('./lib/common'); +var fs = require('fs'); describe('LIST command', function() { 'use strict'; @@ -6,81 +7,128 @@ describe('LIST command', function() { var client; var server; - beforeEach(function(done) { - server = common.server(); - client = common.client(done); - }); + describe('regular cases', function() { - function unslashRgx(rgx) { - return String(rgx).replace(/^\/|\/$/g, ''); - } - - it('should return "-" as first character for files', function(done) { - client.list('/', function(error, listing) { - error.should.equal(false); - listing = common.splitResponseLines(listing, / data\d*\.txt$/); - listing.should.have.lengthOf(6); - listing[0].should.startWith('-'); - done(); + beforeEach(function(done) { + server = common.server(); + client = common.client(done); }); - }); - it('should return "d" as first character for directories', function(done) { - client.list('/', function(error, listing) { - error.should.equal(false); - listing = common.splitResponseLines(listing, / usr$/); - listing.should.have.lengthOf(1); - listing[0].should.startWith('d'); - done(); + function unslashRgx(rgx) { + return String(rgx).replace(/^\/|\/$/g, ''); + } + + it('should return "-" as first character for files', function(done) { + client.list('/', function(error, listing) { + error.should.equal(false); + listing = common.splitResponseLines(listing, / data\d*\.txt$/); + listing.should.have.lengthOf(6); + listing[0].should.startWith('-'); + done(); + }); }); - }); - it('should list files similar to ls -l', function(done) { - client.list('/usr', function(error, listing) { - error.should.equal(false); - listing = common.splitResponseLines(listing); - listing.should.have.lengthOf(1); - var lsLongRgx = [ - /($# file modes: ___|)[d-]([r-][w-][x-]){3}/, - /($# ?¿?¿? inodes?: |)\d+/, - /($# owner name: ___|)\S+/, - /($# owner group: __|)\S+/, - /($# size in bytes: |)\d+/, - /($# month: ________|)[A-Z][a-z]{2}/, - /($# day of month: _|)\d{1,2}/, - /($# time or year: _|)([\d ]\d:|19|[2-9]\d)\d{2}/, - /($# file name: ____|)[\S\s]+/, - ].map(unslashRgx).join('\\s+'); - lsLongRgx = new RegExp(lsLongRgx, ''); - var match = (lsLongRgx.exec(listing[0]) || [false]); - match[0].should.equal(listing[0]); - done(); + it('should return "d" as first character for directories', function(done) { + client.list('/', function(error, listing) { + error.should.equal(false); + listing = common.splitResponseLines(listing, / usr$/); + listing.should.have.lengthOf(1); + listing[0].should.startWith('d'); + done(); + }); }); - }); - it('should list a single file', function(done) { - var filename = 'data.txt'; - client.list('/' + filename, function(error, listing) { - error.should.equal(false); - listing = common.splitResponseLines(listing, ' ' + filename); - listing.should.have.lengthOf(1); - listing[0].should.startWith('-'); - done(); + it('should list files similar to ls -l', function(done) { + client.list('/usr', function(error, listing) { + error.should.equal(false); + listing = common.splitResponseLines(listing); + listing.should.have.lengthOf(1); + var lsLongRgx = [ + /($# file modes: ___|)[d-]([r-][w-][x-]){3}/, + /($# ?¿?¿? inodes?: |)\d+/, + /($# owner name: ___|)\S+/, + /($# owner group: __|)\S+/, + /($# size in bytes: |)\d+/, + /($# month: ________|)[A-Z][a-z]{2}/, + /($# day of month: _|)\d{1,2}/, + /($# time or year: _|)([\d ]\d:|19|[2-9]\d)\d{2}/, + /($# file name: ____|)[\S\s]+/, + ].map(unslashRgx).join('\\s+'); + lsLongRgx = new RegExp(lsLongRgx, ''); + var match = (lsLongRgx.exec(listing[0]) || [false]); + match[0].should.equal(listing[0]); + done(); + }); }); - }); - it('should list a subdirectory', function(done) { - client.list('/usr', function(error, listing) { - error.should.equal(false); - listing = common.splitResponseLines(listing); - listing.should.have.lengthOf(1); - listing[0].should.startWith('d'); - listing[0].should.endWith(' local'); - done(); + it('should list a single file', function(done) { + var filename = 'data.txt'; + client.list('/' + filename, function(error, listing) { + error.should.equal(false); + listing = common.splitResponseLines(listing, ' ' + filename); + listing.should.have.lengthOf(1); + listing[0].should.startWith('-'); + done(); + }); + }); + + it('should list a subdirectory', function(done) { + client.list('/usr', function(error, listing) { + error.should.equal(false); + listing = common.splitResponseLines(listing); + listing.should.have.lengthOf(1); + listing[0].should.startWith('d'); + listing[0].should.endWith(' local'); + done(); + }); + }); + + afterEach(function() { + server.close(); }); }); - afterEach(function() { - server.close(); + describe('corner cases', function() { + 'use strict'; + + var files; + + beforeEach(function(done) { + server = common.server({ + fs: { + stat: function(path, callback) { + console.log('STAT', path); + callback( + undefined /* err */, + new fs.Stats(0,32768 /* file mode */,0,0,0,0,0,0,0,43 /* size */,0,0,0,0) + ); + }, + readdir: function(path, callback) { + console.log('READDIR', path); + callback(undefined, files); + }, + }, + }); + client = common.client(done); + }); + + + it.only('supports directories with only a few files', function(done) { + files = ['a']; + client.list('/', function(error, listing) { + error.should.equal(false); + console.log(listing); + listing = common.splitResponseLines(listing); + listing.should.have.lengthOf(1); + done(); + }); + }); + + afterEach(function() { + server.close(); + }); }); + + }); +