2011-01-19 12:37:37 +08:00
|
|
|
var helper = require(__dirname + "/test-helper")
|
|
|
|
|
|
|
|
var testForTag = function(tagText, callback) {
|
|
|
|
test('includes command tag data for tag ' + tagText, function() {
|
|
|
|
|
|
|
|
var client = helper.client();
|
|
|
|
client.connection.emit('readyForQuery')
|
|
|
|
|
|
|
|
var query = client.query("whatever");
|
2011-10-11 08:21:06 +08:00
|
|
|
assert.lengthIs(client.connection.queries, 1)
|
2011-01-19 12:37:37 +08:00
|
|
|
|
|
|
|
assert.emits(query, 'end', function(result) {
|
|
|
|
assert.ok(result != null, "should pass something to this event")
|
|
|
|
callback(result)
|
|
|
|
})
|
|
|
|
|
|
|
|
client.connection.emit('commandComplete', {
|
|
|
|
text: tagText
|
|
|
|
});
|
|
|
|
|
|
|
|
client.connection.emit('readyForQuery');
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2011-01-19 14:35:32 +08:00
|
|
|
var check = function(oid, rowCount, command) {
|
2011-01-19 12:37:37 +08:00
|
|
|
return function(result) {
|
2011-01-19 14:35:32 +08:00
|
|
|
if(oid != null) {
|
|
|
|
assert.equal(result.oid, oid);
|
|
|
|
}
|
2011-01-19 12:37:37 +08:00
|
|
|
assert.equal(result.rowCount, rowCount);
|
2011-01-19 14:35:32 +08:00
|
|
|
assert.equal(result.command, command);
|
2011-01-19 12:37:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
testForTag("INSERT 0 3", check(0, 3, "INSERT"));
|
|
|
|
testForTag("INSERT 841 1", check(841, 1, "INSERT"));
|
|
|
|
testForTag("DELETE 10", check(null, 10, "DELETE"));
|
|
|
|
testForTag("UPDATE 11", check(null, 11, "UPDATE"));
|
|
|
|
testForTag("SELECT 20", check(null, 20, "SELECT"));
|