Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

test

  • Loading branch information...
commit 43f6e0ae03038e82d826858d8239c1b32eec6e97 1 parent 3ee5518
@isaacs authored
Showing with 121 additions and 0 deletions.
  1. +63 −0 test/basic.js
  2. +58 −0 test/sync.js
View
63 test/basic.js
@@ -0,0 +1,63 @@
+var chmodr = require("../")
+, test = require("tap").test
+, mkdirp = require("mkdirp")
+, rimraf = require("rimraf")
+, fs = require("fs")
+, dirs = []
+
+rimraf("/tmp/chmodr", function (er) {
+ if (er) throw er
+ var cnt = 5
+ for (var i = 0; i < 5; i ++) {
+ mkdirp(getDir(), then)
+ }
+ function then (er) {
+ if (er) throw er
+ if (-- cnt === 0) {
+ runTest()
+ }
+ }
+})
+
+function getDir () {
+ var dir = "/tmp/chmodr"
+
+ dir += "/" + Math.floor(Math.random() * Math.pow(16,4)).toString(16)
+ dirs.push(dir)
+ dir += "/" + Math.floor(Math.random() * Math.pow(16,4)).toString(16)
+ dirs.push(dir)
+ dir += "/" + Math.floor(Math.random() * Math.pow(16,4)).toString(16)
+ dirs.push(dir)
+ return dir
+}
+
+function runTest () {
+ test("should complete successfully", function (t) {
+ console.error("calling chmodr 0700")
+ chmodr("/tmp/chmodr", 0700, function (er) {
+ t.ifError(er)
+ t.end()
+ })
+ })
+
+ dirs.forEach(function (dir) {
+ test("verify "+dir, function (t) {
+ fs.stat(dir, function (er, st) {
+ if (er) {
+ t.ifError(er)
+ return t.end()
+ }
+ t.equal(st.mode & 0777, 0700, "mode should be 0700")
+ t.end()
+ })
+ })
+ })
+
+ test("cleanup", function (t) {
+ rimraf("/tmp/chmodr/", function (er) {
+ t.ifError(er)
+ t.end()
+ })
+ })
+}
+
View
58 test/sync.js
@@ -0,0 +1,58 @@
+var chmodr = require("../")
+, test = require("tap").test
+, mkdirp = require("mkdirp")
+, rimraf = require("rimraf")
+, fs = require("fs")
+, dirs = []
+
+rimraf("/tmp/chmodr", function (er) {
+ if (er) throw er
+ var cnt = 5
+ for (var i = 0; i < 5; i ++) {
+ mkdirp(getDir(), then)
+ }
+ function then (er) {
+ if (er) throw er
+ if (-- cnt === 0) {
+ runTest()
+ }
+ }
+})
+
+function getDir () {
+ var x = Math.floor(Math.random() * Math.pow(16,4)).toString(16);
+ var y = Math.floor(Math.random() * Math.pow(16,4)).toString(16);
+ var z = Math.floor(Math.random() * Math.pow(16,4)).toString(16);
+ var dir = "/tmp/chmodr/" + [x,y,z].join("/")
+ dirs.push(dir)
+ return dir
+}
+
+function runTest () {
+ test("should complete successfully", function (t) {
+ console.error("calling chmodr 0700")
+ chmodr.sync("/tmp/chmodr", 0700)
+ t.end()
+ })
+
+ dirs.forEach(function (dir) {
+ test("verify "+dir, function (t) {
+ fs.stat(dir, function (er, st) {
+ if (er) {
+ t.ifError(er)
+ return t.end()
+ }
+ t.equal(st.mode & 0777, 0700, "uid should be 0700")
+ t.end()
+ })
+ })
+ })
+
+ test("cleanup", function (t) {
+ rimraf("/tmp/chmodr", function (er) {
+ t.ifError(er)
+ t.end()
+ })
+ })
+}
+
Please sign in to comment.
Something went wrong with that request. Please try again.