error test

This commit is contained in:
brianc 2011-02-24 21:50:17 -06:00
parent f4ca716b93
commit b7c3db5f32
3 changed files with 32 additions and 7 deletions

View File

@ -99,7 +99,13 @@ public:
{
HandleScope scope;
Connection *self = ObjectWrap::Unwrap<Connection>(args.This());
printf("%d\n", args.Length());
if(!args[0]->IsString()) {
return ThrowException(Exception::Error(String::New("First parameter must be a string query")));
}
String::Utf8Value queryText(args[0]->ToString());
int result = self->Send(*queryText);
return Undefined();
}

View File

@ -6,13 +6,24 @@ test('query with non-text as first parameter throws error', function() {
var client = new Client(conString);
client.connect();
assert.emits(client, 'connect', function() {
var err;
try{
assert.throws(function() {
client.query({text:{fail: true}});
} catch(e) {
err = e;
}
assert.ok(err != null, "Expected exception to be thrown")
})
client.end();
})
})
test('parameterized query with non-text as first parameter throws error', function() {
var client = new Client(conString);
client.connect();
assert.emits(client, 'connect', function() {
assert.throws(function() {
client.query({
text: {fail: true},
values: [1, 2]
})
})
client.end();
})
})

View File

@ -100,6 +100,14 @@ assert.success = function(callback) {
})
}
assert.throws = function(offender) {
try {
offender();
} catch (e) {
return;
}
assert.ok(false, "Expected " + offender + " to throw exception");
}
assert.length = function(actual, expectedLength) {
assert.equal(actual.length, expectedLength);