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 109
test: ipns over pubsub #361
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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() | ||
}) | ||
}) | ||
}) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.