filer/tests/spec/shell/cat.spec.js

83 lines
2.1 KiB
JavaScript
Raw Normal View History

2014-05-23 20:53:50 +00:00
var util = require('../../lib/test-utils.js');
var expect = require('chai').expect;
2014-02-18 19:51:06 +00:00
2014-05-23 20:53:50 +00:00
describe('FileSystemShell.cat', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
2014-02-18 19:51:06 +00:00
2014-05-23 20:53:50 +00:00
it('should be a function', function() {
var shell = util.shell();
expect(shell.cat).to.be.a('function');
});
it('should fail when files argument is absent', function(done) {
2018-12-21 01:11:51 +00:00
var shell = util.shell();
2014-05-23 20:53:50 +00:00
shell.cat(null, function(error, data) {
expect(error).to.exist;
expect(error.code).to.equal('EINVAL');
2014-05-23 20:53:50 +00:00
expect(data).not.to.exist;
done();
2014-02-18 19:51:06 +00:00
});
2014-05-23 20:53:50 +00:00
});
it('should return the contents of a single file', function(done) {
var fs = util.fs();
2018-12-21 01:11:51 +00:00
var shell = util.shell();
var contents = 'file contents';
2014-02-18 19:51:06 +00:00
2014-05-23 20:53:50 +00:00
fs.writeFile('/file', contents, function(err) {
if(err) throw err;
2014-02-18 19:51:06 +00:00
2014-05-23 20:53:50 +00:00
shell.cat('/file', function(err, data) {
expect(err).not.to.exist;
expect(data).to.equal(contents);
2014-02-18 19:51:06 +00:00
done();
});
});
2014-05-23 20:53:50 +00:00
});
it('should return the contents of multiple files', function(done) {
var fs = util.fs();
2018-12-21 01:11:51 +00:00
var shell = util.shell();
var contents = 'file contents';
2014-05-23 20:53:50 +00:00
var contents2 = contents + '\n' + contents;
2014-02-18 19:51:06 +00:00
2014-05-23 20:53:50 +00:00
fs.writeFile('/file', contents, function(err) {
if(err) throw err;
2014-02-18 19:51:06 +00:00
2014-05-23 20:53:50 +00:00
fs.writeFile('/file2', contents2, function(err) {
2014-02-18 19:51:06 +00:00
if(err) throw err;
2014-05-23 20:53:50 +00:00
shell.cat(['/file', '/file2'], function(err, data) {
2014-02-18 19:51:06 +00:00
expect(err).not.to.exist;
2014-05-23 20:53:50 +00:00
expect(data).to.equal(contents + '\n' + contents2);
2014-02-18 19:51:06 +00:00
done();
});
});
});
2014-05-23 20:53:50 +00:00
});
2014-02-18 19:51:06 +00:00
2014-05-23 20:53:50 +00:00
it('should fail if any of multiple file paths is invalid', function(done) {
var fs = util.fs();
2018-12-21 01:11:51 +00:00
var shell = util.shell();
var contents = 'file contents';
2014-05-23 20:53:50 +00:00
var contents2 = contents + '\n' + contents;
2014-02-18 19:51:06 +00:00
2014-05-23 20:53:50 +00:00
fs.writeFile('/file', contents, function(err) {
if(err) throw err;
2014-02-18 19:51:06 +00:00
2014-05-23 20:53:50 +00:00
fs.writeFile('/file2', contents2, function(err) {
2014-02-18 19:51:06 +00:00
if(err) throw err;
2014-05-23 20:53:50 +00:00
shell.cat(['/file', '/nofile'], function(err, data) {
expect(err).to.exist;
expect(err.code).to.equal('ENOENT');
2014-05-23 20:53:50 +00:00
expect(data).not.to.exist;
done();
2014-02-18 19:51:06 +00:00
});
});
});
});
});