This repository has been archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
59f30cd
commit 2d7071c
Showing
6 changed files
with
312 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* eslint max-nested-callbacks: ["error", 5] */ | ||
/* 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.cancel', function () { | ||
let ipfs | ||
let nodeId | ||
let value | ||
|
||
before(function (done) { | ||
// CI takes longer to instantiate the daemon, so we need to increase the | ||
// timeout for the before step | ||
this.timeout(60 * 1000) | ||
|
||
common.setup((err, factory) => { | ||
expect(err).to.not.exist() | ||
|
||
spawnNodeWithId(factory, (err, node) => { | ||
expect(err).to.not.exist() | ||
|
||
ipfs = node | ||
nodeId = node.peerId.id | ||
|
||
ipfs.files.add(fixture.data, { pin: false }, (err, res) => { | ||
expect(err).to.not.exist() | ||
|
||
value = res[0].path | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
after((done) => common.teardown(done)) | ||
|
||
it('should return false when the name that is intended to cancel is not subscribed', function (done) { | ||
this.timeout(60 * 1000) | ||
|
||
ipfs.name.pubsub.cancel(nodeId, (err, res) => { | ||
expect(err).to.not.exist() | ||
expect(res).to.exist() | ||
expect(res).to.have.property('canceled') | ||
expect(res.canceled).to.eql(false) | ||
|
||
done() | ||
}) | ||
}) | ||
|
||
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) => { | ||
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() | ||
}) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict' | ||
const { createSuite } = require('../utils/suite') | ||
|
||
const tests = { | ||
cancel: require('./cancel'), | ||
state: require('./state'), | ||
subs: require('./subs') | ||
} | ||
|
||
module.exports = createSuite(tests) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const { spawnNodeWithId } = require('../utils/spawn') | ||
const { getDescribe, getIt, expect } = require('../utils/mocha') | ||
|
||
module.exports = (createCommon, options) => { | ||
const describe = getDescribe(options) | ||
const it = getIt(options) | ||
const common = createCommon() | ||
|
||
describe('.name.pubsub.state', function () { | ||
let ipfs | ||
|
||
before(function (done) { | ||
// CI takes longer to instantiate the daemon, so we need to increase the | ||
// timeout for the before step | ||
this.timeout(60 * 1000) | ||
|
||
common.setup((err, factory) => { | ||
expect(err).to.not.exist() | ||
|
||
spawnNodeWithId(factory, (err, node) => { | ||
expect(err).to.not.exist() | ||
|
||
ipfs = node | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
after((done) => common.teardown(done)) | ||
|
||
it('should get the current state of pubsub', function (done) { | ||
this.timeout(50 * 1000) | ||
|
||
ipfs.name.pubsub.state((err, res) => { | ||
expect(err).to.not.exist() | ||
expect(res).to.exist() | ||
expect(res).to.have.property('enabled') | ||
expect(res.enabled).to.be.eql(true) | ||
|
||
done() | ||
}) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* eslint max-nested-callbacks: ["error", 5] */ | ||
/* 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 | ||
// timeout for the before step | ||
this.timeout(60 * 1000) | ||
|
||
common.setup((err, factory) => { | ||
expect(err).to.not.exist() | ||
|
||
spawnNodeWithId(factory, (err, node) => { | ||
expect(err).to.not.exist() | ||
|
||
ipfs = node | ||
nodeId = node.peerId.id | ||
|
||
ipfs.files.add(fixture.data, { pin: false }, (err, res) => { | ||
expect(err).to.not.exist() | ||
|
||
value = res[0].path | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
after((done) => common.teardown(done)) | ||
|
||
it('should get an empty array as a result of subscriptions before any resolve', function (done) { | ||
this.timeout(60 * 1000) | ||
|
||
ipfs.name.pubsub.subs((err, res) => { | ||
expect(err).to.not.exist() | ||
expect(res).to.exist() | ||
expect(res).to.eql([]) | ||
|
||
done() | ||
}) | ||
}) | ||
|
||
it('should get the list of subscriptions updated after a resolve', function (done) { | ||
this.timeout(300 * 1000) | ||
|
||
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) => { | ||
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}`) | ||
|
||
done() | ||
}) | ||
}) | ||
}) | ||
} |