node-postgres/test/unit/client/prepared-statement-tests.js

87 lines
2.0 KiB
JavaScript
Raw Normal View History

2010-10-28 12:51:08 +08:00
var helper = require(__dirname + '/test-helper');
var client = helper.client();
var con = client.connection;
var parseArg = null;
con.parse = function(arg) {
parseArg = arg;
process.nextTick(function() {
con.emit('parseComplete');
});
2010-10-28 12:51:08 +08:00
};
var bindArg = null;
con.bind = function(arg) {
bindArg = arg;
process.nextTick(function(){
con.emit('bindComplete');
});
2010-10-28 12:51:08 +08:00
};
var executeArg = null;
con.execute = function(arg) {
executeArg = arg;
process.nextTick(function() {
con.emit('rowData',{ fields: [] });
con.emit('commandComplete', { text: "" });
});
2010-10-28 12:51:08 +08:00
};
var describeArg = null;
con.describe = function(arg) {
describeArg = arg;
process.nextTick(function() {
con.emit('rowDescription', { fields: [] });
});
2010-10-28 12:51:08 +08:00
};
var syncCalled = false;
con.flush = function() {
};
2010-10-28 12:51:08 +08:00
con.sync = function() {
syncCalled = true;
process.nextTick(function() {
con.emit('readyForQuery');
});
2010-10-28 12:51:08 +08:00
};
test('bound command', function() {
test('simple, unnamed bound command', function() {
assert.ok(client.connection.emit('readyForQuery'));
2010-10-28 12:51:08 +08:00
var query = client.query({
text: 'select * where name = $1',
values: ['hi']
2010-10-28 12:51:08 +08:00
});
assert.emits(query,'end', function() {
test('parse argument', function() {
assert.equal(parseArg.name, null);
assert.equal(parseArg.text, 'select * where name = $1');
assert.equal(parseArg.types, null);
});
2010-10-28 12:51:08 +08:00
test('bind argument', function() {
assert.equal(bindArg.statement, null);
assert.equal(bindArg.portal, null);
assert.lengthIs(bindArg.values, 1);
assert.equal(bindArg.values[0], 'hi')
});
2010-10-28 12:51:08 +08:00
test('describe argument', function() {
assert.equal(describeArg.type, 'P');
assert.equal(describeArg.name, "");
});
2010-10-28 12:51:08 +08:00
test('execute argument', function() {
assert.equal(executeArg.portal, null);
assert.equal(executeArg.rows, null);
});
2010-10-28 12:51:08 +08:00
test('sync called', function() {
assert.ok(syncCalled);
});
2010-10-28 12:51:08 +08:00
});
});
});