test refactoring
This commit is contained in:
parent
af997d914b
commit
fb463923d8
@ -51,4 +51,3 @@ test("multiple select statements", function() {
|
||||
});
|
||||
client.on('drain', client.end.bind(client));
|
||||
});
|
||||
|
||||
|
@ -14,5 +14,6 @@ module.exports = {
|
||||
return client;
|
||||
},
|
||||
connectionString: helper.connectionString,
|
||||
Sink: helper.Sink
|
||||
Sink: helper.Sink,
|
||||
pg: helper.pg
|
||||
};
|
||||
|
@ -1,37 +1,39 @@
|
||||
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){
|
||||
client.query("create temp table test_type(col " + type.name + ")");
|
||||
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() {
|
||||
type.values.forEach(function(val) {
|
||||
test("Coerces " + type.name, function() {
|
||||
type.values.forEach(function(val) {
|
||||
|
||||
var insertQuery = client.query({
|
||||
name: 'insert type test ' + type.name,
|
||||
text: 'insert into test_type(col) VALUES($1)',
|
||||
values: [val]
|
||||
var insertQuery = client.query({
|
||||
name: 'insert type test ' + type.name,
|
||||
text: 'insert into test_type(col) VALUES($1)',
|
||||
values: [val]
|
||||
});
|
||||
|
||||
var query = client.query({
|
||||
name: 'get type ' + type.name ,
|
||||
text: 'select col from test_type'
|
||||
});
|
||||
|
||||
assert.emits(query, 'row', function(row) {
|
||||
assert.strictEqual(row.col, val, "expected " + type.name + " of " + val + " but got " + row[0]);
|
||||
});
|
||||
|
||||
client.query({
|
||||
name: 'delete values',
|
||||
text: 'delete from test_type'
|
||||
});
|
||||
sink.add();
|
||||
});
|
||||
|
||||
var query = client.query({
|
||||
name: 'get type ' + type.name ,
|
||||
text: 'select col from test_type'
|
||||
});
|
||||
|
||||
assert.emits(query, 'row', function(row) {
|
||||
assert.strictEqual(row.col, val, "expected " + type.name + " of " + val + " but got " + row[0]);
|
||||
});
|
||||
|
||||
client.query({
|
||||
name: 'delete values',
|
||||
text: 'delete from test_type'
|
||||
});
|
||||
client.query('drop table test_type');
|
||||
});
|
||||
|
||||
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));
|
||||
});
|
||||
|
||||
|
@ -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;
|
||||
helper.pg.connect(conString, function(err, client) {
|
||||
assert.isNull(err);
|
||||
client.query("select * from NOW()", function() {
|
||||
sink.add();
|
||||
test("connection #" + i + " executes", function() {
|
||||
helper.pg.connect(conString, function(err, client) {
|
||||
assert.isNull(err);
|
||||
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()
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user