Permalink
Browse files

[wip] CP tests

  • Loading branch information...
1 parent cac9f7e commit 587cfdcbf803919202ac58cd6b1717e043e87c8c @filipediasf filipediasf committed Jan 6, 2013
Showing with 133 additions and 13 deletions.
  1. +133 −13 test/tasks/cp.js
View
@@ -1,13 +1,21 @@
var expect = require('expect.js'),
- isFile = require('../helpers/util/is-file')
+ isFile = require('../helpers/util/is-file'),
+ fs = require('fs')
;
module.exports = function (automaton) {
describe('cp', function () {
+
+ var target = __dirname + '/../tmp/cp/';
+
+ beforeEach(function () {
+ fs.mkdirSync(target, '0777');
+ });
+
it('should copy a file', function (done) {
var files = {};
- files[__dirname + '/../helpers/assets/file1.json'] = __dirname + '/../tmp/cp/file1.json';
- files[__dirname + '/../helpers/assets/file2'] = __dirname + '/../tmp/cp/';
+ files[__dirname + '/../helpers/assets/file1.json'] = target + 'file1.json';
+ files[__dirname + '/../helpers/assets/file2'] = target;
automaton.run('cp', {
files: files
@@ -16,8 +24,8 @@ module.exports = function (automaton) {
throw err;
}
- expect(isFile(__dirname + '/../tmp/cp/file1.json')).to.be(true);
- expect(isFile(__dirname + '/../tmp/cp/file2')).to.be(true);
+ expect(isFile(target + 'file1.json')).to.be(true);
+ expect(isFile(target + 'file2')).to.be(true);
done();
});
});
@@ -28,24 +36,136 @@ module.exports = function (automaton) {
// TODO: add more tests when copying files that do not exists, etc!
- it.skip('should work with sources as symlinks (directly or deep)');
- it.skip('should work with destinations as symlinks');
- it.skip('should copy file and folders permissions');
- it('should pass over the glob options', function (done) {
+ it('should work with sources as symlinks (directly or deep)', function (done) {
+ var dir = 'cp_dst/',
+ file = 'file.js',
+ symlink = target + '../symlink',
+ files = {};
+
+ // create file
+ fs.writeFileSync(target + file, 'dummy');
+
+ // create dir
+ fs.mkdirSync(target + '../' + dir);
+
+ // create symlink to folder in tmp
+ fs.symlinkSync(target + file, symlink, 'file');
+
+ // copy file
+ files[symlink] = target + '../' + dir;
+
+ automaton.run('cp', {
+ files: files
+ }, function (err) {
+ if (err) {
+ throw err;
+ }
+
+ expect(isFile(target + '../' + dir + file)).to.be(true);
+ done();
+ });
+ });
+ it('should work with destinations as symlinks', function (done) {
+ var folder = target + 'folder/',
+ file = 'file.js',
+ symlink = target + '../symlink_to_folder',
+ files = {};
+
+ // create file
+ fs.writeFileSync(target + file, 'dummy');
+
+ // create dir
+ fs.mkdirSync(folder);
+
+ // create symlink to folder in tmp
+ fs.symlinkSync(folder, symlink, 'dir');
+
+ // copy file in /tmp/cp/file.js to /tmp/symlink/file.js
+ // where symlink = cp/folder
+ files[target + file] = symlink;
+
+ automaton.run('cp', {
+ files: files
+ }, function (err) {
+ if (err) {
+ throw err;
+ }
+
+ expect(isFile(symlink + '/' + file)).to.be(true);
+ done();
+ });
+ });
+
+ it('should copy file and folders permissions', function (done) {
+
+ var dir = target + 'permissions/',
+ folder = 'folder/',
+ file = 'file.js',
+ toCopy = {},
+ mode755_file,
+ mode777_dir;
+
+ // create dirs
+ fs.mkdirSync(dir);
+ fs.mkdirSync(target + folder);
+ fs.chmodSync(target + folder, '0777');
+
+ // get mode
+ mode777_dir = fs.statSync(target + folder).mode;
+
+ // create file
+ fs.writeFileSync(target + file, 'dummy');
+ fs.chmodSync(target + file, '0755');
+
+ // get mode
+ mode755_file = fs.statSync(target + file).mode;
+
+ // file to copy
+ toCopy[target + file] = dir;
+ toCopy[target + folder] = dir + 'folder/';
+
+ automaton.run('cp', {
+ files: toCopy
+ }, function (err) {
+ if (err) {
+ throw err;
+ }
+
+ expect(fs.statSync(toCopy[target + file]).mode).to.equal(mode755_file);
+ expect(fs.statSync(toCopy[target + folder]).mode).to.equal(mode777_dir);
+ done();
+ });
+ });
+
+ it('should pass over the glob options - should not copy the file', function (done) {
+ var files = {};
+ files[__dirname + '/../helpers/assets/.file'] = target;
+
+ automaton.run('cp', {
+ files: files
+ }, function (err) {
+ if (err) {
+ throw err;
+ }
+ expect(isFile(target + '.file')).to.be(false);
+ done();
+ });
+ });
+
+ it('should pass over the glob options - should copy the file', function (done) {
var files = {};
- files[__dirname + '/../helpers/assets/.file'] = __dirname + '/../tmp/cp/';
+ files[__dirname + '/../helpers/assets/.file'] = target;
automaton.run('cp', {
files: files,
glob: {
- dot: false
+ dot: true
}
}, function (err) {
if (err) {
throw err;
}
-
- //expect(isFile(__dirname + '/../tmp/cp/.file')).to.be(false);
+ expect(isFile(target + '.file')).to.be(true);
done();
});
});

0 comments on commit 587cfdc

Please sign in to comment.