You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

chown.js 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. 'use strict'
  2. var fs = require('graceful-fs')
  3. var path = require('path')
  4. var test = require('tap').test
  5. var rimraf = require('rimraf')
  6. var writeStream = require('../index.js')
  7. var target = path.resolve(__dirname, 'test-chown')
  8. test('chown works', function (t) {
  9. t.plan(1)
  10. var stream = writeStream(target, {chown: {uid: process.getuid(), gid: process.getgid()}})
  11. var hadError = false
  12. stream.on('error', function (er) {
  13. hadError = true
  14. console.log('#', er)
  15. })
  16. stream.on('close', function () {
  17. t.is(hadError, false, 'no errors before close')
  18. })
  19. stream.end()
  20. })
  21. test('chown fails', function (t) {
  22. t.plan(1)
  23. fs.chown = function (file, uid, gid, cb) {
  24. cb(new Error('TEST BREAK'))
  25. }
  26. var stream = writeStream(target, {chown: {uid: process.getuid(), gid: process.getgid()}})
  27. var hadError = false
  28. stream.on('error', function (er) {
  29. hadError = true
  30. console.log('#', er)
  31. })
  32. stream.on('close', function () {
  33. t.is(hadError, true, 'error before close')
  34. })
  35. stream.end()
  36. })
  37. test('cleanup', function (t) {
  38. rimraf.sync(target)
  39. t.end()
  40. })