Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRebecca Turner <me@re-becca.org>2015-07-09 10:27:41 +0300
committerRebecca Turner <me@re-becca.org>2015-07-18 08:21:02 +0300
commit9fafb184ce076150a2207790812a7d63c16d8c70 (patch)
tree4524db38464dc80025ccc605499752ae2b728ebf /test
parent6d59fcf4270230a50a33f61c2d59643798f7e2df (diff)
check-permissions: use inflight to eliminate duplicate checks of the same resource
PR-URL: https://github.com/npm/npm/pull/8974 Fixes: https://github.com/npm/npm/issues/8701 This was breaking things on windows due to locking around the files being created and removed.
Diffstat (limited to 'test')
-rw-r--r--test/tap/check-permissions.js88
1 files changed, 88 insertions, 0 deletions
diff --git a/test/tap/check-permissions.js b/test/tap/check-permissions.js
new file mode 100644
index 000000000..d3c0c6da2
--- /dev/null
+++ b/test/tap/check-permissions.js
@@ -0,0 +1,88 @@
+'use strict'
+var fs = require('fs')
+var path = require('path')
+var test = require('tap').test
+var rimraf = require('rimraf')
+var writable = require('../../lib/install/writable.js').fsAccessImplementation
+var writableFallback = require('../../lib/install/writable.js').fsOpenImplementation
+var exists = require('../../lib/install/exists.js').fsAccessImplementation
+var existsFallback = require('../../lib/install/exists.js').fsStatImplementation
+
+var testBase = path.resolve(__dirname, 'check-permissions')
+var existingDir = path.resolve(testBase, 'exists')
+var nonExistingDir = path.resolve(testBase, 'does-not-exist')
+var writableDir = path.resolve(testBase, 'writable')
+var nonWritableDir = path.resolve(testBase, 'non-writable')
+
+test('setup', function (t) {
+ cleanup()
+ setup()
+ t.end()
+})
+
+test('exists', function (t) {
+ t.plan(2)
+ // fs.access first introduced in node 0.12 / io.js
+ if (fs.access) {
+ existsTests(t, exists)
+ } else {
+ t.pass('# skip fs.access not available in this version')
+ t.pass('# skip fs.access not available in this version')
+ }
+})
+
+test('exists-fallback', function (t) {
+ t.plan(2)
+ existsTests(t, existsFallback)
+})
+
+test('writable', function (t) {
+ t.plan(2)
+ // fs.access first introduced in node 0.12 / io.js
+ if (fs.access) {
+ writableTests(t, writable)
+ } else {
+ t.pass('# skip fs.access not available in this version')
+ t.pass('# skip fs.access not available in this version')
+ }
+})
+
+test('writable-fallback', function (t) {
+ t.plan(2)
+ writableTests(t, writableFallback)
+})
+
+test('cleanup', function (t) {
+ cleanup()
+ t.end()
+})
+
+function setup () {
+ fs.mkdirSync(testBase)
+ fs.mkdirSync(existingDir)
+ fs.mkdirSync(writableDir)
+ fs.mkdirSync(nonWritableDir)
+ fs.chmodSync(nonWritableDir, '555')
+}
+
+function existsTests (t, exists) {
+ exists(existingDir, function (er) {
+ t.error(er, 'exists dir is exists')
+ })
+ exists(nonExistingDir, function (er) {
+ t.ok(er, 'non-existing dir resulted in an error')
+ })
+}
+
+function writableTests (t, writable) {
+ writable(writableDir, function (er) {
+ t.error(er, 'writable dir is writable')
+ })
+ writable(nonWritableDir, function (er) {
+ t.ok(er, 'non-writable dir resulted in an error')
+ })
+}
+
+function cleanup () {
+ rimraf.sync(testBase)
+}