• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var path = require('path')
2
3var test = require('tap').test
4var mkdtemp = require('tmp').dir
5var mkdirp = require('mkdirp')
6
7var vacuum = require('../vacuum.js')
8
9// CONSTANTS
10var TEMP_OPTIONS = {
11  unsafeCleanup: true,
12  mode: '0700'
13}
14
15var BASE_PATH = path.join('foo')
16var HOME_PATH = path.join(BASE_PATH, 'foo', 'bar')
17
18var messages = []
19function log () { messages.push(Array.prototype.slice.call(arguments).join(' ')) }
20
21var homePath, basePath, realHome
22test('xXx setup xXx', function (t) {
23  mkdtemp(TEMP_OPTIONS, function (er, tmpdir) {
24    t.ifError(er, 'temp directory exists')
25
26    homePath = path.resolve(tmpdir, HOME_PATH)
27    basePath = path.resolve(tmpdir, BASE_PATH)
28
29    realHome = process.env.HOME
30    process.env.HOME = homePath
31
32    mkdirp(homePath, function (er) {
33      t.ifError(er, 'made test path')
34      t.end()
35    })
36  })
37})
38
39test('do not remove home directory', function (t) {
40  vacuum(homePath, {purge: false, base: basePath, log: log}, function (er) {
41    t.ifError(er, 'cleaned up to base')
42    t.equal(messages[0], 'quitting because cannot remove home directory ' + homePath)
43    process.env.HOME = realHome
44    t.end()
45  })
46})
47