Skip to content

Commit

Permalink
test: add test for range request on multi block CAR (#55)
Browse files Browse the repository at this point in the history
* test: add test for range request on multi block CAR

* fix: use proper range requested CAR file

* fix: test command
  • Loading branch information
guanzo authored Jan 24, 2024
1 parent fd4029d commit 1504fb0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"main": "src/index.js",
"type": "module",
"scripts": {
"test": "NODE_ENV=development TESTING=true node --test test/",
"test": "NODE_ENV=development TESTING=true node --test test/*",
"build": "webpack --mode production",
"prepack": "npm run build"
},
Expand Down
17 changes: 17 additions & 0 deletions test/car.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,23 @@ describe('CAR Verification', () => {
assert.strictEqual(actualContent, expectedContent)
})

it('should extract content from a valid multi block CAR with a range', async () => {
const cidPath = 'QmStvUMCtXxEb8wRjNSUqWwqHBEDhmnEd5nHp5siV7bm1Z'
const filepath = getFixturePath('multi_block_filtered.car')
const carStream = fs.createReadStream(filepath)

const contentItr = await extractVerifiedContent(cidPath, carStream, { rangeStart: 300, rangeEnd: 349 })
const buffer = await concatChunks(contentItr)
const actualContent = Buffer.from(buffer).toString('base64')

// To get this value:
// $ mkdir -p outdir && car x -f multi_block.car outdir
// $ dd status=none if=outdir/unknown of=/dev/stdout bs=1 skip=300 count=50 | base64
const expectedContent = 'Dubn28NGm5/ycJu4PqXEFrgvN0ys0yAwhuYjl2TV23ruEcDazo4LAzZSKF3JeNfCNgg='

assert.strictEqual(actualContent, expectedContent)
})

it('should verify intermediate path segments', async () => {
const cidPath =
'bafybeigeqgfwhivuuxgmuvcrrwvs4j3yfzgljssvnuqzokm6uby4fpmwsa/subdir/hello.txt'
Expand Down
Binary file added test/fixtures/multi_block.car
Binary file not shown.
Binary file added test/fixtures/multi_block_filtered.car
Binary file not shown.

0 comments on commit 1504fb0

Please sign in to comment.