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 pathname.spec.js
101 lines (89 loc) · 2.17 KB
/
name.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
101
/* eslint-env mocha */
'use strict'
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const parallel = require('async/parallel')
const series = require('async/series')
const loadFixture = require('aegir/fixtures')
const ipfsClient = require('../src')
const f = require('./utils/factory')
const testfile = loadFixture('test/fixtures/testfile.txt')
describe('.name', () => {
let ipfs
let ipfsd
let other
let otherd
let name
let testFileCid
before(function (done) {
this.timeout(30 * 1000)
series([
(cb) => {
f.spawn({ initOptions: { bits: 1024, profile: 'test' } }, (err, _ipfsd) => {
expect(err).to.not.exist()
ipfsd = _ipfsd
ipfs = ipfsClient(_ipfsd.apiAddr)
cb()
})
},
(cb) => {
f.spawn({ initOptions: { bits: 1024, profile: 'test' } }, (err, node) => {
expect(err).to.not.exist()
other = node.api
otherd = node
cb()
})
},
(cb) => {
parallel([
(cb) => {
ipfs.id((err, id) => {
expect(err).to.not.exist()
const ma = id.addresses[0]
other.swarm.connect(ma, cb)
})
},
(cb) => {
ipfs.add(testfile, (err, res) => {
expect(err).to.not.exist()
testFileCid = res[0].hash
cb()
})
}
], cb)
}
], done)
})
after(function (done) {
this.timeout(10 * 1000)
parallel([
(cb) => {
if (!ipfsd) return cb()
ipfsd.stop(cb)
},
(cb) => {
if (!otherd) return cb()
otherd.stop(cb)
}
], done)
})
it('.name.publish', function (done) {
this.timeout(5 * 60 * 1000)
ipfs.name.publish(testFileCid, (err, res) => {
expect(err).to.not.exist()
name = res
expect(name).to.exist()
done()
})
})
it('.name.resolve', (done) => {
ipfs.name.resolve(name.name, (err, res) => {
expect(err).to.not.exist()
expect(res).to.exist()
expect(res).to.be.eql(name.value)
done()
})
})
})