@@ -16,6 +16,9 @@ const series = require('async/series')
16
16
const isNode = require ( 'detect-node' )
17
17
const IPFS = require ( '../../src' )
18
18
const ipnsPath = require ( '../../src/core/ipns/path' )
19
+ const ipnsRouting = require ( '../../src/core/ipns/routing/config' )
20
+ const OfflineDatastore = require ( '../../src/core/ipns/routing/offline-datastore' )
21
+ const PubsubDatastore = require ( '../../src/core/ipns/routing/pubsub-datastore' )
19
22
const { Key } = require ( 'interface-datastore' )
20
23
21
24
const DaemonFactory = require ( 'ipfsd-ctl' )
@@ -193,7 +196,8 @@ describe('name', function () {
193
196
} )
194
197
} )
195
198
196
- describe ( 'work with dht' , ( ) => {
199
+ // TODO: unskip when DHT is enabled in 0.36
200
+ describe . skip ( 'work with dht' , ( ) => {
197
201
let nodes
198
202
let nodeA
199
203
let nodeB
@@ -532,4 +536,86 @@ describe('name', function () {
532
536
} )
533
537
} )
534
538
} )
539
+
540
+ describe ( 'ipns.routing' , function ( ) {
541
+ it ( 'should use only the offline datastore by default' , function ( done ) {
542
+ const ipfs = { }
543
+ const config = ipnsRouting ( ipfs )
544
+
545
+ expect ( config . stores ) . to . have . lengthOf ( 1 )
546
+ expect ( config . stores [ 0 ] instanceof OfflineDatastore ) . to . eql ( true )
547
+
548
+ done ( )
549
+ } )
550
+
551
+ it ( 'should use only the offline datastore if offline' , function ( done ) {
552
+ const ipfs = {
553
+ _options : {
554
+ offline : true
555
+ }
556
+ }
557
+ const config = ipnsRouting ( ipfs )
558
+
559
+ expect ( config . stores ) . to . have . lengthOf ( 1 )
560
+ expect ( config . stores [ 0 ] instanceof OfflineDatastore ) . to . eql ( true )
561
+
562
+ done ( )
563
+ } )
564
+
565
+ it ( 'should use the pubsub datastore if enabled' , function ( done ) {
566
+ const ipfs = {
567
+ libp2p : {
568
+ pubsub : { }
569
+ } ,
570
+ _peerInfo : {
571
+ id : { }
572
+ } ,
573
+ _repo : {
574
+ datastore : { }
575
+ } ,
576
+ _options : {
577
+ EXPERIMENTAL : {
578
+ ipnsPubsub : true
579
+ }
580
+ }
581
+ }
582
+ const config = ipnsRouting ( ipfs )
583
+
584
+ expect ( config . stores ) . to . have . lengthOf ( 2 )
585
+ expect ( config . stores [ 0 ] instanceof PubsubDatastore ) . to . eql ( true )
586
+ expect ( config . stores [ 1 ] instanceof OfflineDatastore ) . to . eql ( true )
587
+
588
+ done ( )
589
+ } )
590
+
591
+ it ( 'should use the dht if enabled' , function ( done ) {
592
+ const dht = { }
593
+
594
+ const ipfs = {
595
+ libp2p : {
596
+ dht
597
+ } ,
598
+ _peerInfo : {
599
+ id : { }
600
+ } ,
601
+ _repo : {
602
+ datastore : { }
603
+ } ,
604
+ _options : {
605
+ libp2p : {
606
+ dht : {
607
+ enabled : true
608
+ }
609
+ }
610
+ }
611
+ }
612
+
613
+ const config = ipnsRouting ( ipfs )
614
+
615
+ expect ( config . stores ) . to . have . lengthOf ( 1 )
616
+ expect ( config . stores [ 0 ] ) . to . eql ( dht )
617
+
618
+ done ( )
619
+ } )
620
+ } )
535
621
} )
0 commit comments