perm_sync.js 875 B

123456789101112131415161718192021222324252627282930313233343536
  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. test('sync perm', function (t) {
  7. t.plan(2);
  8. var file = '/tmp/' + (Math.random() * (1<<30)).toString(16) + '.json';
  9. mkpath.sync(file, 0755);
  10. fs.stat(file, function (err, stat) {
  11. if (err) t.fail(err)
  12. else {
  13. t.equal(stat.mode & 0777, 0755);
  14. t.ok(stat.isDirectory(), 'target not a directory');
  15. t.end();
  16. }
  17. })
  18. });
  19. test('sync root perm', function (t) {
  20. t.plan(1);
  21. var file = '/tmp';
  22. mkpath.sync(file, 0755);
  23. fs.stat(file, function (err, stat) {
  24. if (err) t.fail(err)
  25. else {
  26. t.ok(stat.isDirectory(), 'target not a directory');
  27. t.end();
  28. }
  29. })
  30. });