filer/tests/spec/shell/cd.spec.js

123 lines
3.0 KiB
JavaScript
Raw Permalink Normal View History

2014-05-23 20:53:50 +00:00
var util = require('../../lib/test-utils.js');
2014-05-26 20:57:08 +00:00
var expect = require('chai').expect;
2014-02-17 15:47:47 +00:00
2014-05-23 20:53:50 +00:00
describe('FileSystemShell.cd', function() {
beforeEach(util.setup);
afterEach(util.cleanup);
2014-02-17 15:47:47 +00:00
2014-05-23 20:53:50 +00:00
it('should be a function', function() {
var shell = util.shell();
expect(shell.cd).to.be.a('function');
});
2014-02-17 15:47:47 +00:00
2014-05-23 20:53:50 +00:00
it('should default to a cwd of /', function() {
var shell = util.shell();
expect(shell.pwd()).to.equal('/');
});
2014-02-17 15:47:47 +00:00
2014-05-23 20:53:50 +00:00
it('should allow changing the path to a valid dir', function(done) {
var fs = util.fs();
2014-10-24 18:19:17 +00:00
var shell = new fs.Shell();
2014-02-17 15:47:47 +00:00
2014-05-23 20:53:50 +00:00
fs.mkdir('/dir', function(err) {
if(err) throw err;
2014-02-17 15:47:47 +00:00
2014-05-23 20:53:50 +00:00
expect(shell.pwd()).to.equal('/');
shell.cd('/dir', function(err) {
expect(err).not.to.exist;
expect(shell.pwd()).to.equal('/dir');
done();
2014-02-17 15:47:47 +00:00
});
});
2014-05-23 20:53:50 +00:00
});
2014-02-17 15:47:47 +00:00
2014-05-23 20:53:50 +00:00
it('should fail when changing the path to an invalid dir', function(done) {
var fs = util.fs();
2014-10-24 18:19:17 +00:00
var shell = new fs.Shell();
2014-02-17 15:47:47 +00:00
2014-05-23 20:53:50 +00:00
fs.mkdir('/dir', function(err) {
if(err) throw err;
2014-02-17 15:47:47 +00:00
2014-05-23 20:53:50 +00:00
expect(shell.pwd()).to.equal('/');
shell.cd('/nodir', function(err) {
expect(err).to.exist;
expect(err.code).to.equal('ENOTDIR');
2014-02-19 22:29:11 +00:00
expect(shell.pwd()).to.equal('/');
2014-05-23 20:53:50 +00:00
done();
2014-02-17 15:47:47 +00:00
});
});
2014-05-23 20:53:50 +00:00
});
2014-02-17 15:47:47 +00:00
2014-05-23 20:53:50 +00:00
it('should fail when changing the path to a file', function(done) {
var fs = util.fs();
2014-10-24 18:19:17 +00:00
var shell = new fs.Shell();
2014-02-17 15:47:47 +00:00
2014-05-23 20:53:50 +00:00
fs.writeFile('/file', 'file', function(err) {
if(err) throw err;
2014-02-17 15:47:47 +00:00
2014-05-23 20:53:50 +00:00
expect(shell.pwd()).to.equal('/');
shell.cd('/file', function(err) {
expect(err).to.exist;
expect(err.code).to.equal('ENOTDIR');
2014-02-19 22:29:11 +00:00
expect(shell.pwd()).to.equal('/');
2014-05-23 20:53:50 +00:00
done();
2014-02-17 15:47:47 +00:00
});
});
2014-05-23 20:53:50 +00:00
});
2014-02-17 15:47:47 +00:00
2014-05-23 20:53:50 +00:00
it('should allow relative paths for a valid dir', function(done) {
var fs = util.fs();
2014-10-24 18:19:17 +00:00
var shell = new fs.Shell();
2014-02-17 15:47:47 +00:00
2014-05-23 20:53:50 +00:00
fs.mkdir('/dir', function(err) {
if(err) throw err;
2014-02-17 15:47:47 +00:00
2014-05-23 20:53:50 +00:00
expect(shell.pwd()).to.equal('/');
shell.cd('./dir', function(err) {
expect(err).not.to.exist;
expect(shell.pwd()).to.equal('/dir');
done();
2014-02-17 15:47:47 +00:00
});
});
2014-05-23 20:53:50 +00:00
});
2014-02-17 15:47:47 +00:00
2014-05-23 20:53:50 +00:00
it('should allow .. in paths for a valid dir', function(done) {
var fs = util.fs();
2014-10-24 18:19:17 +00:00
var shell = new fs.Shell();
2014-02-17 15:47:47 +00:00
2014-05-23 20:53:50 +00:00
fs.mkdir('/dir', function(err) {
if(err) throw err;
2014-02-17 15:47:47 +00:00
2014-05-23 20:53:50 +00:00
expect(shell.pwd()).to.equal('/');
shell.cd('./dir', function(err) {
expect(err).not.to.exist;
expect(shell.pwd()).to.equal('/dir');
shell.cd('..', function(err) {
2014-02-17 15:47:47 +00:00
expect(err).not.to.exist;
2014-05-23 20:53:50 +00:00
expect(shell.pwd()).to.equal('/');
done();
2014-02-17 15:47:47 +00:00
});
});
});
2014-05-23 20:53:50 +00:00
});
2014-02-17 15:47:47 +00:00
2014-05-23 20:53:50 +00:00
it('should follow symlinks to dirs', function(done) {
var fs = util.fs();
2014-02-17 21:55:36 +00:00
2014-05-23 20:53:50 +00:00
fs.mkdir('/dir', function(error) {
if(error) throw error;
2014-02-17 21:55:36 +00:00
2014-05-23 20:53:50 +00:00
fs.symlink('/dir', '/link', function(error) {
if(error) throw error;
2014-02-17 21:55:36 +00:00
2014-10-24 18:19:17 +00:00
var shell = new fs.Shell();
2014-05-23 20:53:50 +00:00
shell.cd('link', function(error) {
expect(error).not.to.exist;
expect(shell.pwd()).to.equal('/link');
done();
2014-02-17 21:55:36 +00:00
});
});
});
2014-02-17 15:47:47 +00:00
});
});