|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const common = require('../common'); |
| 4 | +const assert = require('assert'); |
| 5 | +const path = require('path'); |
| 6 | +const fs = require('fs'); |
| 7 | +const d = path.join(common.tmpDir, 'dir'); |
| 8 | + |
| 9 | +common.refreshTmpDir(); |
| 10 | + |
| 11 | +// Make sure the directory does not exist |
| 12 | +assert(!common.fileExists(d)); |
| 13 | +// Create the directory now |
| 14 | +fs.mkdirSync(d); |
| 15 | +// Make sure the directory exists |
| 16 | +assert(common.fileExists(d)); |
| 17 | +// Try creating again, it should fail with EEXIST |
| 18 | +assert.throws(function() { |
| 19 | + fs.mkdirSync(d); |
| 20 | +}, /EEXIST: file already exists, mkdir/); |
| 21 | +// Remove the directory now |
| 22 | +fs.rmdirSync(d); |
| 23 | +// Make sure the directory does not exist |
| 24 | +assert(!common.fileExists(d)); |
| 25 | + |
| 26 | +// Similarly test the Async version |
| 27 | +fs.mkdir(d, 0o666, function(err) { |
| 28 | + assert.ifError(err); |
| 29 | + |
| 30 | + fs.mkdir(d, 0o666, function(err) { |
| 31 | + assert.ok(err.message.match(/^EEXIST/), 'got EEXIST message'); |
| 32 | + assert.equal(err.code, 'EEXIST', 'got EEXIST code'); |
| 33 | + assert.equal(err.path, d, 'got proper path for EEXIST'); |
| 34 | + |
| 35 | + fs.rmdir(d, assert.ifError); |
| 36 | + }); |
| 37 | +}); |
0 commit comments