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 297
/
Copy pathrefs.spec.js
100 lines (88 loc) · 2.85 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* 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 fs = require('fs')
const ipfsClient = require('../src')
const f = require('./utils/factory')
describe('.refs', function () {
this.timeout(80 * 1000)
if (!isNode) { return }
let ipfs
let ipfsd
let folder
before((done) => {
const filesPath = path.join(__dirname, '/fixtures/test-folder')
// Symlinks in a repo don't always clone well, especially on Windows.
// So if the 'hello-link' is not a symlink, then make it one.
const symlinkPath = filesPath + '/hello-link'
const symlinkTarget = 'files/hello.txt'
if (!fs.lstatSync(symlinkPath).isSymbolicLink()) {
fs.unlinkSync(symlinkPath)
fs.symlinkSync(symlinkTarget, symlinkPath)
}
waterfall([
(cb) => f.spawn({ initOptions: { bits: 1024 } }, cb),
(_ipfsd, cb) => {
ipfsd = _ipfsd
ipfs = ipfsClient(_ipfsd.apiAddr)
ipfs.addFromFs(filesPath, { recursive: true }, cb)
},
(hashes, cb) => {
folder = hashes[hashes.length - 1].hash
expect(folder).to.be.eql('QmQao3KNcpCsdXaLGpjieFGMfXzsSXgsf6Rnc5dJJA3QMh')
cb()
}
], done)
})
after((done) => {
if (!ipfsd) return done()
ipfsd.stop(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)
})
})
})
})