Skip to content

Commit

Permalink
fix fixture file path
Browse files Browse the repository at this point in the history
  • Loading branch information
guanzo committed Sep 6, 2023
1 parent 181140a commit 0d4d861
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "src/index.js",
"type": "module",
"scripts": {
"test": "NODE_ENV=development node test/test.js",
"test": "NODE_ENV=development node --test test/",
"build": "webpack --mode production",
"prepack": "npm run build"
},
Expand Down
20 changes: 14 additions & 6 deletions test/car.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import assert from 'node:assert/strict'
import fs from 'node:fs'
import { describe, it } from 'node:test'
import { resolve, dirname } from 'node:path'
import { fileURLToPath } from 'node:url'

import { CarReader, CarWriter } from '@ipld/car'
import { CID } from 'multiformats/cid'

import { extractVerifiedContent } from '#src/utils/car.js'

const __dirname = dirname(fileURLToPath(import.meta.url))

function getFixturePath (filename) {
return resolve(__dirname, `./fixtures/${filename}`)
}

async function concatChunks (itr) {
const arr = []
for await (const chunk of itr) {
Expand All @@ -19,7 +27,7 @@ describe('CAR Verification', () => {
it('should extract content from a valid CAR', async () => {
const cidPath =
'bafkreifjjcie6lypi6ny7amxnfftagclbuxndqonfipmb64f2km2devei4'
const filepath = './fixtures/hello.car'
const filepath = getFixturePath('hello.car')
const carStream = fs.createReadStream(filepath)

const contentItr = await extractVerifiedContent(cidPath, carStream)
Expand All @@ -33,7 +41,7 @@ describe('CAR Verification', () => {
it('should verify intermediate path segments', async () => {
const cidPath =
'bafybeigeqgfwhivuuxgmuvcrrwvs4j3yfzgljssvnuqzokm6uby4fpmwsa/subdir/hello.txt'
const filepath = './fixtures/subdir.car'
const filepath = getFixturePath('subdir.car')
const carStream = fs.createReadStream(filepath)

const contentItr = await extractVerifiedContent(cidPath, carStream)
Expand All @@ -47,7 +55,7 @@ describe('CAR Verification', () => {
it('should verify identity cids', async () => {
const cidPath =
'bafyreiccg6dmxvt6twmzxtr4ujhaobrcucrsau6uopslvo5kq6n523btqi/identity'
const filepath = './fixtures/dag-cbor-with-identity.car'
const filepath = getFixturePath('dag-cbor-with-identity.car')
const carStream = fs.createReadStream(filepath)

const contentItr = await extractVerifiedContent(cidPath, carStream)
Expand All @@ -61,7 +69,7 @@ describe('CAR Verification', () => {
it('should traverse non-unixfs dag-cbor CARs', async () => {
const cidPath =
'bafyreibs4utpgbn7uqegmd2goqz4bkyflre2ek2iwv743fhvylwi4zeeim/foo/link/bar'
const filepath = './fixtures/dag-cbor-traversal.car'
const filepath = getFixturePath('dag-cbor-traversal.car')
const carStream = fs.createReadStream(filepath)

const contentItr = await extractVerifiedContent(cidPath, carStream)
Expand All @@ -75,7 +83,7 @@ describe('CAR Verification', () => {

it('should error if CAR is missing blocks', async () => {
const cidPath = 'bafybeigeqgfwhivuuxgmuvcrrwvs4j3yfzgljssvnuqzokm6uby4fpmwsa'
const filepath = './fixtures/subdir.car'
const filepath = getFixturePath('subdir.car')
const carStream = fs.createReadStream(filepath)

// Create an invalid CAR that only has 1 block but should have 3
Expand All @@ -101,7 +109,7 @@ describe('CAR Verification', () => {

it('should error if CAR blocks are in the wrong traversal order', async () => {
const cidPath = 'bafybeigeqgfwhivuuxgmuvcrrwvs4j3yfzgljssvnuqzokm6uby4fpmwsa'
const filepath = './fixtures/subdir.car'
const filepath = getFixturePath('subdir.car')
const carStream = fs.createReadStream(filepath)

// Create an invalid CAR that has blocks in the wrong order
Expand Down

0 comments on commit 0d4d861

Please sign in to comment.