node-postgres/test/unit/test-helper.js

91 lines
2.0 KiB
JavaScript
Raw Normal View History

sys = require('sys');
assert = require('assert');
2010-10-11 11:42:13 +08:00
Client = require(__dirname+'/../../lib/client');
EventEmitter = require('events').EventEmitter;
BufferList = require(__dirname+'/buffer-list');
2010-10-11 11:42:13 +08:00
buffers = require(__dirname+'/test-buffers');
2010-09-30 13:32:44 +08:00
assert.same = function(actual, expected) {
for(var key in expected) {
assert.equal(actual[key], expected[key]);
}
};
2010-10-09 12:15:47 +08:00
assert.equalBuffers = function(actual, expected) {
if(actual.length != expected.length) {
console.log(actual);
console.log(expected);
assert.equal(actual.length, expected.length);
}
for(var i = 0; i < actual.length; i++) {
if(actual[i] != expected[i]) {
console.log(actual);
console.log(expected);
}
assert.equal(actual[i],expected[i]);
}
};
2010-10-07 10:34:51 +08:00
assert.empty = function(actual) {
2010-10-08 08:35:21 +08:00
assert.length(actual, 0);
2010-10-07 10:34:51 +08:00
};
2010-10-08 08:35:21 +08:00
assert.length = function(actual, expectedLength) {
assert.equal(actual.length, expectedLength);
};
2010-09-30 13:32:44 +08:00
test = function(name, action) {
2010-10-09 15:48:41 +08:00
try{
2010-10-23 13:49:27 +08:00
test.testCount ++;
var result = action();
if(result === false) {
test.ignored.push(name);
process.stdout.write('?');
}else{
process.stdout.write('.');
}
2010-10-09 15:48:41 +08:00
}catch(e) {
2010-10-24 01:30:55 +08:00
process.stdout.write('E');
2010-10-23 13:49:27 +08:00
test.errors.push(e);
2010-10-09 15:48:41 +08:00
}
};
2010-10-23 13:49:27 +08:00
test.testCount = 0;
test.ignored = [];
test.errors = [];
2010-10-23 13:52:16 +08:00
test.start = new Date();
2010-10-23 13:49:27 +08:00
2010-10-14 13:06:09 +08:00
process.on('exit', function() {
console.log('');
2010-10-23 13:52:16 +08:00
var duration = ((new Date() - test.start)/1000);
console.log('Ran ' + test.testCount + ' tests in ' + duration + ' seconds');
2010-10-23 13:49:27 +08:00
test.ignored.forEach(function(name) {
console.log("Ignored: " + name);
});
2010-10-24 01:30:55 +08:00
test.errors.forEach(function(error) {
throw error;
});
2010-10-14 13:06:09 +08:00
});
2010-09-29 12:30:06 +08:00
2010-10-07 08:59:20 +08:00
MemoryStream = function() {
EventEmitter.call(this);
2010-10-07 10:34:51 +08:00
this.packets = [];
2010-10-07 08:59:20 +08:00
};
sys.inherits(MemoryStream, EventEmitter);
var p = MemoryStream.prototype;
2010-10-08 09:00:49 +08:00
p.write = function(packet) {
this.packets.push(packet);
};
createClient = function() {
var stream = new MemoryStream();
stream.readyState = "open";
var client = new Client({
stream: stream
});
client.connect();
2010-10-20 12:02:33 +08:00
return client;
};