Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
chore: add test for get with rawLeaves
Browse files Browse the repository at this point in the history
- add interface-core test for get with rawLeaves: true
- remove cli test for "raw" as core normalises the type to "file" so it was not testing a valid conditon

License: MIT
Signed-off-by: Oli Evans <[email protected]>
  • Loading branch information
olizilla committed May 10, 2021
1 parent a2c86d9 commit 5875102
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
13 changes: 13 additions & 0 deletions packages/interface-ipfs-core/src/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@ module.exports = (common, options) => {
expect(uint8ArrayConcat(await all(output[0].content))).to.eql(input)
})

it('should get a file added as CIDv1 with rawLeaves', async () => {
const input = uint8ArrayFromString(`TEST${Math.random()}`)

const res = await all(importer([{ content: input }], ipfs.block, { cidVersion: 1, rawLeaves: true }))

const cidv1 = res[0].cid
expect(cidv1.version).to.equal(1)

const output = await all(ipfs.get(cidv1))
expect(output[0].type).to.eql('file')
expect(uint8ArrayConcat(await all(output[0].content))).to.eql(input)
})

it('should get a BIG file', async () => {
for await (const file of ipfs.get(fixtures.bigFile.cid)) {
expect(file.path).to.equal(fixtures.bigFile.cid)
Expand Down
22 changes: 0 additions & 22 deletions packages/ipfs-cli/test/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,6 @@ describe('get', () => {
await clean(outPath)
})

it('should get file from a raw block', async () => {
const cid = new CID('bafkreifzjut3te2nhyekklss27nh3k72ysco7y32koao5eei66wof36n5e')
ipfs.get.withArgs(cid.toString(), defaultOptions).returns([{
type: 'raw',
path: 'bafkreifzjut3te2nhyekklss27nh3k72ysco7y32koao5eei66wof36n5e',
content: function * () {
yield buf
}
}])

const outPath = path.join(process.cwd(), cid.toString())
await clean(outPath)

const out = await cli(`get ${cid}`, { ipfs })
expect(out)
.to.equal(`Saving file(s) ${cid}\n`)

expect(fs.readFileSync(outPath)).to.deep.equal(buf)

await clean(outPath)
})

it('get file with output option', async () => {
ipfs.get.withArgs(cid.toString(), defaultOptions).returns([{
type: 'file',
Expand Down

0 comments on commit 5875102

Please sign in to comment.