2014-05-23 20:53:50 +00:00
|
|
|
var util = require('../lib/test-utils.js');
|
|
|
|
var expect = require('chai').expect;
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2018-09-29 05:46:52 +00:00
|
|
|
describe('fs.symlink', function () {
|
2014-05-23 20:53:50 +00:00
|
|
|
beforeEach(util.setup);
|
|
|
|
afterEach(util.cleanup);
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2018-09-29 05:46:52 +00:00
|
|
|
it('should be a function', function () {
|
2014-05-23 20:53:50 +00:00
|
|
|
var fs = util.fs();
|
|
|
|
expect(fs.symlink).to.be.a('function');
|
|
|
|
});
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2018-09-29 05:46:52 +00:00
|
|
|
it('should return an error if part of the parent destination path does not exist', function (done) {
|
2014-05-23 20:53:50 +00:00
|
|
|
var fs = util.fs();
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2018-09-29 05:46:52 +00:00
|
|
|
fs.symlink('/', '/tmp/mydir', function (error) {
|
2014-05-23 20:53:50 +00:00
|
|
|
expect(error).to.exist;
|
2018-07-15 17:25:35 +00:00
|
|
|
expect(error.code).to.equal('ENOENT');
|
2014-05-23 20:53:50 +00:00
|
|
|
done();
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2018-09-29 05:46:52 +00:00
|
|
|
it('should return an error if the destination path already exists', function (done) {
|
2014-05-23 20:53:50 +00:00
|
|
|
var fs = util.fs();
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2018-09-29 05:46:52 +00:00
|
|
|
fs.symlink('/tmp', '/', function (error) {
|
2014-05-23 20:53:50 +00:00
|
|
|
expect(error).to.exist;
|
2018-07-15 17:25:35 +00:00
|
|
|
expect(error.code).to.equal('EEXIST');
|
2014-05-23 20:53:50 +00:00
|
|
|
done();
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
2014-05-23 20:53:50 +00:00
|
|
|
});
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2018-09-29 05:46:52 +00:00
|
|
|
it('should create a symlink', function (done) {
|
2014-05-23 20:53:50 +00:00
|
|
|
var fs = util.fs();
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2018-09-29 05:46:52 +00:00
|
|
|
fs.symlink('/', '/myfile', function (error) {
|
2014-05-23 20:53:50 +00:00
|
|
|
expect(error).not.to.exist;
|
2013-11-27 17:18:09 +00:00
|
|
|
|
2018-09-29 05:46:52 +00:00
|
|
|
fs.stat('/myfile', function (err, stats) {
|
2014-05-23 20:53:50 +00:00
|
|
|
expect(error).not.to.exist;
|
2018-11-28 18:54:20 +00:00
|
|
|
expect(stats.isDirectory()).to.be.true;
|
2014-05-23 20:53:50 +00:00
|
|
|
done();
|
2014-01-21 21:25:09 +00:00
|
|
|
});
|
2013-11-27 17:18:09 +00:00
|
|
|
});
|
|
|
|
});
|
2018-12-13 02:38:12 +00:00
|
|
|
|
2018-09-29 00:44:50 +00:00
|
|
|
/** Tests for fsPromises API */
|
2018-09-28 02:28:48 +00:00
|
|
|
describe('fsPromises.symlink', function () {
|
|
|
|
it('should return an error if destination path does not exist', function () {
|
|
|
|
var fsPromises = util.fs().promises;
|
2018-12-13 02:38:12 +00:00
|
|
|
|
2018-09-28 02:28:48 +00:00
|
|
|
return fsPromises.symlink('/', '/tmp/link')
|
|
|
|
.catch(error => {
|
|
|
|
expect(error).to.exist;
|
|
|
|
expect(error.code).to.equal('ENOENT');
|
|
|
|
});
|
2018-09-29 05:46:52 +00:00
|
|
|
});
|
|
|
|
|
2018-09-28 02:28:48 +00:00
|
|
|
it('should return an error if source path does not exist', function () {
|
|
|
|
var fsPromises = util.fs().promises;
|
2018-12-13 02:38:12 +00:00
|
|
|
|
2018-09-28 02:28:48 +00:00
|
|
|
return fsPromises.symlink('/tmp/myLink', '/myLink')
|
|
|
|
.catch(error => {
|
|
|
|
expect(error).to.exist;
|
|
|
|
expect(error.code).to.equal('ENOENT');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Promise should create a symlink of type DIRECTORY when directory provided', function () {
|
|
|
|
var fsPromises = util.fs().promises;
|
2018-12-13 02:38:12 +00:00
|
|
|
|
2018-09-28 02:28:48 +00:00
|
|
|
return fsPromises.symlink('/', '/myDirLink')
|
2018-12-13 02:38:12 +00:00
|
|
|
.then(() => fsPromises.stat('/myDirLink'))
|
|
|
|
.then(stats => {
|
|
|
|
expect(stats).to.exist;
|
|
|
|
expect(stats.type).to.equal('DIRECTORY');
|
2018-09-28 02:28:48 +00:00
|
|
|
});
|
|
|
|
});
|
2018-09-29 05:46:52 +00:00
|
|
|
|
2018-09-28 02:28:48 +00:00
|
|
|
it('Promise should create a symlink of type FILE when file provided', function () {
|
|
|
|
var fsPromises = util.fs().promises;
|
2018-12-13 02:38:12 +00:00
|
|
|
|
|
|
|
return fsPromises.writeFile('/myFile', 'data')
|
|
|
|
.then(() => fsPromises.symlink('/myFile', '/myFileLink'))
|
|
|
|
.then(() => fsPromises.stat('/myFileLink'))
|
|
|
|
.then(stats => {
|
|
|
|
expect(stats).to.exist;
|
|
|
|
expect(stats.type).to.equal('FILE');
|
2018-09-28 02:28:48 +00:00
|
|
|
});
|
|
|
|
});
|
2018-09-29 05:46:52 +00:00
|
|
|
|
2018-09-28 02:28:48 +00:00
|
|
|
it('Promise should return an error if the destination path already exists', function () {
|
|
|
|
var fsPromises = util.fs().promises;
|
|
|
|
|
|
|
|
return fsPromises.symlink('/tmp', '/')
|
|
|
|
.catch(error => {
|
|
|
|
expect(error).to.exist;
|
|
|
|
expect(error.code).to.equal('EEXIST');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2014-01-21 21:25:09 +00:00
|
|
|
});
|
2018-10-20 20:57:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
describe('fsPromises.symlink', function () {
|
|
|
|
beforeEach(util.setup);
|
|
|
|
afterEach(util.cleanup);
|
|
|
|
|
|
|
|
|
|
|
|
it('should return an error if part of the parent destination path does not exist', () => {
|
|
|
|
var fsPromises = util.fs().promises;
|
|
|
|
|
|
|
|
return fsPromises.symlink('/', '/tmp/mydir')
|
|
|
|
.catch(error => {
|
|
|
|
expect(error).to.exist;
|
|
|
|
expect(error.code).to.equal('ENOENT');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|