test refactoring

This commit is contained in:
Brian Carlson 2010-12-14 19:23:01 -06:00
parent af997d914b
commit fb463923d8
5 changed files with 55 additions and 33 deletions

View File

@ -51,4 +51,3 @@ test("multiple select statements", function() {
});
client.on('drain', client.end.bind(client));
});

View File

@ -14,5 +14,6 @@ module.exports = {
return client;
},
connectionString: helper.connectionString,
Sink: helper.Sink
Sink: helper.Sink,
pg: helper.pg
};

View File

@ -1,9 +1,9 @@
var helper = require(__dirname + '/test-helper');
var client = helper.client();
client.on('drain', client.end.bind(client));
var sink;
var connectionString = helper.connectionString();
var testForTypeCoercion = function(type){
helper.pg.connect(connectionString, function(err, client) {
assert.isNull(err)
client.query("create temp table test_type(col " + type.name + ")");
test("Coerces " + type.name, function() {
@ -28,10 +28,12 @@ var testForTypeCoercion = function(type){
name: 'delete values',
text: 'delete from test_type'
});
sink.add();
});
client.query('drop table test_type');
});
})
};
var types = [{
@ -76,9 +78,18 @@ var types = [{
values: ['13:12:12.321', null]
}];
var valueCount = 0;
types.forEach(function(type) {
valueCount += type.values.length;
})
sink = new helper.Sink(valueCount, function() {
helper.pg.end();
})
types.forEach(testForTypeCoercion);
test("timestampz round trip", function() {
var now = new Date();
var client = helper.client();
client.on('error', function(err) {
@ -112,6 +123,7 @@ test("timestampz round trip", function() {
});
});
client.on('drain', client.end.bind(client));
});

View File

@ -11,10 +11,19 @@ var testPoolSize = function(max) {
test("can pool " + max + " times", function() {
for(var i = 0; i < max; i++) {
helper.pg.poolSize = 10;
test("connection #" + i + " executes", function() {
helper.pg.connect(conString, function(err, client) {
assert.isNull(err);
client.query("select * from NOW()", function() {
sink.add();
client.query("select * from person", function(err, result) {
assert.length(result.rows, 26)
})
client.query("select count(*) as c from person", function(err, result) {
assert.equal(result.rows[0].c, 26)
})
var query = client.query("SELECT * FROM NOW()")
query.on('end',function() {
sink.add()
})
})
})
}

View File

@ -173,6 +173,7 @@ var Sink = function(expected, timeout, callback) {
module.exports = {
args: args,
Sink: Sink,
pg: require('index'),
connectionString: function() {
return "pg"+(count++)+"://"+args.user+":"+args.password+"@"+args.host+":"+args.port+"/"+args.database;
}