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

Commit 5c38bf2

Browse files
test: remove dependency on init doc hashes
Fixes #365
1 parent d85883f commit 5c38bf2

File tree

2 files changed

+53
-39
lines changed

2 files changed

+53
-39
lines changed

Diff for: test/interface-ipfs-core/ls.spec.js

+25-19
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,48 @@
33

44
const expect = require('chai').expect
55
const isNode = require('detect-node')
6+
const waterfall = require('async/waterfall')
7+
const path = require('path')
8+
69
const FactoryClient = require('../factory/factory-client')
10+
711
describe('ls', function () {
12+
if (!isNode) {
13+
return
14+
}
15+
816
let ipfs
917
let fc
18+
let folderHash
1019

1120
before(function (done) {
1221
this.timeout(20 * 1000) // slow CI
1322
fc = new FactoryClient()
14-
fc.spawnNode((err, node) => {
15-
expect(err).to.not.exist
16-
ipfs = node
17-
done()
18-
})
23+
waterfall([
24+
(cb) => fc.spawnNode(cb),
25+
(node, cb) => {
26+
ipfs = node
27+
const filesPath = path.join(__dirname, '../data/test-folder')
28+
ipfs.util.addFromFs(filesPath, { recursive: true }, cb)
29+
},
30+
(hashes, cb) => {
31+
folderHash = hashes[hashes.length - 1].hash
32+
cb()
33+
}
34+
], done)
1935
})
2036

2137
after((done) => {
2238
fc.dismantle(done)
2339
})
2440

2541
it('should correctly retrieve links', function (done) {
26-
if (!isNode) {
27-
return done()
28-
}
29-
30-
ipfs.ls('QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG', (err, res) => {
42+
ipfs.ls(folderHash, (err, res) => {
3143
expect(err).to.not.exist
3244

3345
expect(res).to.have.a.property('Objects')
3446
expect(res.Objects[0]).to.have.a.property('Links')
35-
expect(res.Objects[0]).to.have.property('Hash', 'QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG')
47+
expect(res.Objects[0]).to.have.property('Hash')
3648
done()
3749
})
3850
})
@@ -46,8 +58,6 @@ describe('ls', function () {
4658
})
4759

4860
it('should correctly handle a nonexisting path', function (done) {
49-
if (!isNode) return done()
50-
5161
ipfs.ls('QmRNjDeKStKGTQXnJ2NFqeQ9oW/folder_that_isnt_there', (err, res) => {
5262
expect(err).to.exist
5363
expect(res).to.not.exist
@@ -57,13 +67,11 @@ describe('ls', function () {
5767

5868
describe('promise', () => {
5969
it('should correctly retrieve links', () => {
60-
if (!isNode) return
61-
62-
return ipfs.ls('QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG')
70+
return ipfs.ls(folderHash)
6371
.then((res) => {
6472
expect(res).to.have.a.property('Objects')
6573
expect(res.Objects[0]).to.have.a.property('Links')
66-
expect(res.Objects[0]).to.have.property('Hash', 'QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG')
74+
expect(res.Objects[0]).to.have.property('Hash')
6775
})
6876
})
6977

@@ -75,8 +83,6 @@ describe('ls', function () {
7583
})
7684

7785
it('should correctly handle a nonexisting path', () => {
78-
if (!isNode) return
79-
8086
return ipfs.ls('QmRNjDeKStKGTQXnJ3NFqeQ9oW/folder_that_isnt_there')
8187
.catch((err) => {
8288
expect(err).to.exist

Diff for: test/interface-ipfs-core/refs.spec.js

+28-20
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,64 @@
33

44
const expect = require('chai').expect
55
const isNode = require('detect-node')
6+
const waterfall = require('async/waterfall')
7+
const path = require('path')
68
const FactoryClient = require('../factory/factory-client')
79

810
describe('.refs', () => {
11+
if (!isNode) {
12+
return
13+
}
14+
915
let ipfs
1016
let fc
17+
let folder
1118

1219
before(function (done) {
1320
this.timeout(20 * 1000) // slow CI
1421
fc = new FactoryClient()
15-
fc.spawnNode((err, node) => {
16-
expect(err).to.not.exist
17-
ipfs = node
18-
done()
19-
})
22+
waterfall([
23+
(cb) => fc.spawnNode(cb),
24+
(node, cb) => {
25+
ipfs = node
26+
const filesPath = path.join(__dirname, '../data/test-folder')
27+
ipfs.util.addFromFs(filesPath, { recursive: true }, cb)
28+
},
29+
(hashes, cb) => {
30+
folder = hashes[hashes.length - 1].hash
31+
cb()
32+
}
33+
], done)
2034
})
2135

2236
after((done) => {
2337
fc.dismantle(done)
2438
})
2539

26-
const folder = 'QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG'
2740
const result = [{
28-
Ref: 'QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V about',
41+
Ref: 'QmRNjDeKStKGTQXnJ2NFqeQ9oW23WcpbmvCVrpDHgDg3T6 QmcUYKmQxmTcFom4R4UZP7FWeQzgJkwcFn51XrvsMy7PE9 add.js',
2942
Err: ''
3043
}, {
31-
Ref: 'QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG QmYCvbfNbCwFR45HiNP45rwJgvatpiW38D961L5qAhUM5Y contact',
44+
Ref: 'QmRNjDeKStKGTQXnJ2NFqeQ9oW23WcpbmvCVrpDHgDg3T6 QmNeHxDfQfjVFyYj2iruvysLH9zpp78v3cu1s3BZq1j5hY cat.js',
3245
Err: ''
3346
}, {
34-
Ref: 'QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7 help',
47+
Ref: 'QmRNjDeKStKGTQXnJ2NFqeQ9oW23WcpbmvCVrpDHgDg3T6 QmTYFLz5vsdMpq4XXw1a1pSxujJc9Z5V3Aw1Qg64d849Zy files',
3548
Err: ''
3649
}, {
37-
Ref: 'QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG QmdncfsVm2h5Kqq9hPmU7oAVX2zTSVP3L869tgTbPYnsha quick-start',
50+
Ref: 'QmRNjDeKStKGTQXnJ2NFqeQ9oW23WcpbmvCVrpDHgDg3T6 QmY9cxiHqTFoWamkQVkpmmqzBrY3hCBEL2XNu3NtX74Fuu hello-link',
3851
Err: ''
3952
}, {
40-
Ref: 'QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG QmPZ9gcCEpqKTo6aq61g2nXGUhM4iCL3ewB6LDXZCtioEB readme',
53+
Ref: 'QmRNjDeKStKGTQXnJ2NFqeQ9oW23WcpbmvCVrpDHgDg3T6 QmU7wetVaAqc3Meurif9hcYBHGvQmL5QdpPJYBoZizyTNL ipfs-add.js',
4154
Err: ''
4255
}, {
43-
Ref: 'QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG QmTumTjvcYCAvRRwQ8sDRxh8ezmrcr88YFU7iYNroGGTBZ security-notes',
56+
Ref: 'QmRNjDeKStKGTQXnJ2NFqeQ9oW23WcpbmvCVrpDHgDg3T6 QmctZfSuegbi2TMFY2y3VQjxsH5JbRBu7XmiLfHNvshhio ls.js',
57+
Err: ''
58+
}, {
59+
Ref: 'QmRNjDeKStKGTQXnJ2NFqeQ9oW23WcpbmvCVrpDHgDg3T6 QmbkMNB6rwfYAxRvnG9CWJ6cKKHEdq2ZKTozyF5FQ7H8Rs version.js',
4460
Err: ''
4561
}]
4662

4763
it('refs', (done) => {
48-
if (!isNode) {
49-
return done()
50-
}
51-
5264
ipfs.refs(folder, {format: '<src> <dst> <linkname>'}, (err, objs) => {
5365
expect(err).to.not.exist
5466
expect(objs).to.eql(result)
@@ -59,10 +71,6 @@ describe('.refs', () => {
5971

6072
describe('promise', () => {
6173
it('refs', () => {
62-
if (!isNode) {
63-
return
64-
}
65-
6674
return ipfs.refs(folder, {format: '<src> <dst> <linkname>'})
6775
.then((objs) => {
6876
expect(objs).to.eql(result)

0 commit comments

Comments
 (0)