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

Commit e872b8a

Browse files
vasco-santosAlan Shaw
authored and
Alan Shaw
committed
fix: ipns over pubsub tests (#395)
1 parent 0d7b447 commit e872b8a

File tree

2 files changed

+44
-56
lines changed

2 files changed

+44
-56
lines changed

js/src/name-pubsub/cancel.js

+30-29
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@
22
/* eslint-env mocha */
33
'use strict'
44

5-
const series = require('async/series')
6-
const loadFixture = require('aegir/fixtures')
5+
const auto = require('async/auto')
6+
const PeerId = require('peer-id')
77

88
const { spawnNodeWithId } = require('../utils/spawn')
99
const { getDescribe, getIt, expect } = require('../utils/mocha')
1010

11-
const fixture = Object.freeze({
12-
data: loadFixture('js/test/fixtures/testfile.txt', 'interface-ipfs-core')
13-
})
14-
1511
module.exports = (createCommon, options) => {
1612
const describe = getDescribe(options)
1713
const it = getIt(options)
@@ -20,7 +16,6 @@ module.exports = (createCommon, options) => {
2016
describe('.name.pubsub.cancel', function () {
2117
let ipfs
2218
let nodeId
23-
let value
2419

2520
before(function (done) {
2621
// CI takes longer to instantiate the daemon, so we need to increase the
@@ -36,12 +31,7 @@ module.exports = (createCommon, options) => {
3631
ipfs = node
3732
nodeId = node.peerId.id
3833

39-
ipfs.add(fixture.data, { pin: false }, (err, res) => {
40-
expect(err).to.not.exist()
41-
42-
value = res[0].path
43-
done()
44-
})
34+
done()
4535
})
4636
})
4737
})
@@ -63,24 +53,35 @@ module.exports = (createCommon, options) => {
6353

6454
it('should cancel a subscription correctly returning true', function (done) {
6555
this.timeout(300 * 1000)
66-
const ipnsPath = `/ipns/${nodeId}`
67-
68-
series([
69-
(cb) => ipfs.name.pubsub.subs(cb),
70-
(cb) => ipfs.name.publish(value, { resolve: false }, cb),
71-
(cb) => ipfs.name.resolve(nodeId, cb),
72-
(cb) => ipfs.name.pubsub.subs(cb),
73-
(cb) => ipfs.name.pubsub.cancel(ipnsPath, cb),
74-
(cb) => ipfs.name.pubsub.subs(cb)
75-
], (err, res) => {
56+
57+
PeerId.create({ bits: 512 }, (err, peerId) => {
7658
expect(err).to.not.exist()
77-
expect(res).to.exist()
78-
expect(res[0]).to.eql([]) // initally empty
79-
expect(res[4]).to.have.property('canceled')
80-
expect(res[4].canceled).to.eql(true)
81-
expect(res[5]).to.be.an('array').that.does.not.include(ipnsPath)
8259

83-
done()
60+
const id = peerId.toB58String()
61+
const ipnsPath = `/ipns/${id}`
62+
63+
ipfs.name.pubsub.subs((err, res) => {
64+
expect(err).to.not.exist()
65+
expect(res).to.be.an('array').that.does.not.include(ipnsPath)
66+
67+
ipfs.name.resolve(id, (err) => {
68+
expect(err).to.exist()
69+
auto({
70+
subs1: (cb) => ipfs.name.pubsub.subs(cb),
71+
cancel: ['subs1', (_, cb) => ipfs.name.pubsub.cancel(ipnsPath, cb)],
72+
subs2: ['cancel', (_, cb) => ipfs.name.pubsub.subs(cb)]
73+
}, (err, res) => {
74+
expect(err).to.not.exist()
75+
expect(res).to.exist()
76+
expect(res.subs1).to.be.an('array').that.does.include(ipnsPath)
77+
expect(res.cancel).to.have.property('canceled')
78+
expect(res.cancel.canceled).to.eql(true)
79+
expect(res.subs2).to.be.an('array').that.does.not.include(ipnsPath)
80+
81+
done()
82+
})
83+
})
84+
})
8485
})
8586
})
8687
})

js/src/name-pubsub/subs.js

+14-27
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,16 @@
22
/* eslint-env mocha */
33
'use strict'
44

5-
const series = require('async/series')
6-
const loadFixture = require('aegir/fixtures')
7-
85
const { spawnNodeWithId } = require('../utils/spawn')
96
const { getDescribe, getIt, expect } = require('../utils/mocha')
107

11-
const fixture = Object.freeze({
12-
data: loadFixture('js/test/fixtures/testfile.txt', 'interface-ipfs-core')
13-
})
14-
158
module.exports = (createCommon, options) => {
169
const describe = getDescribe(options)
1710
const it = getIt(options)
1811
const common = createCommon()
1912

2013
describe('.name.pubsub.subs', function () {
2114
let ipfs
22-
let nodeId
23-
let value
2415

2516
before(function (done) {
2617
// CI takes longer to instantiate the daemon, so we need to increase the
@@ -34,14 +25,7 @@ module.exports = (createCommon, options) => {
3425
expect(err).to.not.exist()
3526

3627
ipfs = node
37-
nodeId = node.peerId.id
38-
39-
ipfs.add(fixture.data, { pin: false }, (err, res) => {
40-
expect(err).to.not.exist()
41-
42-
value = res[0].path
43-
done()
44-
})
28+
done()
4529
})
4630
})
4731
})
@@ -62,19 +46,22 @@ module.exports = (createCommon, options) => {
6246

6347
it('should get the list of subscriptions updated after a resolve', function (done) {
6448
this.timeout(300 * 1000)
49+
const id = 'QmNP1ASen5ZREtiJTtVD3jhMKhoPb1zppET1tgpjHx2NGA'
6550

66-
series([
67-
(cb) => ipfs.name.pubsub.subs(cb),
68-
(cb) => ipfs.name.publish(value, { resolve: false }, cb),
69-
(cb) => ipfs.name.resolve(nodeId, cb),
70-
(cb) => ipfs.name.pubsub.subs(cb)
71-
], (err, res) => {
51+
ipfs.name.pubsub.subs((err, res) => {
7252
expect(err).to.not.exist()
73-
expect(res).to.exist()
74-
expect(res[0]).to.eql([]) // initally empty
75-
expect(res[3]).to.be.an('array').that.does.include(`/ipns/${nodeId}`)
53+
expect(res).to.eql([]) // initally empty
7654

77-
done()
55+
ipfs.name.resolve(id, (err) => {
56+
expect(err).to.exist()
57+
58+
ipfs.name.pubsub.subs((err, res) => {
59+
expect(err).to.not.exist()
60+
expect(res).to.be.an('array').that.does.include(`/ipns/${id}`)
61+
62+
done()
63+
})
64+
})
7865
})
7966
})
8067
})

0 commit comments

Comments
 (0)