Skip to content

Commit

Permalink
Test command implemented with Promises
Browse files Browse the repository at this point in the history
  • Loading branch information
q2s2t committed Aug 11, 2014
1 parent 669ccee commit 6980b13
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
26 changes: 26 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

var Promise = require('promise');
var process = require('child_process');
var os = require('os');
var path = require('path');

module.exports.test = function test(archivePath) {

return new Promise(function (fulfill, reject){
var command = '7z t ' + archivePath;
process.exec(command, function (err, stdout, stderr) {
//TODO: Custom error
if (err) return reject(err);
if (stderr) return reject(stderr);
var r = [];
stdout.split(os.EOL).forEach(function (_line) {
if (_line.substr(0, 12) === 'Testing ') {
return r.push(_line.substr(12, _line.length).replace(path.sep, '/'));
}
});
return fulfill(r);
});
});

};
23 changes: 23 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';
var sevenzip = require('../index');
var expect = require('chai').expect;

describe('Specifications for the `test` function', function(){

it('should get an error when 7z gets an error', function (done) {
sevenzip.test('test/resource/nothere.7z')
.then(null, function (err) {
expect(err.message.substr(0, 14)).to.eql('Command failed');
done();
});
});

it('should get a list of files and directories', function (done) {
sevenzip.test('test/resource/resource.7z')
.then(function (files) {
expect(files.length).to.be.at.least(6);
done();
});
});

});

0 comments on commit 6980b13

Please sign in to comment.