chmod.js 1.1 KB

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