Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize prewrite test for memory-level #90

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion test/hooks/prewrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ module.exports = function (test, testCommon) {
const db = testCommon.factory()
await db.open()

const textDecoder = new TextDecoder()
const books = db.sublevel('books', { valueEncoding: 'json' })
const index = db.sublevel('authors', {
// Use JSON, which normally doesn't make sense for keys but
Expand All @@ -779,7 +780,14 @@ module.exports = function (test, testCommon) {
db.on('write', (ops) => {
// Check that data is written to correct sublevels, specifically
// !authors!Hesse~12 rather than !books!!authors!Hesse~12.
t.same(ops.map(x => x.key), ['!books!12', '!authors!"Hesse~12"'])
t.same(ops.map(x => decode(x.key)), ['!books!12', '!authors!"Hesse~12"'])

// It's unfortunate DX but because the write is made via the sublevel, the
// format of keys depends on the supported encodings of db. For example on
// a MemoryLevel({ storeEncoding: 'buffer' }) the key will be a buffer.
function decode (key) {
return db.keyEncoding('utf8').format === 'utf8' ? key : textDecoder.decode(key)
}
})

books.on('write', (ops) => {
Expand Down
Loading