Skip to content

Commit f89c204

Browse files
authored
clear tests (#3)
* clear tests * fix clear test
1 parent cc5a461 commit f89c204

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

Diff for: index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ module.exports = class HypercoreBlobServer {
428428
throw new Error('Must specify a filename or blob')
429429
}
430430

431-
const core = this._getCore(key, toInfo(key, blob, drive, filename, version), false)
431+
const core = await this._getCore(key, toInfo(key, blob, drive, filename, version), false)
432432
if (core === null) return null
433433

434434
if (blob) {

Diff for: test/blobs.js

+21
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,24 @@ test('handle invalid range header', async function (t) {
132132
t.is(res.status, 200)
133133
t.is(res.data, 'Hello World')
134134
})
135+
136+
test('server could clear blobs', async function (t) {
137+
const store = new Corestore(await tmp())
138+
139+
const core = store.get({ name: 'test' })
140+
await core.append([Buffer.from('abc'), Buffer.from('d'), Buffer.from('efg')])
141+
142+
const server = testBlobServer(t, store)
143+
await server.listen()
144+
145+
await server.clear(core.key, {
146+
blob: {
147+
blockOffset: 0,
148+
blockLength: 2
149+
}
150+
})
151+
152+
t.is(await core.get(0, { wait: false }), null)
153+
t.is(await core.get(1, { wait: false }), null)
154+
t.alike(await core.get(2, { wait: false }), Buffer.from('efg'))
155+
})

Diff for: test/drives.js

+21
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,24 @@ test('can select a file for full download', async function (t) {
178178
const dl = server.download(drive.key, { filename: '/file.txt' })
179179
await dl.done()
180180
})
181+
182+
test('server could clear files', async function (t) {
183+
const store = new Corestore(await tmp())
184+
185+
const drive = testHyperdrive(t, store)
186+
await drive.put('/file.txt', 'Here')
187+
await drive.put('/file2.txt', 'IAm')
188+
189+
const server = testBlobServer(t, store)
190+
await server.listen()
191+
192+
t.is((await drive.blobs.get({ blockOffset: 0, blockLength: 1, byteOffset: 0, byteLength: 4 }, { wait: false })).toString(), 'Here')
193+
t.is((await drive.blobs.get({ blockOffset: 1, blockLength: 1, byteOffset: 4, byteLength: 3 }, { wait: false })).toString(), 'IAm')
194+
195+
await server.clear(drive.key, {
196+
filename: '/file2.txt'
197+
})
198+
199+
t.is((await drive.blobs.get({ blockOffset: 0, blockLength: 1, byteOffset: 0, byteLength: 4 }, { wait: false })).toString(), 'Here')
200+
t.is(await drive.blobs.get({ blockOffset: 1, blockLength: 1, byteOffset: 4, byteLength: 3 }, { wait: false }), null)
201+
})

0 commit comments

Comments
 (0)