Skip to content

Commit

Permalink
sqlite: add test conditional exception filter callback
Browse files Browse the repository at this point in the history
  • Loading branch information
louwers committed Feb 3, 2025
1 parent 9393375 commit 4adb1bf
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions test/parallel/test-sqlite-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,11 @@ suite('filter tables', () => {
if (options.error) {
t.assert.throws(applyChangeset, options.error);
} else {
applyChangeset();
try {
applyChangeset();
} catch (error) {
if (!options.expectError) throw error;
}
}

t.assert.strictEqual(database2.prepare('SELECT * FROM data1').all().length, options.data1);
Expand All @@ -407,6 +411,18 @@ suite('filter tables', () => {
});
});

test('database.createSession() - throw sometimes in filter callback', (t) => {
testFilter(t, {
filter: (tableName) => { if (tableName === 'data2') throw new Error(); else { return true; } },
// Only changes to data1 should be applied
// note that the changeset was not aborted
data1: 3,
data2: 0,
expectError: true
});
});


test('database.createSession() - do not return anything in filter callback', (t) => {
testFilter(t, {
filter: () => {},
Expand Down Expand Up @@ -439,7 +455,7 @@ suite('filter tables', () => {
test('database.createSession() - no filter callback', (t) => {
testFilter(t, {
filter: undefined,
// all changes should be applied
// All changes should be applied
data1: 3,
data2: 5
});
Expand Down

0 comments on commit 4adb1bf

Please sign in to comment.