node-postgres/test/parser-tests.js

33 lines
1.2 KiB
JavaScript
Raw Normal View History

require(__dirname+'/test-helper');
test('Parser on single messages', function() {
test('parses AuthenticationOk message', function() {
2010-09-29 13:12:04 +08:00
var result = new Parser().parse(Buffer([0x52, 00, 00, 00, 08, 00, 00, 00, 00]));
assert.equal(result.name, 'AuthenticationOk');
assert.equal(result.id, 'R');
assert.equal(result.length, 8);
});
2010-09-29 12:31:40 +08:00
test('parses ParameterStatus message', function() {
var firstString = [0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x5f, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0];
var secondString = [0x55, 0x54, 0x46, 0x38, 0];
var bytes = [0x53, 0, 0, 0, 0x19].concat(firstString).concat(secondString);
2010-09-29 13:12:04 +08:00
var result = new Parser().parse(Buffer(bytes));
2010-09-29 13:08:53 +08:00
assert.equal(result.name, 'ParameterStatus');
assert.equal(result.id, 'S');
assert.equal(result.length, 25);
assert.equal(result.parameterName, "client_encoding");
assert.equal(result.parameterValue, "UTF8");
2010-09-29 12:31:40 +08:00
});
2010-09-29 13:20:10 +08:00
test('parses normal CString', function() {
var result = new Parser().parseCString(Buffer([33,00]));
assert.equal(result,"!");
});
test('parses empty CString', function() {
var result = new Parser().parseCString(Buffer([0]));
assert.equal(result, '');
});
});