This repository was archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 297
/
Copy pathget.spec.js
80 lines (61 loc) · 2.29 KB
/
get.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* eslint-env mocha */
/* eslint max-nested-callbacks: ["error", 8] */
'use strict'
const { expect } = require('interface-ipfs-core/src/utils/mocha')
const loadFixture = require('aegir/fixtures')
const f = require('./utils/factory')
describe('.get (specific go-ipfs features)', function () {
this.timeout(60 * 1000)
function fixture (path) {
return loadFixture(path, 'interface-ipfs-core')
}
const smallFile = {
cid: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP',
data: fixture('test/fixtures/testfile.txt')
}
let ipfs
before(async () => {
ipfs = (await f.spawn()).api
await ipfs.add(smallFile.data)
})
after(() => f.clean())
it('no compression args', async () => {
const files = await ipfs.get(smallFile.cid)
expect(files).to.be.length(1)
expect(files[0].content.toString()).to.contain(smallFile.data.toString())
})
it('archive true', async () => {
const files = await ipfs.get(smallFile.cid, { archive: true })
expect(files).to.be.length(1)
expect(files[0].content.toString()).to.contain(smallFile.data.toString())
})
it('err with out of range compression level', async () => {
await expect(ipfs.get(smallFile.cid, {
compress: true,
compressionLevel: 10
})).to.be.rejectedWith('compression level must be between 1 and 9')
})
// TODO Understand why this test started failing
it.skip('with compression level', async () => {
await ipfs.get(smallFile.cid, { compress: true, 'compression-level': 1 })
})
it('add path containing "+"s (for testing get)', async () => {
const filename = 'ti,c64x+mega++mod-pic.txt'
const subdir = 'tmp/c++files'
const expectedCid = 'QmPkmARcqjo5fqK1V1o8cFsuaXxWYsnwCNLJUYS4KeZyff'
const path = `${subdir}/${filename}`
const files = await ipfs.add([{
path,
content: Buffer.from(path)
}])
expect(files[2].hash).to.equal(expectedCid)
})
it('get path containing "+"s', async () => {
const cid = 'QmPkmARcqjo5fqK1V1o8cFsuaXxWYsnwCNLJUYS4KeZyff'
const files = await ipfs.get(cid)
expect(files).to.be.an('array').with.lengthOf(3)
expect(files[0]).to.have.property('path', cid)
expect(files[1]).to.have.property('path', `${cid}/c++files`)
expect(files[2]).to.have.property('path', `${cid}/c++files/ti,c64x+mega++mod-pic.txt`)
})
})