From 4519dd00f936ebdfe3de4e08763ae587c445cb32 Mon Sep 17 00:00:00 2001 From: Sakthipriyan Vairamani Date: Fri, 28 Aug 2015 07:01:11 +0530 Subject: [PATCH] test: test sync version of mkdir & rmdir MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Reviewed-By: Johan Bergström --- test/parallel/test-fs-mkdir-rmdir.js | 37 +++++++++++++++++++++++++++++++ test/sequential/test-mkdir-rmdir.js | 43 ------------------------------------ 2 files changed, 37 insertions(+), 43 deletions(-) create mode 100644 test/parallel/test-fs-mkdir-rmdir.js delete mode 100644 test/sequential/test-mkdir-rmdir.js diff --git a/test/parallel/test-fs-mkdir-rmdir.js b/test/parallel/test-fs-mkdir-rmdir.js new file mode 100644 index 0000000..0bddf67 --- /dev/null +++ b/test/parallel/test-fs-mkdir-rmdir.js @@ -0,0 +1,37 @@ +'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); + }); +}); diff --git a/test/sequential/test-mkdir-rmdir.js b/test/sequential/test-mkdir-rmdir.js deleted file mode 100644 index 976dbf6..0000000 --- a/test/sequential/test-mkdir-rmdir.js +++ /dev/null @@ -1,43 +0,0 @@ -'use strict'; -var common = require('../common'); -var assert = require('assert'); -var path = require('path'); -var fs = require('fs'); - -common.refreshTmpDir(); - -var dirname = path.dirname(__filename); -var d = path.join(common.tmpDir, 'dir'); - -var mkdir_error = false; -var rmdir_error = false; - -fs.mkdir(d, 0o666, function(err) { - if (err) { - console.log('mkdir error: ' + err.message); - mkdir_error = true; - } else { - fs.mkdir(d, 0o666, function(err) { - console.log('expect EEXIST error: ', 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'); - - console.log('mkdir okay!'); - fs.rmdir(d, function(err) { - if (err) { - console.log('rmdir error: ' + err.message); - rmdir_error = true; - } else { - console.log('rmdir okay!'); - } - }); - }); - } -}); - -process.on('exit', function() { - assert.equal(false, mkdir_error); - assert.equal(false, rmdir_error); - console.log('exit'); -}); -- 2.7.4