perm.js 970 B

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