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

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
  • Loading branch information
Alan Shaw committed May 31, 2019
1 parent ea14bbc commit 656c375
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/core/ipns/routing/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module.exports = (ipfs) => {
}

// DHT should not be added as routing if we are offline or it is disabled
if (get(ipfs._options, 'offline') || !get(ipfs._options, 'libp2p.dht.enabled', false)) {
if (get(ipfs._options, 'offline') || !get(ipfs._options, 'libp2p.dht.enabled', true)) {
const offlineDatastore = new OfflineDatastore(ipfs._repo)
ipnsStores.push(offlineDatastore)
} else {
Expand Down
30 changes: 26 additions & 4 deletions test/core/name.js
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,16 @@ describe('name', function () {
})

describe('ipns.routing', function () {
it('should use only the offline datastore by default', function (done) {
const ipfs = {}
it('should use offline datastore if DHT is disabled', function (done) {
const ipfs = {
_options: {
libp2p: {
dht: {
enabled: false
}
}
}
}
const config = ipnsRouting(ipfs)

expect(config.stores).to.have.lengthOf(1)
Expand All @@ -562,8 +570,11 @@ describe('name', function () {
})

it('should use the pubsub datastore if enabled', function (done) {
const dht = {}

const ipfs = {
libp2p: {
dht,
pubsub: {}
},
_peerInfo: {
Expand All @@ -581,8 +592,8 @@ describe('name', function () {
const config = ipnsRouting(ipfs)

expect(config.stores).to.have.lengthOf(2)
expect(config.stores[0] instanceof PubsubDatastore).to.eql(true)
expect(config.stores[1] instanceof OfflineDatastore).to.eql(true)
expect(config.stores.some(s => s instanceof PubsubDatastore)).to.eql(true)
expect(config.stores).to.include(dht)

done()
})
Expand Down Expand Up @@ -616,5 +627,16 @@ describe('name', function () {

done()
})

it('should use the dht by default', function (done) {
const dht = {}
const ipfs = { libp2p: { dht } }
const config = ipnsRouting(ipfs)

expect(config.stores).to.have.lengthOf(1)
expect(config.stores[0]).to.eql(dht)

done()
})
})
})

0 comments on commit 656c375

Please sign in to comment.