Skip to content

Commit

Permalink
fix(codec): encode Modified state, throw error on invalid type
Browse files Browse the repository at this point in the history
  - Makefiles were updated to recursively run all tests
  - check added to Codec.encode to throw if the type is unknown
  - fixed Modified state to use 'boolean' instead of 'bool'
  - a few other test cleanups regarding naming, extraneous
    console.logs, etc

closes #176
  • Loading branch information
mbroadst committed Oct 20, 2015
1 parent 8c915d9 commit 271415c
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 10 deletions.
6 changes: 3 additions & 3 deletions Makefile
Expand Up @@ -21,13 +21,13 @@ codeclimate-send:
CODECLIMATE_REPO_TOKEN=2612b6d4b7bed06760320154f22eba4e348e53055c0eaf9a9a00e3b05ef3b37d codeclimate < coverage/lcov.info

test-unit: jshint
$(NPM_BIN)/mocha --globals setImmediate,clearImmediate --check-leaks --colors -t 10000 --reporter $(REPORTER) $(UNIT_TESTS) $(GREPARG)
$(NPM_BIN)/mocha --globals setImmediate,clearImmediate --recursive --check-leaks --colors -t 10000 --reporter $(REPORTER) $(UNIT_TESTS) $(GREPARG)

test-qpid: jshint
$(NPM_BIN)/mocha --globals setImmediate,clearImmediate --check-leaks --colors -t 10000 --reporter $(REPORTER) $(QPID_INTEGRATION_TESTS) $(GREPARG)
$(NPM_BIN)/mocha --globals setImmediate,clearImmediate --recursive --check-leaks --colors -t 10000 --reporter $(REPORTER) $(QPID_INTEGRATION_TESTS) $(GREPARG)

test-servicebus: jshint
$(NPM_BIN)/mocha --recursive --globals setImmediate,clearImmediate --check-leaks --colors -t 10000 --reporter $(REPORTER) $(SERVICEBUS_INTEGRATION_TESTS) $(GREPARG)
$(NPM_BIN)/mocha --recursive --globals setImmediate,clearImmediate --recursive --check-leaks --colors -t 10000 --reporter $(REPORTER) $(SERVICEBUS_INTEGRATION_TESTS) $(GREPARG)

test: test-unit test-qpid test-servicebus

Expand Down
6 changes: 3 additions & 3 deletions Makefile.win
Expand Up @@ -26,13 +26,13 @@ codeclimate-send:
CODECLIMATE_REPO_TOKEN=2612b6d4b7bed06760320154f22eba4e348e53055c0eaf9a9a00e3b05ef3b37d codeclimate < coverage\lcov.info

test-unit: jshint
$(NPM_BIN)\mocha.cmd --globals setImmediate,clearImmediate --check-leaks --colors -t 10000 --reporter $(REPORTER) $(UNIT_TESTS) $(GREPARG)
$(NPM_BIN)\mocha.cmd --globals setImmediate,clearImmediate --recursive --check-leaks --colors -t 10000 --reporter $(REPORTER) $(UNIT_TESTS) $(GREPARG)

test-qpid: jshint
$(NPM_BIN)\mocha.cmd --globals setImmediate,clearImmediate --check-leaks --colors -t 10000 --reporter $(REPORTER) $(QPID_INTEGRATION_TESTS) $(GREPARG)
$(NPM_BIN)\mocha.cmd --globals setImmediate,clearImmediate --recursive --check-leaks --colors -t 10000 --reporter $(REPORTER) $(QPID_INTEGRATION_TESTS) $(GREPARG)

test-servicebus: jshint
$(NPM_BIN)\mocha.cmd --recursive --globals setImmediate,clearImmediate --check-leaks --colors -t 10000 --reporter $(REPORTER) $(SERVICEBUS_INTEGRATION_TESTS) $(GREPARG)
$(NPM_BIN)\mocha.cmd --recursive --globals setImmediate,clearImmediate --recursive --check-leaks --colors -t 10000 --reporter $(REPORTER) $(SERVICEBUS_INTEGRATION_TESTS) $(GREPARG)

test: test-unit test-qpid test-servicebus

Expand Down
1 change: 1 addition & 0 deletions lib/codec.js
Expand Up @@ -189,6 +189,7 @@ Codec.prototype.encode = function(val, buf, forceType) {

if (!!forceType) {
encoder = types.builders[forceType] || types.buildersByCode[forceType];
if (encoder === undefined) throw new errors.EncodingError(forceType);
return encoder(val, buf, this);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/types/delivery_state.js
Expand Up @@ -166,8 +166,8 @@ Modified.fromDescribedType = function(describedType) {
Modified.prototype.getValue = function() {
var self = this;
return [
new ForcedType('bool', self.deliveryFailed),
new ForcedType('bool', self.undeliverableHere),
new ForcedType('boolean', self.deliveryFailed),
new ForcedType('boolean', self.undeliverableHere),
new AMQPFields(self.messageAnnotations)
];
};
Expand Down
1 change: 0 additions & 1 deletion test/unit/mocks/server.js
Expand Up @@ -108,7 +108,6 @@ function convertSequenceFramesToBuffers(frame) {
*/
MockServer.prototype.setExpectedFrameSequence = function(expected) {
this._expectedFrames = expected.map(convertSequenceFramesToBuffers);
console.log(this._expectedFrames[0].toString('hex'));
};

MockServer.prototype.setResponseSequence = function(responses) {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/policies/qpid_java.test.js
Expand Up @@ -26,7 +26,7 @@ function buildInitialResponseFor(user, pass) {
return buf.get();
}

describe('Client', function() {
describe('QpidJava Policy', function() {
describe('#connect()', function() {
beforeEach(function() {
if (!!test.server) test.server = undefined;
Expand Down
7 changes: 7 additions & 0 deletions test/unit/test_types.js
Expand Up @@ -35,6 +35,13 @@ describe('Types', function() {
expect(function() { codec.encode(type, buffer); }).to.throw(errors.NotImplementedError);
});
});

it('should throw an EncodingError for invalid ForcedTypes', function() {
var invalidType = new ForcedType('bazookas', 'hello world');
var invalid = function() { codec.encode(invalidType, new BufferBuilder()); };
expect(invalid).to.throw(errors.EncodingError);
expect(invalid).to.throw(/bazookas/);
});
});

describe('primitives', function() {
Expand Down
21 changes: 21 additions & 0 deletions test/unit/types/delivery_state.test.js
@@ -0,0 +1,21 @@
"use strict";
var BufferBuilder = require('buffer-builder'),
expect = require('chai').expect,

codec = require('../../../lib/codec'),
DeliveryState = require('../../../lib/types/delivery_state');

// @todo: this suite could use some actual structure, but for the moment
// accurately tests the issue reported
describe('Types(DeliveryState)', function() {
it('should encode Modified states', function() {
var buffer = new BufferBuilder();
var type = new DeliveryState.Modified({
deliveryFailed: true, undeliverableHere: true, messageAnnotations: {}
});

codec.encode(type, buffer);
expect(buffer.get())
.to.eql(new Buffer([0x00, 0x53, 0x27, 0xc0, 0x06, 0x03, 0x41, 0x41, 0xc1, 0x01, 0x00]));
});
});

0 comments on commit 271415c

Please sign in to comment.