more integration tests for new api
This commit is contained in:
parent
0bde640bab
commit
f7d990068f
@ -8,30 +8,44 @@ var preparedCalled = false
|
||||
pg.connect(helper.args, function(err, client) {
|
||||
connected = true
|
||||
test('error is null', function() {
|
||||
assert.equal(err, null)
|
||||
assert.equal(err, null);
|
||||
})
|
||||
|
||||
client.query('CREATE TEMP TABLE band(name varchar(100))');
|
||||
|
||||
['the flaming lips', 'wolf parade', 'radiohead', 'bright eyes', 'the beach boys', 'dead black hearts'].forEach(function(bandName) {
|
||||
client.query("INSERT INTO band (name) VALUES ('"+ bandName +"')")
|
||||
});
|
||||
|
||||
|
||||
test('simple query execution', function() {
|
||||
client.query('CREATE TEMP TABLE band(name varchar(100))')
|
||||
client.query("INSERT INTO band (name) VALUES ('dead black hearts')")
|
||||
client.query("SELECT * FROM band WHERE name = 'dead black hearts'", function(err, result) {
|
||||
client.query("SELECT * FROM band WHERE name = 'the beach boys'", function(err, result) {
|
||||
simpleCalled = true
|
||||
assert.equal(result.rows.pop().name, 'dead black hearts')
|
||||
})
|
||||
assert.length(result.rows, 1)
|
||||
assert.equal(result.rows.pop().name, 'the beach boys')
|
||||
});
|
||||
|
||||
})
|
||||
|
||||
test('prepared statement execution', function() {
|
||||
client.query('SELECT * FROM band WHERE name = $1', ['dead black hearts'], function(err, result) {
|
||||
preparedCalled = true
|
||||
assert.equal(result.rows.pop().name, 'dead black hearts')
|
||||
preparedCalled = true;
|
||||
assert.length(result.rows, 1);
|
||||
assert.equal(result.rows.pop().name, 'dead black hearts');
|
||||
})
|
||||
|
||||
client.query('SELECT * FROM band WHERE name LIKE $1 ORDER BY name', ['the %'], function(err, result) {
|
||||
assert.length(result.rows, 2);
|
||||
assert.equal(result.rows.pop().name, 'the flaming lips');
|
||||
assert.equal(result.rows.pop().name, 'the beach boys');
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
process.on('exit', function() {
|
||||
assert.ok(connected, 'never connected')
|
||||
assert.ok(simpleCalled, 'query result callback was never called')
|
||||
assert.ok(preparedCalled, 'prepared callback was never called')
|
||||
assert.ok(connected, 'never connected');
|
||||
assert.ok(simpleCalled, 'query result callback was never called');
|
||||
assert.ok(preparedCalled, 'prepared callback was never called');
|
||||
})
|
||||
|
||||
test('raises error if cannot connect', function() {
|
||||
|
Loading…
Reference in New Issue
Block a user