Skip to content

Commit

Permalink
add deflate option assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Turney committed Nov 30, 2016
1 parent af32058 commit 8997572
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion graylog.js
Expand Up @@ -2,7 +2,8 @@ var zlib = require('zlib'),
crypto = require('crypto'),
dgram = require('dgram'),
util = require('util'),
EventEmitter = require('events').EventEmitter;
EventEmitter = require('events').EventEmitter,
assert = require('assert');

/**
* Graylog instances emit errors. That means you really really should listen for them,
Expand All @@ -19,6 +20,9 @@ var graylog = function graylog(config) {
this.hostname = config.hostname || require('os').hostname();
this.facility = config.facility || 'Node.js';
this.deflate = config.deflate || 'optimal';
assert(
this.deflate === 'optimal' || this.deflate === 'always' || this.deflate === 'never',
'deflate must be one of "optimal", "always", or "never". was "' + this.deflate + '"');

this._unsentMessages = 0;
this._unsentChunks = 0;
Expand Down
17 changes: 17 additions & 0 deletions test.js
@@ -1,5 +1,6 @@
var graylog = require('./graylog'),
fs = require('fs'),
assert = require('assert'),
file,
data,
servers = [
Expand Down Expand Up @@ -66,3 +67,19 @@ client.close(function () {
console.log('Insertion complete. Please check', 'http://' + servers[0].host + ':3000', 'and verify that insertion was successfull');
console.log('');
});

console.log('---------------------------------------------');
console.log('Checking deflate assertion');
console.log('---------------------------------------------');
try {
new graylog.graylog({
servers: servers,
facility: 'Test logger / Node.JS Test Script',
deflate: 'not an option'
});
throw new Error('should not get here')
} catch (err) {
assert(
err.message === 'deflate must be one of "optimal", "always", or "never". was "not an option"',
'assertion msg was wrong: ' + err.message);
}

0 comments on commit 8997572

Please sign in to comment.