Skip to content

Commit

Permalink
Add failing test for reopening
Browse files Browse the repository at this point in the history
  • Loading branch information
jmatsushita committed May 6, 2023
1 parent 03adc85 commit b75daed
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ require('./random.js')
require('./del.js')
require('./reopen.js')
require('./simple.js')
require('./simple-reopen.js')
27 changes: 27 additions & 0 deletions test/simple-reopen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const b4a = require('b4a')
const test = require('brittle')

const { storage, write, read, teardown, close } = require('./helpers')

test('simple reopen', async function (t) {
t.teardown(teardown())

const cool = storage('cool.txt', { size: 5 })
t.is(cool.name, 'cool.txt')
await write(cool, 100, b4a.from('GREETINGS'))
const fstbuf = await read(cool, 100, 9)
t.is(b4a.toString(fstbuf, 'utf-8'), 'GREETINGS')
const sndbuf = await read(cool, 104, 3)
t.is(b4a.toString(sndbuf, 'utf-8'), 'TIN')
console.log('before closing')
await close(cool)
console.log('after closing')
const cool2 = storage('cool.txt', { size: 5 })
console.log('after reopening')
try {
const reopenbuf = await read(cool2, 100, 9)
t.is(b4a.toString(reopenbuf, 'utf-8'), 'GREETINGS')
} catch (err) {
console.log('after read error', err)
};
})

0 comments on commit b75daed

Please sign in to comment.