perm_sync.js 1.1 KB

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