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 299
/
Copy pathrefs.spec.js
83 lines (75 loc) · 2.37 KB
/
refs.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
/* eslint-env mocha */
'use strict'
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const isNode = require('detect-node')
const waterfall = require('async/waterfall')
const path = require('path')
const FactoryClient = require('./ipfs-factory/client')
describe('.refs', () => {
if (!isNode) { return }
let ipfs
let fc
let folder
before(function (done) {
this.timeout(20 * 1000) // slow CI
fc = new FactoryClient()
waterfall([
(cb) => fc.spawnNode(cb),
(node, cb) => {
ipfs = node
const filesPath = path.join(__dirname, '/fixtures/test-folder')
ipfs.util.addFromFs(filesPath, { recursive: true }, cb)
},
(hashes, cb) => {
folder = hashes[hashes.length - 1].hash
expect(folder).to.be.eql('QmQao3KNcpCsdXaLGpjieFGMfXzsSXgsf6Rnc5dJJA3QMh')
cb()
}
], done)
})
after((done) => fc.dismantle(done))
const result = [
{
Ref: 'QmQao3KNcpCsdXaLGpjieFGMfXzsSXgsf6Rnc5dJJA3QMh QmcUYKmQxmTcFom4R4UZP7FWeQzgJkwcFn51XrvsMy7PE9 add',
Err: ''
}, {
Ref: 'QmQao3KNcpCsdXaLGpjieFGMfXzsSXgsf6Rnc5dJJA3QMh QmNeHxDfQfjVFyYj2iruvysLH9zpp78v3cu1s3BZq1j5hY cat',
Err: ''
}, {
Ref: 'QmQao3KNcpCsdXaLGpjieFGMfXzsSXgsf6Rnc5dJJA3QMh QmTYFLz5vsdMpq4XXw1a1pSxujJc9Z5V3Aw1Qg64d849Zy files',
Err: ''
}, {
Ref: 'QmQao3KNcpCsdXaLGpjieFGMfXzsSXgsf6Rnc5dJJA3QMh QmY9cxiHqTFoWamkQVkpmmqzBrY3hCBEL2XNu3NtX74Fuu hello-link',
Err: ''
}, {
Ref: 'QmQao3KNcpCsdXaLGpjieFGMfXzsSXgsf6Rnc5dJJA3QMh QmU7wetVaAqc3Meurif9hcYBHGvQmL5QdpPJYBoZizyTNL ipfs-add',
Err: ''
}, {
Ref: 'QmQao3KNcpCsdXaLGpjieFGMfXzsSXgsf6Rnc5dJJA3QMh QmctZfSuegbi2TMFY2y3VQjxsH5JbRBu7XmiLfHNvshhio ls',
Err: ''
}, {
Ref: 'QmQao3KNcpCsdXaLGpjieFGMfXzsSXgsf6Rnc5dJJA3QMh QmbkMNB6rwfYAxRvnG9CWJ6cKKHEdq2ZKTozyF5FQ7H8Rs version',
Err: ''
}
]
describe('Callback API', () => {
it('refs', (done) => {
ipfs.refs(folder, { format: '<src> <dst> <linkname>' }, (err, objs) => {
expect(err).to.not.exist()
expect(objs).to.eql(result)
done()
})
})
})
describe('Promise API', () => {
it('refs', () => {
return ipfs.refs(folder, {format: '<src> <dst> <linkname>'})
.then((objs) => {
expect(objs).to.eql(result)
})
})
})
})