Skip to content

Commit 619783b

Browse files
author
rpedela
committed
brianc#701 Add tests for new error fields in 9.3+.
1 parent f4579b7 commit 619783b

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

test/integration/client/query-error-handling-tests.js

+47
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,50 @@ test('error during query execution', function() {
3535
}));
3636
}));
3737
});
38+
39+
test('9.3 column error fields', function() {
40+
var client = new Client(helper.args);
41+
client.connect(assert.success(function() {
42+
helper.versionGTE(client, '9.3.0', assert.success(function(isGreater) {
43+
if(!isGreater) {
44+
console.log('skip 9.3 error field on older versions of postgres');
45+
return client.end();
46+
}
47+
48+
client.query('DROP TABLE IF EXISTS column_err_test');
49+
client.query('CREATE TABLE column_err_test(a int NOT NULL)');
50+
client.query('INSERT INTO column_err_test(a) VALUES (NULL)', function (err) {
51+
assert.equal(err.severity, 'ERROR');
52+
assert.equal(err.code, '23502');
53+
assert.equal(err.schema, 'public');
54+
assert.equal(err.table, 'column_err_test');
55+
assert.equal(err.column, 'a');
56+
return client.end();
57+
});
58+
}));
59+
}));
60+
});
61+
62+
test('9.3 constraint error fields', function() {
63+
var client = new Client(helper.args);
64+
client.connect(assert.success(function() {
65+
helper.versionGTE(client, '9.3.0', assert.success(function(isGreater) {
66+
if(!isGreater) {
67+
console.log('skip 9.3 error field on older versions of postgres');
68+
return client.end();
69+
}
70+
71+
client.query('DROP TABLE IF EXISTS constraint_err_test');
72+
client.query('CREATE TABLE constraint_err_test(a int PRIMARY KEY)');
73+
client.query('INSERT INTO constraint_err_test(a) VALUES (1)');
74+
client.query('INSERT INTO constraint_err_test(a) VALUES (1)', function (err) {
75+
assert.equal(err.severity, 'ERROR');
76+
assert.equal(err.code, '23505');
77+
assert.equal(err.schema, 'public');
78+
assert.equal(err.table, 'constraint_err_test');
79+
assert.equal(err.constraint, 'constraint_err_test_pkey');
80+
return client.end();
81+
});
82+
}));
83+
}));
84+
});

0 commit comments

Comments
 (0)