umask.js 898 B

1234567891011121314151617181920212223242526272829
  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. test('implicit mode from umask', function (t) {
  8. t.plan(2);
  9. var x = Math.floor(Math.random() * Math.pow(16,4)).toString(16);
  10. var y = Math.floor(Math.random() * Math.pow(16,4)).toString(16);
  11. var z = Math.floor(Math.random() * Math.pow(16,4)).toString(16);
  12. var file = '/tmp/' + [x,y,z].join('/');
  13. mkpath(file, function (err) {
  14. if (err) t.fail(err);
  15. else fs.stat(file, function (err, stat) {
  16. if (err) t.fail(err)
  17. else {
  18. t.equal(stat.mode & 0777, 0777 & (~process.umask()));
  19. t.ok(stat.isDirectory(), 'target not a directory');
  20. t.end();
  21. }
  22. })
  23. });
  24. });