Skip to content

Commit

Permalink
test(copymitter) pause/continue, no fs.access, directory exist
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Dec 23, 2015
1 parent 6071e0a commit 3132ce3
Showing 1 changed file with 101 additions and 0 deletions.
101 changes: 101 additions & 0 deletions test/copymitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

var path = require('path'),
fs = require('fs'),
rimraf = require('rimraf'),
mkdirp = require('mkdirp'),
test = require('tape'),
copymitter = require('..');

Expand All @@ -21,6 +23,46 @@
});
});

test('file: error EACESS: no fs.access', function(t) {
var access = fs.access;

fs.access = null;

var cp = copymitter(__dirname, '/', [
path.basename(__filename)
]);

cp.on('error', function(error) {
t.equal(error.code, 'EACCES', error.message);
cp.abort();
});

cp.on('end', function() {
fs.access = access;
t.end();
});
});

test('file: error EACESS: no fs.access, read error', function(t) {
var access = fs.access;

fs.access = null;

var cp = copymitter('/root', '/', [
path.basename(__filename)
]);

cp.on('error', function(error) {
t.equal(error.code, 'EACCES', error.message);
cp.abort();
});

cp.on('end', function() {
fs.access = access;
t.end();
});
});

test('folder: error EACESS', function(t) {
var from = path.join(__dirname, '..'),
name = path.basename(__dirname);
Expand Down Expand Up @@ -63,6 +105,46 @@
});
});

test('copy 1 file: to (error: EISDIR, not create dir)', function(t) {
var mkdir = fs.mkdir,
from = path.join(__dirname, '..'),
to = path.join('/tmp', String(Math.random())),
name = 'bin';

fs.mkdir = function(name, mode, cb) {
cb();
};

fs.mkdirSync(to);

var cp = copymitter(from, to, [
name
]);

cp.on('end', function() {
fs.mkdir = mkdir;
rimraf.sync(to);
t.end();
});
});

test('copy 1 file: to (directory exist)', function(t) {
var from = path.join(__dirname, '..'),
to = path.join('/tmp', String(Math.random())),
name = 'bin';

mkdirp.sync(path.join(to, 'bin', 'copymitter.js'));

var cp = copymitter(from, to, [
name
]);

cp.on('end', function() {
rimraf.sync(to);
t.end();
});
});

test('copy 1 file: from', function(t) {
var from = path.join(__dirname, '/../bin/'),
to = '/tmp',
Expand Down Expand Up @@ -140,4 +222,23 @@
});
});

test('pause/continue', function(t) {
var from = path.join(__dirname, '..'),
to = path.join('/tmp', String(Math.random())),
name = 'bin';

mkdirp.sync(to);

var cp = copymitter(from, to, [
name
]);

cp.pause();
cp.continue();

cp.on('end', function() {
rimraf.sync(to);
t.end();
});
});
})();

0 comments on commit 3132ce3

Please sign in to comment.