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 298
/
Copy pathget.spec.js
118 lines (99 loc) · 2.98 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* eslint-env mocha */
/* eslint max-nested-callbacks: ["error", 8] */
'use strict'
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const isNode = require('detect-node')
const series = require('async/series')
const loadFixture = require('aegir/fixtures')
const IPFSApi = require('../src')
const f = require('./utils/factory')
describe('.get (specific go-ipfs features)', function () {
this.timeout(20 * 1000)
function fixture (path) {
return loadFixture(path, 'interface-ipfs-core')
}
const smallFile = {
cid: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP',
data: fixture('js/test/fixtures/testfile.txt')
}
let ipfsd
let ipfs
before(function (done) {
series([
(cb) => f.spawn({ initOptions: { bits: 1024 } }, (err, _ipfsd) => {
expect(err).to.not.exist()
ipfsd = _ipfsd
ipfs = IPFSApi(_ipfsd.apiAddr)
cb()
}),
(cb) => ipfs.files.add(smallFile.data, cb)
], done)
})
after((done) => ipfsd.stop(done))
it('no compression args', (done) => {
ipfs.get(smallFile.cid, (err, files) => {
expect(err).to.not.exist()
expect(files).to.be.length(1)
expect(files[0].content.toString()).to.contain(smallFile.data.toString())
done()
})
})
it('archive true', (done) => {
ipfs.get(smallFile.cid, { archive: true }, (err, files) => {
expect(err).to.not.exist()
expect(files).to.be.length(1)
expect(files[0].content.toString()).to.contain(smallFile.data.toString())
done()
})
})
it('err with out of range compression level', (done) => {
ipfs.get(smallFile.cid, {
compress: true,
'compression-level': 10
}, (err, files) => {
expect(err).to.exist()
expect(err.toString()).to.equal('Error: Compression level must be between 1 and 9')
done()
})
})
// TODO Understand why this test started failing
it.skip('with compression level', (done) => {
ipfs.get(smallFile.cid, { compress: true, 'compression-level': 1 }, done)
})
it('add path containing "+"s (for testing get)', (done) => {
if (!isNode) {
return done()
}
const filename = 'ti,c64x+mega++mod-pic.txt'
const subdir = 'tmp/c++files'
const expectedCid = 'QmPkmARcqjo5fqK1V1o8cFsuaXxWYsnwCNLJUYS4KeZyff'
ipfs.add([{
path: subdir + '/' + filename,
content: Buffer.from(subdir + '/' + filename, 'utf-8')
}], (err, files) => {
expect(err).to.not.exist()
expect(files[2].hash).to.equal(expectedCid)
done()
})
})
it('get path containing "+"s', (done) => {
if (!isNode) {
return done()
}
const cid = 'QmPkmARcqjo5fqK1V1o8cFsuaXxWYsnwCNLJUYS4KeZyff'
let count = 0
ipfs.get(cid, (err, files) => {
expect(err).to.not.exist()
files.forEach((file) => {
if (file.path !== cid) {
count++
expect(file.path).to.contain('+')
if (count === 2) done()
}
})
})
})
})