read-only-file-test.js 745 B

12345678910111213141516171819202122232425262728
  1. "use strict";
  2. var should = require('should')
  3. , fs = require('fs')
  4. , path = require('path')
  5. , streamroller = require('../lib/index.js');
  6. describe('when the destination file is read-only', function() {
  7. var testFile = path.join(__dirname, 'read-only-file.log');
  8. before(function() {
  9. fs.writeFileSync(
  10. testFile,
  11. "Some test content"
  12. );
  13. fs.chmodSync(testFile, 292 /* 0o444 - octal literals not allowed in old node */);
  14. });
  15. it('should generate an error when writing', function(done) {
  16. var stream = new streamroller.RollingFileStream(testFile);
  17. stream.on('error', function(e) {
  18. e.code.should.eql('EACCES');
  19. done();
  20. });
  21. });
  22. after(function() {
  23. fs.unlinkSync(testFile);
  24. });
  25. });