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

sync.js « test « chmodr « node_modules - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 71f90cd1ee96d2415e0b35a66be6247220900bd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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()
    })
  })
}