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

Commit 7f3edc4

Browse files
committed
chore: fix tests
1 parent b605a59 commit 7f3edc4

File tree

4 files changed

+25
-18
lines changed

4 files changed

+25
-18
lines changed

packages/interface-ipfs-core/src/key/gen.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ module.exports = (common, options) => {
2929

3030
it('should respect timeout option when generating a key', () => {
3131
return testTimeout(() => ipfs.key.gen(nanoid(), {
32+
type: 'rsa',
33+
size: 2048,
3234
timeout: 1
3335
}))
3436
})

packages/ipfs/src/http/api/resources/dht.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const Joi = require('../../utils/joi')
44
const Boom = require('@hapi/boom')
55
const all = require('it-all')
66
const pipe = require('it-pipe')
7-
const { Buffer } = require('buffer')
87
const ndjson = require('iterable-ndjson')
98
const toStream = require('it-to-stream')
109
const { map } = require('streaming-iterables')

packages/ipfs/src/http/utils/joi.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,24 @@ const toIpfsPath = (value) => {
1212
}
1313

1414
value = value.toString()
15+
let startedWithIpfs = false
1516

16-
if (!value.startsWith('/ipfs/')) {
17-
value = `/ipfs/${value}`
17+
if (value.startsWith('/ipfs/')) {
18+
startedWithIpfs = true
19+
value = value.replace(/^\/ipfs\//, '')
1820
}
1921

2022
// section after /ipfs/ should be a valid CID
2123
const parts = value.split('/')
2224

2325
// will throw if not valid
24-
parts[2] = new CID(parts[2])
26+
parts[0] = new CID(parts[0])
2527

26-
return parts.join('/')
28+
// go-ipfs returns /ipfs/ prefix for ipfs paths when passed to the http api
29+
// and not when it isn't. E.g.
30+
// GET /api/v0/ls?arg=/ipfs/Qmfoo -> /ipfs/Qmfoo will be in the result
31+
// GET /api/v0/ls?arg=Qmfoo -> Qmfoo will be in the result
32+
return `${startedWithIpfs ? '/ipfs/' : ''}${parts.join('/')}`
2733
}
2834

2935
const toCID = (value) => {

packages/ipfs/test/cli/get.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
const fs = require('fs')
55
const { expect } = require('interface-ipfs-core/src/utils/mocha')
66
const path = require('path')
7-
const rimraf = require('rimraf').sync
7+
const clean = require('../utils/clean')
88
const CID = require('cids')
99
const cli = require('../utils/cli')
1010
const sinon = require('sinon')
@@ -33,15 +33,15 @@ describe('get', () => {
3333
}])
3434

3535
const outPath = path.join(process.cwd(), cid.toString())
36-
rimraf(outPath)
36+
await clean(outPath)
3737

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

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

44-
rimraf(outPath)
44+
await clean(outPath)
4545
})
4646

4747
it('get file with output option', async () => {
@@ -53,15 +53,15 @@ describe('get', () => {
5353
}])
5454

5555
const outPath = path.join(process.cwd(), 'derp')
56-
rimraf(outPath)
56+
await clean(outPath)
5757

5858
const out = await cli(`get ${cid} --output ${outPath}`, { ipfs })
5959
expect(out)
6060
.to.equal(`Saving file(s) ${cid}\n`)
6161

6262
expect(fs.readFileSync(path.join(outPath, cid.toString()))).to.deep.equal(buf)
6363

64-
rimraf(outPath)
64+
await clean(outPath)
6565
})
6666

6767
it('get file with short output option', async () => {
@@ -73,15 +73,15 @@ describe('get', () => {
7373
}])
7474

7575
const outPath = path.join(process.cwd(), 'herp')
76-
rimraf(outPath)
76+
await clean(outPath)
7777

7878
const out = await cli(`get ${cid} -o ${outPath}`, { ipfs })
7979
expect(out)
8080
.to.equal(`Saving file(s) ${cid}\n`)
8181

8282
expect(fs.readFileSync(path.join(outPath, cid.toString()))).to.deep.equal(buf)
8383

84-
rimraf(outPath)
84+
await clean(outPath)
8585
})
8686

8787
it('get directory', async () => {
@@ -90,15 +90,15 @@ describe('get', () => {
9090
}])
9191

9292
const outPath = path.join(process.cwd(), cid.toString())
93-
rimraf(outPath)
93+
await clean(outPath)
9494

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

9999
expect(fs.statSync(outPath).isDirectory()).to.be.true()
100100

101-
rimraf(outPath)
101+
await clean(outPath)
102102
})
103103

104104
it('get recursively', async () => {
@@ -112,7 +112,7 @@ describe('get', () => {
112112
}])
113113

114114
const outPath = path.join(process.cwd(), cid.toString())
115-
rimraf(outPath)
115+
await clean(outPath)
116116

117117
const out = await cli(`get ${cid}`, { ipfs })
118118
expect(out).to.eql(
@@ -123,7 +123,7 @@ describe('get', () => {
123123
expect(fs.statSync(path.join(outPath, 'foo.txt')).isFile()).to.be.true()
124124
expect(fs.readFileSync(path.join(outPath, 'foo.txt'))).to.deep.equal(buf)
125125

126-
rimraf(outPath)
126+
await clean(outPath)
127127
})
128128

129129
it('should get file with a timeout', async () => {
@@ -138,14 +138,14 @@ describe('get', () => {
138138
}])
139139

140140
const outPath = path.join(process.cwd(), cid.toString())
141-
rimraf(outPath)
141+
await clean(outPath)
142142

143143
const out = await cli(`get ${cid} --timeout=1s`, { ipfs })
144144
expect(out)
145145
.to.equal(`Saving file(s) ${cid}\n`)
146146

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

149-
rimraf(outPath)
149+
await clean(outPath)
150150
})
151151
})

0 commit comments

Comments
 (0)