Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 9141594

Browse files
committed
migrate extra tests
1 parent 6fc3b18 commit 9141594

File tree

2 files changed

+76
-179
lines changed

2 files changed

+76
-179
lines changed

test/get.spec.js

Lines changed: 70 additions & 178 deletions
Original file line numberDiff line numberDiff line change
@@ -8,212 +8,104 @@ const dirtyChai = require('dirty-chai')
88
const expect = chai.expect
99
chai.use(dirtyChai)
1010
const isNode = require('detect-node')
11-
const fs = require('fs')
12-
const concat = require('concat-stream')
13-
const through = require('through2')
14-
const streamEqual = require('stream-equal')
15-
const path = require('path')
11+
const series = require('async/series')
1612
const loadFixture = require('aegir/fixtures')
1713
const FactoryClient = require('./ipfs-factory/client')
1814

19-
const testfile = loadFixture(__dirname, '/fixtures/testfile.txt')
20-
let testfileBig
21-
let tfbPath
15+
describe('.get (specific go-ipfs features)', function () {
16+
this.timeout(20 * 1000)
2217

23-
if (isNode) {
24-
tfbPath = path.join(__dirname, '/fixtures/15mb.random')
25-
testfileBig = fs.createReadStream(tfbPath, { bufferSize: 128 })
26-
}
18+
function fixture (path) {
19+
return loadFixture(__dirname, path, 'interface-ipfs-core')
20+
}
2721

28-
describe('.get', function () {
29-
this.timeout(80 * 1000)
22+
const smallFile = {
23+
cid: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP',
24+
data: fixture('../test/fixtures/testfile.txt')
25+
}
3026

3127
let ipfs
3228
let fc
3329

3430
before((done) => {
3531
fc = new FactoryClient()
36-
fc.spawnNode((err, node) => {
37-
expect(err).to.not.exist()
38-
ipfs = node
39-
done()
40-
})
41-
})
42-
43-
after((done) => fc.dismantle(done))
44-
45-
describe('Callback API', () => {
46-
this.timeout(80 * 1000)
47-
48-
it('add file for testing', (done) => {
49-
const expectedMultihash = 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP'
50-
51-
ipfs.files.add(testfile, (err, res) => {
52-
expect(err).to.not.exist()
53-
54-
expect(res).to.have.length(1)
55-
expect(res[0].hash).to.equal(expectedMultihash)
56-
expect(res[0].path).to.equal(expectedMultihash)
57-
done()
58-
})
59-
})
6032

61-
it('get with no compression args', (done) => {
62-
ipfs.get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', (err, res) => {
33+
series([
34+
(cb) => fc.spawnNode((err, node) => {
6335
expect(err).to.not.exist()
36+
ipfs = node
37+
cb()
38+
}),
39+
(cb) => ipfs.files.add(smallFile.data, cb)
40+
], done)
41+
})
6442

65-
// accumulate the files and their content
66-
var files = []
67-
68-
res.pipe(through.obj((file, enc, next) => {
69-
file.content.pipe(concat((content) => {
70-
files.push({
71-
path: file.path,
72-
content: content
73-
})
74-
next()
75-
}))
76-
}, () => {
77-
expect(files).to.be.length(1)
78-
expect(files[0].content.toString()).to.contain(testfile.toString())
79-
done()
80-
}))
81-
})
82-
})
43+
after((done) => fc.dismantle(done))
8344

84-
it('get with archive true', (done) => {
85-
ipfs.get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', {
86-
archive: true
87-
}, (err, res) => {
88-
expect(err).to.not.exist()
45+
it('no compression args', (done) => {
46+
ipfs.get(smallFile.cid, (err, files) => {
47+
expect(err).to.not.exist()
8948

90-
// accumulate the files and their content
91-
var files = []
92-
93-
res.pipe(through.obj((file, enc, next) => {
94-
file.content.pipe(concat((content) => {
95-
files.push({
96-
path: file.path,
97-
content: content
98-
})
99-
next()
100-
}))
101-
}, () => {
102-
expect(files).to.be.length(1)
103-
expect(files[0].content.toString()).to.contain(testfile.toString())
104-
done()
105-
}))
106-
})
49+
expect(files).to.be.length(1)
50+
expect(files[0].content.toString()).to.contain(smallFile.data.toString())
51+
done()
10752
})
53+
})
10854

109-
it('get err with out of range compression level', (done) => {
110-
ipfs.get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', {
111-
compress: true,
112-
'compression-level': 10
113-
}, (err, res) => {
114-
expect(err).to.exist()
115-
expect(err.toString()).to.equal('Error: Compression level must be between 1 and 9')
116-
done()
117-
})
118-
})
55+
it('archive true', (done) => {
56+
ipfs.get(smallFile.cid, { archive: true }, (err, files) => {
57+
expect(err).to.not.exist()
11958

120-
it('get with compression level', (done) => {
121-
ipfs.get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', {
122-
compress: true,
123-
'compression-level': 1
124-
}, (err, res) => {
125-
expect(err).to.not.exist()
126-
done()
127-
})
59+
expect(files).to.be.length(1)
60+
expect(files[0].content.toString()).to.contain(smallFile.data.toString())
61+
done()
12862
})
63+
})
12964

