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

Commit a854a42

Browse files
committed
chore: move repeated fixtures into utils module
License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io>
1 parent ab4ddb9 commit a854a42

12 files changed

+114
-204
lines changed

js/src/files/add-pull-stream.js

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const chai = require('chai')
77
const dirtyChai = require('dirty-chai')
88
const expect = chai.expect
99
chai.use(dirtyChai)
10-
const loadFixture = require('aegir/fixtures')
10+
const { fixtures } = require('./utils')
1111
const pull = require('pull-stream')
1212
const { getDescribe, getIt } = require('../utils/mocha')
1313

@@ -21,18 +21,6 @@ module.exports = (createCommon, options) => {
2121

2222
let ipfs
2323

24-
const directory = {
25-
cid: 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP',
26-
files: {
27-
'pp.txt': loadFixture('js/test/fixtures/test-folder/pp.txt', 'interface-ipfs-core'),
28-
'holmes.txt': loadFixture('js/test/fixtures/test-folder/holmes.txt', 'interface-ipfs-core'),
29-
'jungle.txt': loadFixture('js/test/fixtures/test-folder/jungle.txt', 'interface-ipfs-core'),
30-
'alice.txt': loadFixture('js/test/fixtures/test-folder/alice.txt', 'interface-ipfs-core'),
31-
'files/hello.txt': loadFixture('js/test/fixtures/test-folder/files/hello.txt', 'interface-ipfs-core'),
32-
'files/ipfs.txt': loadFixture('js/test/fixtures/test-folder/files/ipfs.txt', 'interface-ipfs-core')
33-
}
34-
}
35-
3624
before(function (done) {
3725
// CI takes longer to instantiate the daemon, so we need to increase the
3826
// timeout for the before step
@@ -53,7 +41,7 @@ module.exports = (createCommon, options) => {
5341
it('should add pull stream of valid files and dirs', function (done) {
5442
const content = (name) => ({
5543
path: `test-folder/${name}`,
56-
content: directory.files[name]
44+
content: fixtures.directory.files[name]
5745
})
5846

5947
const emptyDir = (name) => ({ path: `test-folder/${name}` })
@@ -79,7 +67,7 @@ module.exports = (createCommon, options) => {
7967

8068
filesAdded.forEach((file) => {
8169
if (file.path === 'test-folder') {
82-
expect(file.hash).to.equal(directory.cid)
70+
expect(file.hash).to.equal(fixtures.directory.cid)
8371
done()
8472
}
8573
})

js/src/files/add-readable-stream.js

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const chai = require('chai')
77
const dirtyChai = require('dirty-chai')
88
const expect = chai.expect
99
chai.use(dirtyChai)
10-
const loadFixture = require('aegir/fixtures')
10+
const { fixtures } = require('./utils')
1111
const { getDescribe, getIt } = require('../utils/mocha')
1212

1313
module.exports = (createCommon, options) => {
@@ -20,18 +20,6 @@ module.exports = (createCommon, options) => {
2020

2121
let ipfs
2222

23-
const directory = {
24-
cid: 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP',
25-
files: {
26-
'pp.txt': loadFixture('js/test/fixtures/test-folder/pp.txt', 'interface-ipfs-core'),
27-
'holmes.txt': loadFixture('js/test/fixtures/test-folder/holmes.txt', 'interface-ipfs-core'),
28-
'jungle.txt': loadFixture('js/test/fixtures/test-folder/jungle.txt', 'interface-ipfs-core'),
29-
'alice.txt': loadFixture('js/test/fixtures/test-folder/alice.txt', 'interface-ipfs-core'),
30-
'files/hello.txt': loadFixture('js/test/fixtures/test-folder/files/hello.txt', 'interface-ipfs-core'),
31-
'files/ipfs.txt': loadFixture('js/test/fixtures/test-folder/files/ipfs.txt', 'interface-ipfs-core')
32-
}
33-
}
34-
3523
before(function (done) {
3624
// CI takes longer to instantiate the daemon, so we need to increase the
3725
// timeout for the before step
@@ -52,7 +40,7 @@ module.exports = (createCommon, options) => {
5240
it('should add readable stream of valid files and dirs', function (done) {
5341
const content = (name) => ({
5442
path: `test-folder/${name}`,
55-
content: directory.files[name]
43+
content: fixtures.directory.files[name]
5644
})
5745

5846
const emptyDir = (name) => ({ path: `test-folder/${name}` })
@@ -76,7 +64,7 @@ module.exports = (createCommon, options) => {
7664

7765
stream.on('data', (file) => {
7866
if (file.path === 'test-folder') {
79-
expect(file.hash).to.equal(directory.cid)
67+
expect(file.hash).to.equal(fixtures.directory.cid)
8068
done()
8169
}
8270
})

js/src/files/add.js

Lines changed: 24 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const chai = require('chai')
77
const dirtyChai = require('dirty-chai')
88
const expect = chai.expect
99
chai.use(dirtyChai)
10-
const loadFixture = require('aegir/fixtures')
10+
const { fixtures } = require('./utils')
1111
const Readable = require('readable-stream').Readable
1212
const pull = require('pull-stream')
1313
const path = require('path')
@@ -24,28 +24,6 @@ module.exports = (createCommon, options) => {
2424

2525
let ipfs
2626

27-
const smallFile = {
28-
cid: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP',
29-
data: loadFixture('js/test/fixtures/testfile.txt', 'interface-ipfs-core')
30-
}
31-
32-
const bigFile = {
33-
cid: 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq',
34-
data: loadFixture('js/test/fixtures/15mb.random', 'interface-ipfs-core')
35-
}
36-
37-
const directory = {
38-
cid: 'QmVvjDy7yF7hdnqE8Hrf4MHo5ABDtb5AbX6hWbD3Y42bXP',
39-
files: {
40-
'pp.txt': loadFixture('js/test/fixtures/test-folder/pp.txt', 'interface-ipfs-core'),
41-
'holmes.txt': loadFixture('js/test/fixtures/test-folder/holmes.txt', 'interface-ipfs-core'),
42-
'jungle.txt': loadFixture('js/test/fixtures/test-folder/jungle.txt', 'interface-ipfs-core'),
43-
'alice.txt': loadFixture('js/test/fixtures/test-folder/alice.txt', 'interface-ipfs-core'),
44-
'files/hello.txt': loadFixture('js/test/fixtures/test-folder/files/hello.txt', 'interface-ipfs-core'),
45-
'files/ipfs.txt': loadFixture('js/test/fixtures/test-folder/files/ipfs.txt', 'interface-ipfs-core')
46-
}
47-
}
48-
4927
before(function (done) {
5028
// CI takes longer to instantiate the daemon, so we need to increase the
5129
// timeout for the before step
@@ -64,38 +42,38 @@ module.exports = (createCommon, options) => {
6442
after((done) => common.teardown(done))
6543

6644
it('should add a Buffer', (done) => {
67-
ipfs.files.add(smallFile.data, (err, filesAdded) => {
45+
ipfs.files.add(fixtures.smallFile.data, (err, filesAdded) => {
6846
expect(err).to.not.exist()
6947

7048
expect(filesAdded).to.have.length(1)
7149
const file = filesAdded[0]
72-
expect(file.hash).to.equal(smallFile.cid)
73-
expect(file.path).to.equal(smallFile.cid)
50+
expect(file.hash).to.equal(fixtures.smallFile.cid)
51+
expect(file.path).to.equal(fixtures.smallFile.cid)
7452
// file.size counts the overhead by IPLD nodes and unixfs protobuf
75-
expect(file.size).greaterThan(smallFile.data.length)
53+
expect(file.size).greaterThan(fixtures.smallFile.data.length)
7654
done()
7755
})
7856
})
7957

8058
it('should add a Buffer (promised)', () => {
81-
return ipfs.files.add(smallFile.data)
59+
return ipfs.files.add(fixtures.smallFile.data)
8260
.then((filesAdded) => {
8361
const file = filesAdded[0]
84-
expect(file.hash).to.equal(smallFile.cid)
85-
expect(file.path).to.equal(smallFile.cid)
62+
expect(file.hash).to.equal(fixtures.smallFile.cid)
63+
expect(file.path).to.equal(fixtures.smallFile.cid)
8664
})
8765
})
8866

8967
it('should add a BIG Buffer', (done) => {
90-
ipfs.files.add(bigFile.data, (err, filesAdded) => {
68+
ipfs.files.add(fixtures.bigFile.data, (err, filesAdded) => {
9169
expect(err).to.not.exist()
9270

9371
expect(filesAdded).to.have.length(1)
9472
const file = filesAdded[0]
95-
expect(file.hash).to.equal(bigFile.cid)
96-
expect(file.path).to.equal(bigFile.cid)
73+
expect(file.hash).to.equal(fixtures.bigFile.cid)
74+
expect(file.path).to.equal(fixtures.bigFile.cid)
9775
// file.size counts the overhead by IPLD nodes and unixfs protobuf
98-
expect(file.size).greaterThan(bigFile.data.length)
76+
expect(file.size).greaterThan(fixtures.bigFile.data.length)
9977
done()
10078
})
10179
})
@@ -108,22 +86,22 @@ module.exports = (createCommon, options) => {
10886
accumProgress = p
10987
}
11088

111-
ipfs.files.add(bigFile.data, { progress: handler }, (err, filesAdded) => {
89+
ipfs.files.add(fixtures.bigFile.data, { progress: handler }, (err, filesAdded) => {
11290
expect(err).to.not.exist()
11391

11492
expect(filesAdded).to.have.length(1)
11593
const file = filesAdded[0]
116-
expect(file.hash).to.equal(bigFile.cid)
117-
expect(file.path).to.equal(bigFile.cid)
94+
expect(file.hash).to.equal(fixtures.bigFile.cid)
95+
expect(file.path).to.equal(fixtures.bigFile.cid)
11896

11997
expect(progCalled).to.be.true()
120-
expect(accumProgress).to.equal(bigFile.data.length)
98+
expect(accumProgress).to.equal(fixtures.bigFile.data.length)
12199
done()
122100
})
123101
})
124102

125103
it('should add a Buffer as tuple', (done) => {
126-
const tuple = { path: 'testfile.txt', content: smallFile.data }
104+
const tuple = { path: 'testfile.txt', content: fixtures.smallFile.data }
127105

128106
ipfs.files.add([
129107
tuple
@@ -132,7 +110,7 @@ module.exports = (createCommon, options) => {
132110

133111
expect(filesAdded).to.have.length(1)
134112
const file = filesAdded[0]
135-
expect(file.hash).to.equal(smallFile.cid)
113+
expect(file.hash).to.equal(fixtures.smallFile.cid)
136114
expect(file.path).to.equal('testfile.txt')
137115

138116
done()
@@ -222,7 +200,7 @@ module.exports = (createCommon, options) => {
222200
it('should add a nested directory as array of tupples', function (done) {
223201
const content = (name) => ({
224202
path: `test-folder/${name}`,
225-
content: directory.files[name]
203+
content: fixtures.directory.files[name]
226204
})
227205

228206
const emptyDir = (name) => ({ path: `test-folder/${name}` })
@@ -243,15 +221,15 @@ module.exports = (createCommon, options) => {
243221
const root = res[res.length - 1]
244222

245223
expect(root.path).to.equal('test-folder')
246-
expect(root.hash).to.equal(directory.cid)
224+
expect(root.hash).to.equal(fixtures.directory.cid)
247225
done()
248226
})
249227
})
250228

251229
it('should add a nested directory as array of tupples with progress', function (done) {
252230
const content = (name) => ({
253231
path: `test-folder/${name}`,
254-
content: directory.files[name]
232+
content: fixtures.directory.files[name]
255233
})
256234

257235
const emptyDir = (name) => ({ path: `test-folder/${name}` })
@@ -285,7 +263,7 @@ module.exports = (createCommon, options) => {
285263
expect(progCalled).to.be.true()
286264
expect(accumProgress).to.be.at.least(total)
287265
expect(root.path).to.equal('test-folder')
288-
expect(root.hash).to.equal(directory.cid)
266+
expect(root.hash).to.equal(fixtures.directory.cid)
289267
done()
290268
})
291269
})
@@ -300,14 +278,14 @@ module.exports = (createCommon, options) => {
300278
})
301279

302280
it('should wrap content in a directory', (done) => {
303-
const data = { path: 'testfile.txt', content: smallFile.data }
281+
const data = { path: 'testfile.txt', content: fixtures.smallFile.data }
304282

305283
ipfs.files.add(data, { wrapWithDirectory: true }, (err, filesAdded) => {
306284
expect(err).to.not.exist()
307285
expect(filesAdded).to.have.length(2)
308286
const file = filesAdded[0]
309287
const wrapped = filesAdded[1]
310-
expect(file.hash).to.equal(smallFile.cid)
288+
expect(file.hash).to.equal(fixtures.smallFile.cid)
311289
expect(file.path).to.equal('testfile.txt')
312290
expect(wrapped.path).to.equal('')
313291
done()

js/src/files/cat-pull-stream.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const chai = require('chai')
77
const dirtyChai = require('dirty-chai')
88
const expect = chai.expect
99
chai.use(dirtyChai)
10-
const loadFixture = require('aegir/fixtures')
10+
const { fixtures } = require('./utils')
1111
const pull = require('pull-stream')
1212
const { getDescribe, getIt } = require('../utils/mocha')
1313

@@ -21,11 +21,6 @@ module.exports = (createCommon, options) => {
2121

2222
let ipfs
2323

24-
const smallFile = {
25-
cid: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP',
26-
data: loadFixture('js/test/fixtures/testfile.txt', 'interface-ipfs-core')
27-
}
28-
2924
before(function (done) {
3025
// CI takes longer to instantiate the daemon, so we need to increase the
3126
// timeout for the before step
@@ -41,19 +36,19 @@ module.exports = (createCommon, options) => {
4136
})
4237
})
4338

44-
before((done) => ipfs.files.add(smallFile.data, done))
39+
before((done) => ipfs.files.add(fixtures.smallFile.data, done))
4540

4641
after((done) => common.teardown(done))
4742

4843
it('should return a Pull Stream for a CID', (done) => {
49-
const stream = ipfs.files.catPullStream(smallFile.cid)
44+
const stream = ipfs.files.catPullStream(fixtures.smallFile.cid)
5045

5146
pull(
5247
stream,
5348
pull.concat((err, data) => {
5449
expect(err).to.not.exist()
55-
expect(data.length).to.equal(smallFile.data.length)
56-
expect(data).to.eql(smallFile.data.toString())
50+
expect(data.length).to.equal(fixtures.smallFile.data.length)
51+
expect(data).to.eql(fixtures.smallFile.data.toString())
5752
done()
5853
})
5954
)
@@ -63,7 +58,7 @@ module.exports = (createCommon, options) => {
6358
const offset = 1
6459
const length = 3
6560

66-
const stream = ipfs.files.catPullStream(smallFile.cid, {
61+
const stream = ipfs.files.catPullStream(fixtures.smallFile.cid, {
6762
offset,
6863
length
6964
})

js/src/files/cat-readable-stream.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const chai = require('chai')
77
const dirtyChai = require('dirty-chai')
88
const expect = chai.expect
99
chai.use(dirtyChai)
10-
const loadFixture = require('aegir/fixtures')
10+
const { fixtures } = require('./utils')
1111
const bl = require('bl')
1212
const { getDescribe, getIt } = require('../utils/mocha')
1313

@@ -21,16 +21,6 @@ module.exports = (createCommon, options) => {
2121

2222
let ipfs
2323

24-
const smallFile = {
25-
cid: 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP',
26-
data: loadFixture('js/test/fixtures/testfile.txt', 'interface-ipfs-core')
27-
}
28-
29-
const bigFile = {
30-
cid: 'Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq',
31-
data: loadFixture('js/test/fixtures/15mb.random', 'interface-ipfs-core')
32-
}
33-
3424
before(function (done) {
3525
// CI takes longer to instantiate the daemon, so we need to increase the
3626
// timeout for the before step
@@ -46,16 +36,16 @@ module.exports = (createCommon, options) => {
4636
})
4737
})
4838

49-
before((done) => ipfs.files.add(bigFile.data, done))
39+
before((done) => ipfs.files.add(fixtures.bigFile.data, done))
5040

5141
after((done) => common.teardown(done))
5242

5343
it('should return a Readable Stream for a CID', (done) => {
54-
const stream = ipfs.files.catReadableStream(bigFile.cid)
44+
const stream = ipfs.files.catReadableStream(fixtures.bigFile.cid)
5545

5646
stream.pipe(bl((err, data) => {
5747
expect(err).to.not.exist()
58-
expect(data).to.eql(bigFile.data)
48+
expect(data).to.eql(fixtures.bigFile.data)
5949
done()
6050
}))
6151
})
@@ -64,7 +54,7 @@ module.exports = (createCommon, options) => {
6454
const offset = 1
6555
const length = 3
6656

67-
const stream = ipfs.files.catReadableStream(smallFile.cid, {
57+
const stream = ipfs.files.catReadableStream(fixtures.smallFile.cid, {
6858
offset,
6959
length
7060
})

0 commit comments

Comments
 (0)