diff options
Diffstat (limited to 'node_modules/express/node_modules/mkdirp/test')
13 files changed, 406 insertions, 0 deletions
| diff --git a/node_modules/express/node_modules/mkdirp/test/chmod.js b/node_modules/express/node_modules/mkdirp/test/chmod.js new file mode 100644 index 0000000..520dcb8 --- /dev/null +++ b/node_modules/express/node_modules/mkdirp/test/chmod.js @@ -0,0 +1,38 @@ +var mkdirp = require('../').mkdirp; +var path = require('path'); +var fs = require('fs'); +var test = require('tap').test; + +var ps = [ '', 'tmp' ]; + +for (var i = 0; i < 25; i++) { +    var dir = Math.floor(Math.random() * Math.pow(16,4)).toString(16); +    ps.push(dir); +} + +var file = ps.join('/'); + +test('chmod-pre', function (t) { +    var mode = 0744 +    mkdirp(file, mode, function (er) { +        t.ifError(er, 'should not error'); +        fs.stat(file, function (er, stat) { +            t.ifError(er, 'should exist'); +            t.ok(stat && stat.isDirectory(), 'should be directory'); +            t.equal(stat && stat.mode & 0777, mode, 'should be 0744'); +            t.end(); +        }); +    }); +}); + +test('chmod', function (t) { +    var mode = 0755 +    mkdirp(file, mode, function (er) { +        t.ifError(er, 'should not error'); +        fs.stat(file, function (er, stat) { +            t.ifError(er, 'should exist'); +            t.ok(stat && stat.isDirectory(), 'should be directory'); +            t.end(); +        }); +    }); +}); diff --git a/node_modules/express/node_modules/mkdirp/test/clobber.js b/node_modules/express/node_modules/mkdirp/test/clobber.js new file mode 100644 index 0000000..0eb7099 --- /dev/null +++ b/node_modules/express/node_modules/mkdirp/test/clobber.js @@ -0,0 +1,37 @@ +var mkdirp = require('../').mkdirp; +var path = require('path'); +var fs = require('fs'); +var test = require('tap').test; + +var ps = [ '', 'tmp' ]; + +for (var i = 0; i < 25; i++) { +    var dir = Math.floor(Math.random() * Math.pow(16,4)).toString(16); +    ps.push(dir); +} + +var file = ps.join('/'); + +// a file in the way +var itw = ps.slice(0, 3).join('/'); + + +test('clobber-pre', function (t) { +    console.error("about to write to "+itw) +    fs.writeFileSync(itw, 'I AM IN THE WAY, THE TRUTH, AND THE LIGHT.'); + +    fs.stat(itw, function (er, stat) { +        t.ifError(er) +        t.ok(stat && stat.isFile(), 'should be file') +        t.end() +    }) +}) + +test('clobber', function (t) { +    t.plan(2); +    mkdirp(file, 0755, function (err) { +        t.ok(err); +        t.equal(err.code, 'ENOTDIR'); +        t.end(); +    }); +}); diff --git a/node_modules/express/node_modules/mkdirp/test/mkdirp.js b/node_modules/express/node_modules/mkdirp/test/mkdirp.js new file mode 100644 index 0000000..b07cd70 --- /dev/null +++ b/node_modules/express/node_modules/mkdirp/test/mkdirp.js @@ -0,0 +1,28 @@ +var mkdirp = require('../'); +var path = require('path'); +var fs = require('fs'); +var test = require('tap').test; + +test('woo', function (t) { +    t.plan(2); +    var x = Math.floor(Math.random() * Math.pow(16,4)).toString(16); +    var y = Math.floor(Math.random() * Math.pow(16,4)).toString(16); +    var z = Math.floor(Math.random() * Math.pow(16,4)).toString(16); +     +    var file = '/tmp/' + [x,y,z].join('/'); +     +    mkdirp(file, 0755, function (err) { +        if (err) t.fail(err); +        else path.exists(file, function (ex) { +            if (!ex) t.fail('file not created') +            else fs.stat(file, function (err, stat) { +                if (err) t.fail(err) +                else { +                    t.equal(stat.mode & 0777, 0755); +                    t.ok(stat.isDirectory(), 'target not a directory'); +                    t.end(); +                } +            }) +        }) +    }); +}); diff --git a/node_modules/express/node_modules/mkdirp/test/perm.js b/node_modules/express/node_modules/mkdirp/test/perm.js new file mode 100644 index 0000000..23a7abb --- /dev/null +++ b/node_modules/express/node_modules/mkdirp/test/perm.js @@ -0,0 +1,32 @@ +var mkdirp = require('../'); +var path = require('path'); +var fs = require('fs'); +var test = require('tap').test; + +test('async perm', function (t) { +    t.plan(2); +    var file = '/tmp/' + (Math.random() * (1<<30)).toString(16); +     +    mkdirp(file, 0755, function (err) { +        if (err) t.fail(err); +        else path.exists(file, function (ex) { +            if (!ex) t.fail('file not created') +            else fs.stat(file, function (err, stat) { +                if (err) t.fail(err) +                else { +                    t.equal(stat.mode & 0777, 0755); +                    t.ok(stat.isDirectory(), 'target not a directory'); +                    t.end(); +                } +            }) +        }) +    }); +}); + +test('async root perm', function (t) { +    mkdirp('/tmp', 0755, function (err) { +        if (err) t.fail(err); +        t.end(); +    }); +    t.end(); +}); diff --git a/node_modules/express/node_modules/mkdirp/test/perm_sync.js b/node_modules/express/node_modules/mkdirp/test/perm_sync.js new file mode 100644 index 0000000..f685f60 --- /dev/null +++ b/node_modules/express/node_modules/mkdirp/test/perm_sync.js @@ -0,0 +1,39 @@ +var mkdirp = require('../'); +var path = require('path'); +var fs = require('fs'); +var test = require('tap').test; + +test('sync perm', function (t) { +    t.plan(2); +    var file = '/tmp/' + (Math.random() * (1<<30)).toString(16) + '.json'; +     +    mkdirp.sync(file, 0755); +    path.exists(file, function (ex) { +        if (!ex) t.fail('file not created') +        else fs.stat(file, function (err, stat) { +            if (err) t.fail(err) +            else { +                t.equal(stat.mode & 0777, 0755); +                t.ok(stat.isDirectory(), 'target not a directory'); +                t.end(); +            } +        }) +    }); +}); + +test('sync root perm', function (t) { +    t.plan(1); +     +    var file = '/tmp'; +    mkdirp.sync(file, 0755); +    path.exists(file, function (ex) { +        if (!ex) t.fail('file not created') +        else fs.stat(file, function (err, stat) { +            if (err) t.fail(err) +            else { +                t.ok(stat.isDirectory(), 'target not a directory'); +                t.end(); +            } +        }) +    }); +}); diff --git a/node_modules/express/node_modules/mkdirp/test/race.js b/node_modules/express/node_modules/mkdirp/test/race.js new file mode 100644 index 0000000..96a0447 --- /dev/null +++ b/node_modules/express/node_modules/mkdirp/test/race.js @@ -0,0 +1,41 @@ +var mkdirp = require('../').mkdirp; +var path = require('path'); +var fs = require('fs'); +var test = require('tap').test; + +test('race', function (t) { +    t.plan(4); +    var ps = [ '', 'tmp' ]; +     +    for (var i = 0; i < 25; i++) { +        var dir = Math.floor(Math.random() * Math.pow(16,4)).toString(16); +        ps.push(dir); +    } +    var file = ps.join('/'); +     +    var res = 2; +    mk(file, function () { +        if (--res === 0) t.end(); +    }); +     +    mk(file, function () { +        if (--res === 0) t.end(); +    }); +     +    function mk (file, cb) { +        mkdirp(file, 0755, function (err) { +            if (err) t.fail(err); +            else path.exists(file, function (ex) { +                if (!ex) t.fail('file not created') +                else fs.stat(file, function (err, stat) { +                    if (err) t.fail(err) +                    else { +                        t.equal(stat.mode & 0777, 0755); +                        t.ok(stat.isDirectory(), 'target not a directory'); +                        if (cb) cb(); +                    } +                }) +            }) +        }); +    } +}); diff --git a/node_modules/express/node_modules/mkdirp/test/rel.js b/node_modules/express/node_modules/mkdirp/test/rel.js new file mode 100644 index 0000000..7985824 --- /dev/null +++ b/node_modules/express/node_modules/mkdirp/test/rel.js @@ -0,0 +1,32 @@ +var mkdirp = require('../'); +var path = require('path'); +var fs = require('fs'); +var test = require('tap').test; + +test('rel', function (t) { +    t.plan(2); +    var x = Math.floor(Math.random() * Math.pow(16,4)).toString(16); +    var y = Math.floor(Math.random() * Math.pow(16,4)).toString(16); +    var z = Math.floor(Math.random() * Math.pow(16,4)).toString(16); +     +    var cwd = process.cwd(); +    process.chdir('/tmp'); +     +    var file = [x,y,z].join('/'); +     +    mkdirp(file, 0755, function (err) { +        if (err) t.fail(err); +        else path.exists(file, function (ex) { +            if (!ex) t.fail('file not created') +            else fs.stat(file, function (err, stat) { +                if (err) t.fail(err) +                else { +                    process.chdir(cwd); +                    t.equal(stat.mode & 0777, 0755); +                    t.ok(stat.isDirectory(), 'target not a directory'); +                    t.end(); +                } +            }) +        }) +    }); +}); diff --git a/node_modules/express/node_modules/mkdirp/test/return.js b/node_modules/express/node_modules/mkdirp/test/return.js new file mode 100644 index 0000000..bce68e5 --- /dev/null +++ b/node_modules/express/node_modules/mkdirp/test/return.js @@ -0,0 +1,25 @@ +var mkdirp = require('../'); +var path = require('path'); +var fs = require('fs'); +var test = require('tap').test; + +test('return value', function (t) { +    t.plan(4); +    var x = Math.floor(Math.random() * Math.pow(16,4)).toString(16); +    var y = Math.floor(Math.random() * Math.pow(16,4)).toString(16); +    var z = Math.floor(Math.random() * Math.pow(16,4)).toString(16); + +    var file = '/tmp/' + [x,y,z].join('/'); + +    // should return the first dir created. +    // By this point, it would be profoundly surprising if /tmp didn't +    // already exist, since every other test makes things in there. +    mkdirp(file, function (err, made) { +        t.ifError(err); +        t.equal(made, '/tmp/' + x); +        mkdirp(file, function (err, made) { +          t.ifError(err); +          t.equal(made, null); +        }); +    }); +}); diff --git a/node_modules/express/node_modules/mkdirp/test/return_sync.js b/node_modules/express/node_modules/mkdirp/test/return_sync.js new file mode 100644 index 0000000..7c222d3 --- /dev/null +++ b/node_modules/express/node_modules/mkdirp/test/return_sync.js @@ -0,0 +1,24 @@ +var mkdirp = require('../'); +var path = require('path'); +var fs = require('fs'); +var test = require('tap').test; + +test('return value', function (t) { +    t.plan(2); +    var x = Math.floor(Math.random() * Math.pow(16,4)).toString(16); +    var y = Math.floor(Math.random() * Math.pow(16,4)).toString(16); +    var z = Math.floor(Math.random() * Math.pow(16,4)).toString(16); + +    var file = '/tmp/' + [x,y,z].join('/'); + +    // should return the first dir created. +    // By this point, it would be profoundly surprising if /tmp didn't +    // already exist, since every other test makes things in there. +    // Note that this will throw on failure, which will fail the test. +    var made = mkdirp.sync(file); +    t.equal(made, '/tmp/' + x); + +    // making the same file again should have no effect. +    made = mkdirp.sync(file); +    t.equal(made, null); +}); diff --git a/node_modules/express/node_modules/mkdirp/test/root.js b/node_modules/express/node_modules/mkdirp/test/root.js new file mode 100644 index 0000000..97ad7a2 --- /dev/null +++ b/node_modules/express/node_modules/mkdirp/test/root.js @@ -0,0 +1,18 @@ +var mkdirp = require('../'); +var path = require('path'); +var fs = require('fs'); +var test = require('tap').test; + +test('root', function (t) { +    // '/' on unix, 'c:/' on windows. +    var file = path.resolve('/'); + +    mkdirp(file, 0755, function (err) { +        if (err) throw err +        fs.stat(file, function (er, stat) { +            if (er) throw er +            t.ok(stat.isDirectory(), 'target is a directory'); +            t.end(); +        }) +    }); +}); diff --git a/node_modules/express/node_modules/mkdirp/test/sync.js b/node_modules/express/node_modules/mkdirp/test/sync.js new file mode 100644 index 0000000..7530cad --- /dev/null +++ b/node_modules/express/node_modules/mkdirp/test/sync.js @@ -0,0 +1,32 @@ +var mkdirp = require('../'); +var path = require('path'); +var fs = require('fs'); +var test = require('tap').test; + +test('sync', function (t) { +    t.plan(2); +    var x = Math.floor(Math.random() * Math.pow(16,4)).toString(16); +    var y = Math.floor(Math.random() * Math.pow(16,4)).toString(16); +    var z = Math.floor(Math.random() * Math.pow(16,4)).toString(16); + +    var file = '/tmp/' + [x,y,z].join('/'); + +    try { +        mkdirp.sync(file, 0755); +    } catch (err) { +        t.fail(err); +        return t.end(); +    } + +    path.exists(file, function (ex) { +        if (!ex) t.fail('file not created') +        else fs.stat(file, function (err, stat) { +            if (err) t.fail(err) +            else { +                t.equal(stat.mode & 0777, 0755); +                t.ok(stat.isDirectory(), 'target not a directory'); +                t.end(); +            } +        }); +    }); +}); diff --git a/node_modules/express/node_modules/mkdirp/test/umask.js b/node_modules/express/node_modules/mkdirp/test/umask.js new file mode 100644 index 0000000..64ccafe --- /dev/null +++ b/node_modules/express/node_modules/mkdirp/test/umask.js @@ -0,0 +1,28 @@ +var mkdirp = require('../'); +var path = require('path'); +var fs = require('fs'); +var test = require('tap').test; + +test('implicit mode from umask', function (t) { +    t.plan(2); +    var x = Math.floor(Math.random() * Math.pow(16,4)).toString(16); +    var y = Math.floor(Math.random() * Math.pow(16,4)).toString(16); +    var z = Math.floor(Math.random() * Math.pow(16,4)).toString(16); +     +    var file = '/tmp/' + [x,y,z].join('/'); +     +    mkdirp(file, function (err) { +        if (err) t.fail(err); +        else path.exists(file, function (ex) { +            if (!ex) t.fail('file not created') +            else fs.stat(file, function (err, stat) { +                if (err) t.fail(err) +                else { +                    t.equal(stat.mode & 0777, 0777 & (~process.umask())); +                    t.ok(stat.isDirectory(), 'target not a directory'); +                    t.end(); +                } +            }) +        }) +    }); +}); diff --git a/node_modules/express/node_modules/mkdirp/test/umask_sync.js b/node_modules/express/node_modules/mkdirp/test/umask_sync.js new file mode 100644 index 0000000..35bd5cb --- /dev/null +++ b/node_modules/express/node_modules/mkdirp/test/umask_sync.js @@ -0,0 +1,32 @@ +var mkdirp = require('../'); +var path = require('path'); +var fs = require('fs'); +var test = require('tap').test; + +test('umask sync modes', function (t) { +    t.plan(2); +    var x = Math.floor(Math.random() * Math.pow(16,4)).toString(16); +    var y = Math.floor(Math.random() * Math.pow(16,4)).toString(16); +    var z = Math.floor(Math.random() * Math.pow(16,4)).toString(16); + +    var file = '/tmp/' + [x,y,z].join('/'); + +    try { +        mkdirp.sync(file); +    } catch (err) { +        t.fail(err); +        return t.end(); +    } + +    path.exists(file, function (ex) { +        if (!ex) t.fail('file not created') +        else fs.stat(file, function (err, stat) { +            if (err) t.fail(err) +            else { +                t.equal(stat.mode & 0777, (0777 & (~process.umask()))); +                t.ok(stat.isDirectory(), 'target not a directory'); +                t.end(); +            } +        }); +    }); +}); | 
