Skip to content

Commit

Permalink
test(readify) readdir: owner (close #1)
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Jan 6, 2017
1 parent 903dcc2 commit 4d97dd0
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions test/readify.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ test('result: should be sorted by name folders then files', (t) => {
});
});

test('readify: result', (t) => {
test('readify: result: no owner', (t) => {
const update = () => {
delete require.cache[require.resolve('..')];
readify = require('..');
Expand Down Expand Up @@ -97,14 +97,17 @@ test('readify: result', (t) => {
name,
size: '1.00kb',
date: '23.11.2016',
owner: 'bin',
/* depends on npm@nicki */
/* could be different */
/* owner: 'bin', */
mode: 'rwx rwx r-x'
}]
};

update();

readify('.', (error, result) => {
delete result.files[0].owner;
t.deepEqual(result, expected, 'should get raw values');

fs.readdir = readdir;
Expand All @@ -116,6 +119,49 @@ test('readify: result', (t) => {
});
});

test('readify: result: owner', (t) => {
const update = () => {
delete require.cache[require.resolve('..')];
readify = require('..');
};

const {readdir, stat} = fs;

const name = 'hello.txt';
const mode = 16893;
const size = 1024;
const mtime = new Date('2016-11-23T14:36:46.311Z');
const uid = 2;

fs.readdir = (dir, fn) => {
fn(null, [name]);
};

fs.stat = (name, fn) => {
fn(null, {
isDirectory: noop,
name,
mode,
size,
mtime,
uid
});
};

update();

readify('.', (error, result) => {
t.ok(result.files[0].owner, 'should contain owner');

fs.readdir = readdir;
fs.stat = stat;

update();

t.end();
});
});

test('readify: result: "raw"', (t) => {
const update = () => {
delete require.cache[require.resolve('..')];
Expand Down

0 comments on commit 4d97dd0

Please sign in to comment.