Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix: code review for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Nov 7, 2018
1 parent e4ba943 commit 83fee00
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 96 deletions.
2 changes: 1 addition & 1 deletion src/core/ipns/publisher.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class IpnsPublisher {

let keys
try {
keys = ipns.getIdKeys(peerId.id)
keys = ipns.getIdKeys(peerId.toBytes())
} catch (err) {
log.error(err)
return callback(err)
Expand Down
180 changes: 85 additions & 95 deletions test/cli/name-pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,21 @@ describe('name-pubsub', () => {

// Connect
before(function () {
return ipfsA('swarm', 'connect', bMultiaddr).then((out) => {
expect(out).to.eql(`connect ${bMultiaddr} success\n`)
})
return ipfsA('swarm', 'connect', bMultiaddr)
.then((out) => {
expect(out).to.eql(`connect ${bMultiaddr} success\n`)
})
})

after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done))

describe('pubsub commands', () => {
before(function (done) {
this.timeout(50 * 1000)
done()
})

it('should get enabled state of pubsub', function () {
return ipfsA('name pubsub state').then((res) => {
expect(res).to.exist()
expect(res).to.have.string('enabled') // enabled
})
return ipfsA('name pubsub state')
.then((res) => {
expect(res).to.exist()
expect(res).to.have.string('enabled') // enabled
})
})

it('should subscribe on name resolve', function () {
Expand All @@ -110,19 +107,17 @@ describe('name-pubsub', () => {
.catch((err) => {
expect(err).to.exist() // Not available (subscribed)

return Promise.all([
ipfsB('pubsub ls'),
ipfsB('name pubsub subs')
])
.then((res) => {
expect(res).to.exist()

expect(res[0]).to.exist()
expect(res[0]).to.have.string('/ipns/') // have an ipns subscribtion
return ipfsB('pubsub ls')
})
.then((res) => {
expect(res).to.exist()
expect(res).to.have.string('/ipns/') // have an ipns subscribtion

expect(res[1]).to.exist()
expect(res[1]).to.have.string(`/ipns/${nodeAId.id}`) // have subscription
})
return ipfsB('name pubsub subs')
})
.then((res) => {
expect(res).to.exist()
expect(res).to.have.string(`/ipns/${nodeAId.id}`) // have subscription
})
})

Expand All @@ -135,29 +130,27 @@ describe('name-pubsub', () => {
expect(res).to.have.string('no subscription') // tried to cancel a not yet subscribed id

return ipfsA(`name resolve ${nodeBId.id}`)
.catch((err) => {
expect(err).to.exist() // Not available (subscribed now)

return ipfsA(`name pubsub cancel /ipns/${nodeBId.id}`)
.then((res) => {
expect(res).to.exist()
expect(res).to.have.string('canceled') // canceled now

return Promise.all([
ipfsA('pubsub ls'),
ipfsA('name pubsub subs')
])
.then((res) => {
expect(res).to.exist()

expect(res[0]).to.exist()
expect(res[0]).to.not.have.string('/ipns/') // ipns subscribtion not available

expect(res[1]).to.exist()
expect(res[1]).to.not.have.string(`/ipns/${nodeBId.id}`) // ipns subscribtion not available
})
})
})
})
.catch((err) => {
expect(err).to.exist() // Not available (subscribed now)

return ipfsA(`name pubsub cancel /ipns/${nodeBId.id}`)
})
.then((res) => {
expect(res).to.exist()
expect(res).to.have.string('canceled') // canceled now

return ipfsA('pubsub ls')
})
.then((res) => {
expect(res).to.exist()
expect(res).to.not.have.string('/ipns/') // ipns subscribtion not available

return ipfsA('name pubsub subs')
})
.then((res) => {
expect(res).to.exist()
expect(res).to.not.have.string(`/ipns/${nodeBId.id}`) // ipns subscribtion not available
})
})
})
Expand All @@ -167,10 +160,11 @@ describe('name-pubsub', () => {

before(function (done) {
this.timeout(50 * 1000)
ipfsA('add src/init-files/init-docs/readme').then((out) => {
cidAdded = out.split(' ')[1]
done()
})
ipfsA('add src/init-files/init-docs/readme')
.then((out) => {
cidAdded = out.split(' ')[1]
done()
})
})

it('should publish the received record to the subscriber', function () {
Expand All @@ -182,30 +176,28 @@ describe('name-pubsub', () => {
expect(res).to.satisfy(checkAll([emptyDirCid])) // Empty dir received (subscribed)

return ipfsA(`name resolve ${nodeBId.id}`)
.catch((err) => {
expect(err).to.exist() // Not available (subscribed now)

return ipfsB(`name publish ${cidAdded}`)
.then((res) => {
// published to IpfsB and published through pubsub to ipfsa
expect(res).to.exist()
expect(res).to.satisfy(checkAll([cidAdded, nodeBId.id]))

return Promise.all([
ipfsB(`name resolve ${nodeBId.id}`),
ipfsA(`name resolve ${nodeBId.id}`)
])
.then((res) => {
expect(res).to.exist()

expect(res[0]).to.exist()
expect(res[0]).to.satisfy(checkAll([cidAdded]))

expect(res[1]).to.exist()
expect(res[1]).to.satisfy(checkAll([cidAdded])) // value propagated to node B
})
})
})
})
.catch((err) => {
expect(err).to.exist() // Not available (subscribed now)

return ipfsB(`name publish ${cidAdded}`)
})
.then((res) => {
// published to IpfsB and published through pubsub to ipfsa
expect(res).to.exist()
expect(res).to.satisfy(checkAll([cidAdded, nodeBId.id]))

return ipfsB(`name resolve ${nodeBId.id}`)
})
.then((res) => {
expect(res).to.exist()
expect(res).to.satisfy(checkAll([cidAdded]))

return ipfsA(`name resolve ${nodeBId.id}`)
})
.then((res) => {
expect(res).to.exist()
expect(res).to.satisfy(checkAll([cidAdded])) // value propagated to node B
})
})
})
Expand Down Expand Up @@ -235,30 +227,28 @@ describe('name-pubsub', () => {

after((done) => parallel(nodes.map((node) => (cb) => node.stop(cb)), done))

it('should get disabled state of pubsub', function (done) {
ipfsA('name pubsub state').then((res) => {
expect(res).to.exist()
expect(res).to.have.string('disabled')

done()
})
it('should get disabled state of pubsub', function () {
return ipfsA('name pubsub state')
.then((res) => {
expect(res).to.exist()
expect(res).to.have.string('disabled')
})
})

it('should get error getting the available subscriptions', function (done) {
ipfsA('name pubsub subs').catch((err) => {
expect(err).to.exist() // error as it is disabled
expect(err.toString()).to.have.string('IPNS pubsub subsystem is not enabled')
done()
})
it('should get error getting the available subscriptions', function () {
return ipfsA('name pubsub subs')
.catch((err) => {
expect(err).to.exist() // error as it is disabled
expect(err.toString()).to.have.string('IPNS pubsub subsystem is not enabled')
})
})

it('should get error canceling a subscription', function (done) {
ipfsA('name pubsub cancel /ipns/QmSWxaPcGgf4TDnFEBDWz2JnbHywF14phmY9hNcAeBEK5v').catch((err) => {
expect(err).to.exist() // error as it is disabled
expect(err.toString()).to.have.string('IPNS pubsub subsystem is not enabled')

done()
})
it('should get error canceling a subscription', function () {
return ipfsA('name pubsub cancel /ipns/QmSWxaPcGgf4TDnFEBDWz2JnbHywF14phmY9hNcAeBEK5v')
.catch((err) => {
expect(err).to.exist() // error as it is disabled
expect(err.toString()).to.have.string('IPNS pubsub subsystem is not enabled')
})
})
})
})

0 comments on commit 83fee00

Please sign in to comment.