| 1 |
'use strict'; |
| 2 |
|
| 3 |
var fs = require('graceful-fs'); |
| 4 |
var File = require('vinyl'); |
| 5 |
var expect = require('expect'); |
| 6 |
var miss = require('mississippi'); |
| 7 |
|
| 8 |
var vfs = require('../'); |
| 9 |
|
| 10 |
var cleanup = require('./utils/cleanup'); |
| 11 |
var isWindows = require('./utils/is-windows'); |
| 12 |
var testConstants = require('./utils/test-constants'); |
| 13 |
|
| 14 |
var from = miss.from; |
| 15 |
var pipe = miss.pipe; |
| 16 |
var concat = miss.concat; |
| 17 |
|
| 18 |
var inputBase = testConstants.inputBase; |
| 19 |
var outputBase = testConstants.outputBase; |
| 20 |
var inputPath = testConstants.inputPath; |
| 21 |
var contents = testConstants.contents; |
| 22 |
|
| 23 |
var clean = cleanup(outputBase); |
| 24 |
|
| 25 |
describe('.dest() with custom owner', function() { |
| 26 |
|
| 27 |
beforeEach(clean); |
| 28 |
afterEach(clean); |
| 29 |
|
| 30 |
it('calls fchown when the uid and/or gid are provided on the vinyl stat', function(done) { |
| 31 |
if (isWindows) { |
| 32 |
this.skip(); |
| 33 |
return; |
| 34 |
} |
| 35 |
|
| 36 |
var fchownSpy = expect.spyOn(fs, 'fchown').andCallThrough(); |
| 37 |
|
| 38 |
var file = new File({ |
| 39 |
base: inputBase, |
| 40 |
path: inputPath, |
| 41 |
contents: new Buffer(contents), |
| 42 |
stat: { |
| 43 |
uid: 1001, |
| 44 |
gid: 1001, |
| 45 |
}, |
| 46 |
}); |
| 47 |
|
| 48 |
function assert() { |
| 49 |
expect(fchownSpy.calls.length).toEqual(1); |
| 50 |
expect(fchownSpy.calls[0].arguments[1]).toEqual(1001); |
| 51 |
expect(fchownSpy.calls[0].arguments[2]).toEqual(1001); |
| 52 |
} |
| 53 |
|
| 54 |
pipe([ |
| 55 |
from.obj([file]), |
| 56 |
vfs.dest(outputBase), |
| 57 |
concat(assert), |
| 58 |
], done); |
| 59 |
}); |
| 60 |
|
| 61 |
it('does not call fchown when the uid and gid provided on the vinyl stat are invalid', function(done) { |
| 62 |
if (isWindows) { |
| 63 |
this.skip(); |
| 64 |
return; |
| 65 |
} |
| 66 |
|
| 67 |
var fchownSpy = expect.spyOn(fs, 'fchown').andCallThrough(); |
| 68 |
|
| 69 |
var file = new File({ |
| 70 |
base: inputBase, |
| 71 |
path: inputPath, |
| 72 |
contents: new Buffer(contents), |
| 73 |
stat: { |
| 74 |
uid: -1, |
| 75 |
gid: -1, |
| 76 |
}, |
| 77 |
}); |
| 78 |
|
| 79 |
function assert() { |
| 80 |
expect(fchownSpy.calls.length).toEqual(0); |
| 81 |
} |
| 82 |
|
| 83 |
pipe([ |
| 84 |
from.obj([file]), |
| 85 |
vfs.dest(outputBase), |
| 86 |
concat(assert), |
| 87 |
], done); |
| 88 |
}); |
| 89 |
}); |