UNPKG

1.81 kBJavaScriptView Raw
1var assert = require("assert");
2var file = require('../file-system');
3var fs = require('fs');
4var path = require('path');
5
6function getPath(filepath) {
7 return path.join(__dirname, filepath);
8}
9
10function checkPermission(filepath, mask) {
11 var stat = fs.statSync(filepath);
12 var mode = mask & parseInt((stat.mode & parseInt ("777", 8)).toString (8)[0]);
13
14 return !!mode;
15}
16
17describe('mkdir', function() {
18 it('one level Directory', function(done) {
19 file.mkdir(getPath('var/mkdir'), function(err) {
20 if (err) throw err;
21
22 var exists = fs.existsSync(getPath('var/mkdir'));
23
24 assert.equal(true, exists);
25 done();
26 });
27 });
28
29 it('multiple level Directory', function(done) {
30 file.mkdir(getPath('var/mkdir/1/2/3/4'), function(err) {
31 if (err) throw err;
32
33 var exists = fs.existsSync(getPath('var/mkdir/1/2/3/4'));
34
35 assert.equal(true, exists);
36 done();
37 });
38 });
39
40 it('file mode', function(done) {
41 // 7 = 4+2+1 (read/write/execute)
42 // 6 = 4+2 (read/write)
43 // 5 = 4+1 (read/execute)
44 // 4 = 4 (read)
45 // 3 = 2+1 (write/execute)
46 // 2 = 2 (write)
47 // 1 = 1 (execute)
48 fs.mkdir(getPath('var/mkdir/mode'), 511, function(err) {
49 if (err) throw err;
50
51 assert.equal(true, checkPermission(getPath('var/mkdir/mode'), 4));
52 done();
53 });
54
55 fs.mkdir(getPath('var/mkdir/mode2'), 111, function(err) {
56 if (err) throw err;
57
58 assert.equal(false, checkPermission(getPath('var/mkdir/mode2'), 4));
59 });
60 });
61
62 it('callback', function(done) {
63 var a;
64 fs.mkdir(getPath('var/mkdir/callback'), function(err) {
65 a = 1;
66
67 assert.equal(a, 1);
68 done();
69 });
70 });
71
72 after(function() {
73 file.chmodSync(getPath('var/mkdir/mode2'), 511);
74 file.rmdirSync(getPath('var/mkdir'));
75 });
76});
\No newline at end of file