130-
it('add a BIG file (for testing get)', (done) => {
131-
if (!isNode) { return done() }
132-
133-
const bigFile = fs.readFileSync(tfbPath)
134-
const expectedMultihash = 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq'
135-
136-
ipfs.files.add(bigFile, (err, res) => {
137-
expect(err).to.not.exist()
138-
139-
expect(res).to.have.length(1)
140-
expect(res[0].path).to.equal(expectedMultihash)
141-
expect(res[0].hash).to.equal(expectedMultihash)
142-
done()
143-
})
65+
it('err with out of range compression level', (done) => {
66+
ipfs.get(smallFile.cid, {
67+
compress: true,
68+
'compression-level': 10
69+
}, (err, files) => {
70+
expect(err).to.exist()
71+
expect(err.toString()).to.equal('Error: Compression level must be between 1 and 9')
72+
done()
14473
})
74+
})
14575

146-
it('get BIG file', (done) => {
147-
if (!isNode) { return done() }
148-
149-
ipfs.get('Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq', (err, files) => {
150-
expect(err).to.not.exist()
76+
it('with compression level', (done) => {
77+
ipfs.get(smallFile.cid, { compress: true, 'compression-level': 1 }, done)
78+
})
15179

152-
files.on('data', (file) => {
153-
// Do not blow out the memory of nodejs :)
154-
streamEqual(file.content, testfileBig, (err, equal) => {
155-
expect(err).to.not.exist()
156-
expect(equal).to.equal(true)
157-
done()
158-
})
159-
})
160-
})
80+
it('add path containing "+"s (for testing get)', (done) => {
81+
if (!isNode) { return done() }
82+
const filename = 'ti,c64x+mega++mod-pic.txt'
83+
const subdir = 'tmp/c++files'
84+
const expectedCid = 'QmPkmARcqjo5fqK1V1o8cFsuaXxWYsnwCNLJUYS4KeZyff'
85+
ipfs.add([{
86+
path: subdir + '/' + filename,
87+
content: Buffer.from(subdir + '/' + filename, 'utf-8')
88+
}], (err, files) => {
89+
expect(err).to.not.exist()
90+
expect(files[2].hash).to.equal(expectedCid)
91+
done()
16192
})
93+
})
16294

163-
it('add path containing "+"s (for testing get)', (done) => {
164-
if (!isNode) { return done() }
165-
const filename = 'ti,c64x+mega++mod-pic.txt'
166-
const subdir = 'tmp/c++files'
167-
const expectedMultihash = 'QmPkmARcqjo5fqK1V1o8cFsuaXxWYsnwCNLJUYS4KeZyff'
168-
ipfs.files.add([{
169-
path: subdir + '/' + filename,
170-
content: Buffer.from(subdir + '/' + filename, 'utf-8')
171-
}], (err, res) => {
172-
if (err) done(err)
173-
expect(res[2].hash).to.equal(expectedMultihash)
174-
done()
175-
})
176-
})
95+
it('get path containing "+"s', (done) => {
96+
if (!isNode) { return done() }
17797

178-
it('get path containing "+"s', (done) => {
179-
if (!isNode) { return done() }
180-
const multihash = 'QmPkmARcqjo5fqK1V1o8cFsuaXxWYsnwCNLJUYS4KeZyff'
181-
let count = 0
182-
ipfs.get(multihash, (err, files) => {
183-
expect(err).to.not.exist()
184-
files.on('data', (file) => {
185-
if (file.path !== multihash) {
186-
count++
187-
expect(file.path).to.contain('+')
188-
if (count === 2) done()
189-
}
190-
})
98+
const cid = 'QmPkmARcqjo5fqK1V1o8cFsuaXxWYsnwCNLJUYS4KeZyff'
99+
let count = 0
100+
ipfs.get(cid, (err, files) => {
101+
expect(err).to.not.exist()
102+
files.forEach((file) => {
103+
if (file.path !== cid) {
104+
count++
105+
expect(file.path).to.contain('+')
106+
if (count === 2) done()
107+
}
191108
})
192109
})
193110
})
194-
195-
describe('Promise API', () => {
196-
this.timeout(80 * 1000)
197-
198-
it('get', (done) => {
199-
ipfs.get('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP')
200-
.then((files) => {
201-
files.on('data', (file) => {
202-
let buf = ''
203-
file.content
204-
.on('error', (err) => expect(err).to.not.exist())
205-
.on('data', (data) => {
206-
buf += data.toString()
207-
})
208-
.on('end', () => {
209-
expect(buf).to.contain(testfile.toString())
210-
done()
211-
})
212-
})
213-
})
214-
.catch((err) => {
215-
expect(err).to.not.exist()
216-
})
217-
})
218-
})
219111
})

test/sub-modules.spec.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,14 @@ describe('submodules', () => {
157157
const files = require('../src/files')(config)
158158

159159
expect(files.add).to.be.a('function')
160-
expect(files.createAddStream).to.be.a('function')
160+
expect(files.addReadableStream).to.be.a('function')
161+
expect(files.addPullStream).to.be.a('function')
161162
expect(files.get).to.be.a('function')
163+
expect(files.getReadableStream).to.be.a('function')
164+
expect(files.getPullStream).to.be.a('function')
162165
expect(files.cat).to.be.a('function')
166+
expect(files.catReadableStream).to.be.a('function')
167+
expect(files.catPullStream).to.be.a('function')
163168
expect(files.cp).to.be.a('function')
164169
expect(files.ls).to.be.a('function')
165170
expect(files.mkdir).to.be.a('function')

0 commit comments

Comments
 (0)