chmod.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* Tests borrowed from substack's node-mkdirp
  2. * https://github.com/substack/node-mkdirp */
  3. var mkpath = require('../');
  4. var path = require('path');
  5. var fs = require('fs');
  6. var test = require('tap').test;
  7. var ps = [ '', 'tmp' ];
  8. for (var i = 0; i < 25; i++) {
  9. var dir = Math.floor(Math.random() * Math.pow(16,4)).toString(16);
  10. ps.push(dir);
  11. }
  12. var file = ps.join('/');
  13. test('chmod-pre', function (t) {
  14. var mode = 0744
  15. mkpath(file, mode, function (er) {
  16. t.ifError(er, 'should not error');
  17. fs.stat(file, function (er, stat) {
  18. t.ifError(er, 'should exist');
  19. t.ok(stat && stat.isDirectory(), 'should be directory');
  20. t.equal(stat && stat.mode & 0777, mode, 'should be 0744');
  21. t.end();
  22. });
  23. });
  24. });
  25. test('chmod', function (t) {
  26. var mode = 0755
  27. mkpath(file, mode, function (er) {
  28. t.ifError(er, 'should not error');
  29. fs.stat(file, function (er, stat) {
  30. t.ifError(er, 'should exist');
  31. t.ok(stat && stat.isDirectory(), 'should be directory');
  32. t.end();
  33. });
  34. });
  35. });