0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 07:27:22 +01:00
nodejs/test/parallel/test-fs-mkdir-rmdir.js
Sakthipriyan Vairamani 571a517259 test: test sync version of mkdir & rmdir
This patch includes tests for sync versions of mkdir and rmdir.
Also, it moves the test to `parallel`.

PR-URL: https://github.com/nodejs/node/pull/2588
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
2015-09-21 12:42:45 +05:30

38 lines
1011 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const path = require('path');
const fs = require('fs');
const d = path.join(common.tmpDir, 'dir');
common.refreshTmpDir();
// Make sure the directory does not exist
assert(!common.fileExists(d));
// Create the directory now
fs.mkdirSync(d);
// Make sure the directory exists
assert(common.fileExists(d));
// Try creating again, it should fail with EEXIST
assert.throws(function() {
fs.mkdirSync(d);
}, /EEXIST: file already exists, mkdir/);
// Remove the directory now
fs.rmdirSync(d);
// Make sure the directory does not exist
assert(!common.fileExists(d));
// Similarly test the Async version
fs.mkdir(d, 0o666, function(err) {
assert.ifError(err);
fs.mkdir(d, 0o666, function(err) {
assert.ok(err.message.match(/^EEXIST/), 'got EEXIST message');
assert.equal(err.code, 'EEXIST', 'got EEXIST code');
assert.equal(err.path, d, 'got proper path for EEXIST');
fs.rmdir(d, assert.ifError);
});
});