2014-05-23 20:53:50 +00:00
|
|
|
var Filer = require('../../..');
|
|
|
|
var util = require('../../lib/test-utils.js');
|
|
|
|
var expect = require('chai').expect;
|
|
|
|
|
|
|
|
describe('FileSystemShell.env', function() {
|
|
|
|
beforeEach(util.setup);
|
|
|
|
afterEach(util.cleanup);
|
|
|
|
|
|
|
|
it('should get default env options', function() {
|
|
|
|
var shell = util.shell();
|
|
|
|
expect(shell.env).to.exist;
|
|
|
|
expect(shell.env.get('TMP')).to.equal('/tmp');
|
|
|
|
expect(shell.env.get('PATH')).to.equal('');
|
|
|
|
expect(shell.pwd()).to.equal('/');
|
|
|
|
});
|
2014-02-19 22:29:11 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
it('should be able to specify env options', function() {
|
|
|
|
var options = {
|
|
|
|
env: {
|
|
|
|
TMP: '/tempdir',
|
|
|
|
PATH: '/dir'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
var shell = util.shell(options);
|
|
|
|
expect(shell.env).to.exist;
|
|
|
|
expect(shell.env.get('TMP')).to.equal('/tempdir');
|
|
|
|
expect(shell.env.get('PATH')).to.equal('/dir');
|
|
|
|
expect(shell.pwd()).to.equal('/');
|
|
|
|
|
|
|
|
expect(shell.env.get('FOO')).not.to.exist;
|
|
|
|
shell.env.set('FOO', 1);
|
|
|
|
expect(shell.env.get('FOO')).to.equal(1);
|
|
|
|
});
|
2014-02-19 17:15:02 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
it('should fail when dirs argument is absent', function(done) {
|
|
|
|
var fs = util.fs();
|
|
|
|
var shell = fs.Shell();
|
2014-02-19 17:15:02 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
shell.cat(null, function(error, list) {
|
|
|
|
expect(error).to.exist;
|
|
|
|
expect(error.code).to.equal("EINVAL");
|
|
|
|
expect(list).not.to.exist;
|
|
|
|
done();
|
2014-02-19 17:15:02 +00:00
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
2014-02-19 17:15:02 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
it('should give new value for shell.pwd() when cwd changes', function(done) {
|
|
|
|
var fs = util.fs();
|
|
|
|
var shell = fs.Shell();
|
2014-02-19 17:15:02 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
fs.mkdir('/dir', function(err) {
|
|
|
|
if(err) throw err;
|
2014-02-19 17:15:02 +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-19 17:15:02 +00:00
|
|
|
});
|
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
2014-02-19 17:15:02 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
it('should create/return the default tmp dir', function(done) {
|
|
|
|
var fs = util.fs();
|
|
|
|
var shell = fs.Shell();
|
2014-02-19 17:15:02 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
expect(shell.env.get('TMP')).to.equal('/tmp');
|
|
|
|
shell.tempDir(function(err, tmp) {
|
|
|
|
expect(err).not.to.exist;
|
|
|
|
shell.cd(tmp, function(err) {
|
2014-02-19 17:15:02 +00:00
|
|
|
expect(err).not.to.exist;
|
2014-05-23 20:53:50 +00:00
|
|
|
expect(shell.pwd()).to.equal('/tmp');
|
|
|
|
done();
|
2014-02-19 17:15:02 +00:00
|
|
|
});
|
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
2014-02-19 17:15:02 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
it('should create/return the tmp dir specified in env.TMP', function(done) {
|
|
|
|
var fs = util.fs();
|
|
|
|
var shell = fs.Shell({
|
|
|
|
env: {
|
|
|
|
TMP: '/tempdir'
|
|
|
|
}
|
|
|
|
});
|
2014-02-19 17:15:02 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
expect(shell.env.get('TMP')).to.equal('/tempdir');
|
|
|
|
shell.tempDir(function(err, tmp) {
|
|
|
|
expect(err).not.to.exist;
|
|
|
|
shell.cd(tmp, function(err) {
|
2014-02-19 17:15:02 +00:00
|
|
|
expect(err).not.to.exist;
|
2014-05-23 20:53:50 +00:00
|
|
|
expect(shell.pwd()).to.equal('/tempdir');
|
|
|
|
done();
|
2014-02-19 17:15:02 +00:00
|
|
|
});
|
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should allow repeated calls to tempDir()', function(done) {
|
|
|
|
var fs = util.fs();
|
|
|
|
var shell = fs.Shell();
|
2014-02-19 17:15:02 +00:00
|
|
|
|
2014-05-23 20:53:50 +00:00
|
|
|
expect(shell.env.get('TMP')).to.equal('/tmp');
|
|
|
|
shell.tempDir(function(err, tmp) {
|
|
|
|
expect(err).not.to.exist;
|
|
|
|
expect(tmp).to.equal('/tmp');
|
2014-02-19 17:15:02 +00:00
|
|
|
|
|
|
|
shell.tempDir(function(err, tmp) {
|
|
|
|
expect(err).not.to.exist;
|
|
|
|
expect(tmp).to.equal('/tmp');
|
2014-05-23 20:53:50 +00:00
|
|
|
done();
|
2014-02-19 17:15:02 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|