test.js
1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'use strict';
var crypto = require('crypto');
var os = require('os');
var fs = require('fs');
var path = require('path');
var tmpdir = os.tmpdir();
var dirs = [tmpdir].concat([ 'foo', 'bar', 'baz', 'quux' ]);
var rnds = [tmpdir].concat([
crypto.randomBytes(4).toString('hex')
, crypto.randomBytes(4).toString('hex')
, crypto.randomBytes(4).toString('hex')
, crypto.randomBytes(4).toString('hex')
]);
var mkdirp = require('./mkdirp.js');
fs.stat(rnds.join(path.sep), function (err) {
if (!err) { throw new Error("Sanity error: random directory already exists"); }
mkdirp(dirs.join(path.sep), function (err) {
if (err) { throw err; }
mkdirp(dirs.join(path.sep), function (err) {
if (err) { throw err; }
mkdirp(rnds.join(path.sep), function (err) {
if (err) { throw err; }
fs.stat(rnds.join(path.sep), function (err, stat) {
if (err) { throw err; }
if (!stat.isDirectory()) { throw new Error("path is not a directory"); }
mkdirp(rnds.join(path.sep), function (err) {
if (err) { throw err; }
mkdirp('/root/special/place', function (err) {
if (!err) { throw new Error("either you ran the test as root (don't do that)"
+ " or there was an unreported error"); }
dirs.shift(); // local dir
mkdirp(dirs.join(path.sep), function (err) {
console.info("PASS");
});
});
});
});
});
});
});
});