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

fix: ipns over pubsub tests #395

Merged
merged 3 commits into from
Dec 3, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 30 additions & 29 deletions js/src/name-pubsub/cancel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@
/* eslint-env mocha */
'use strict'

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

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

const fixture = Object.freeze({
data: loadFixture('js/test/fixtures/testfile.txt', 'interface-ipfs-core')
})

module.exports = (createCommon, options) => {
const describe = getDescribe(options)
const it = getIt(options)
Expand All @@ -20,7 +16,6 @@ module.exports = (createCommon, options) => {
describe('.name.pubsub.cancel', function () {
let ipfs
let nodeId
let value

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

ipfs.add(fixture.data, { pin: false }, (err, res) => {
expect(err).to.not.exist()

value = res[0].path
done()
})
done()
})
})
})
Expand All @@ -63,24 +53,35 @@ module.exports = (createCommon, options) => {

it('should cancel a subscription correctly returning true', function (done) {
this.timeout(300 * 1000)
const ipnsPath = `/ipns/${nodeId}`

series([
(cb) => ipfs.name.pubsub.subs(cb),
(cb) => ipfs.name.publish(value, { resolve: false }, cb),
(cb) => ipfs.name.resolve(nodeId, cb),
(cb) => ipfs.name.pubsub.subs(cb),
(cb) => ipfs.name.pubsub.cancel(ipnsPath, cb),
(cb) => ipfs.name.pubsub.subs(cb)
], (err, res) => {

PeerId.create({ bits: 512 }, (err, peerId) => {
expect(err).to.not.exist()
expect(res).to.exist()
expect(res[0]).to.eql([]) // initally empty
expect(res[4]).to.have.property('canceled')
expect(res[4].canceled).to.eql(true)
expect(res[5]).to.be.an('array').that.does.not.include(ipnsPath)

done()
const id = peerId.toB58String()
const ipnsPath = `/ipns/${id}`

ipfs.name.pubsub.subs((err, res) => {
expect(err).to.not.exist()
expect(res).to.be.an('array').that.does.not.include(ipnsPath)

ipfs.name.resolve(id, (err) => {
expect(err).to.exist()
auto({
subs1: (cb) => ipfs.name.pubsub.subs(cb),
cancel: (cb) => ipfs.name.pubsub.cancel(ipnsPath, cb),
subs2: (cb) => ipfs.name.pubsub.subs(cb)
}, 1, (err, res) => {
vasco-santos marked this conversation as resolved.
Show resolved Hide resolved
expect(err).to.not.exist()
expect(res).to.exist()
expect(res.subs1).to.be.an('array').that.does.include(ipnsPath)
expect(res.cancel).to.have.property('canceled')
expect(res.cancel.canceled).to.eql(true)
expect(res.subs2).to.be.an('array').that.does.not.include(ipnsPath)

done()
})
})
})
})
})
})
Expand Down
41 changes: 14 additions & 27 deletions js/src/name-pubsub/subs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,16 @@
/* eslint-env mocha */
'use strict'

const series = require('async/series')
const loadFixture = require('aegir/fixtures')

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

const fixture = Object.freeze({
data: loadFixture('js/test/fixtures/testfile.txt', 'interface-ipfs-core')
})

module.exports = (createCommon, options) => {
const describe = getDescribe(options)
const it = getIt(options)
const common = createCommon()

describe('.name.pubsub.subs', function () {
let ipfs
let nodeId
let value

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

ipfs = node
nodeId = node.peerId.id

ipfs.add(fixture.data, { pin: false }, (err, res) => {
expect(err).to.not.exist()

value = res[0].path
done()
})
done()
})
})
})
Expand All @@ -62,19 +46,22 @@ module.exports = (createCommon, options) => {

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

series([
(cb) => ipfs.name.pubsub.subs(cb),
(cb) => ipfs.name.publish(value, { resolve: false }, cb),
(cb) => ipfs.name.resolve(nodeId, cb),
(cb) => ipfs.name.pubsub.subs(cb)
], (err, res) => {
ipfs.name.pubsub.subs((err, res) => {
expect(err).to.not.exist()
expect(res).to.exist()
expect(res[0]).to.eql([]) // initally empty
expect(res[3]).to.be.an('array').that.does.include(`/ipns/${nodeId}`)
expect(res).to.eql([]) // initally empty

done()
ipfs.name.resolve(id, (err) => {
expect(err).to.exist()

ipfs.name.pubsub.subs((err, res) => {
expect(err).to.not.exist()
expect(res).to.be.an('array').that.does.include(`/ipns/${id}`)

done()
})
})
})
})
})
Expand Down