@@ -7,45 +7,96 @@ const dirtyChai = require('dirty-chai')
7
7
const expect = chai . expect
8
8
chai . use ( dirtyChai )
9
9
10
+ const isNode = require ( 'detect-node' )
11
+
10
12
const IPFSFactory = require ( 'ipfsd-ctl' )
11
13
const IPFS = require ( '../../src/core' )
12
14
13
15
describe ( 'dht' , ( ) => {
14
- let ipfsd , ipfs
16
+ describe ( 'enabled' , ( ) => {
17
+ let ipfsd , ipfs
18
+
19
+ before ( function ( done ) {
20
+ this . timeout ( 30 * 1000 )
15
21
16
- before ( function ( done ) {
17
- this . timeout ( 30 * 1000 )
22
+ const factory = IPFSFactory . create ( { type : 'proc' } )
18
23
19
- const factory = IPFSFactory . create ( { type : 'proc' } )
24
+ factory . spawn ( {
25
+ exec : IPFS ,
26
+ initOptions : { bits : 512 } ,
27
+ config : {
28
+ Bootstrap : [ ]
29
+ }
30
+ } , ( err , _ipfsd ) => {
31
+ expect ( err ) . to . not . exist ( )
32
+ ipfsd = _ipfsd
33
+ ipfs = _ipfsd . api
34
+ done ( )
35
+ } )
36
+ } )
20
37
21
- factory . spawn ( {
22
- exec : IPFS ,
23
- initOptions : { bits : 512 } ,
24
- config : {
25
- Bootstrap : [ ]
38
+ after ( ( done ) => {
39
+ if ( ipfsd ) {
40
+ ipfsd . stop ( done )
41
+ } else {
42
+ done ( )
26
43
}
27
- } , ( err , _ipfsd ) => {
28
- expect ( err ) . to . not . exist ( )
29
- ipfsd = _ipfsd
30
- ipfs = _ipfsd . api
31
- done ( )
32
44
} )
33
- } )
34
45
35
- after ( ( done ) => {
36
- if ( ipfsd ) {
37
- ipfsd . stop ( done )
38
- } else {
39
- done ( )
40
- }
46
+ describe ( 'findprovs' , ( ) => {
47
+ it ( 'should callback with error for invalid CID input' , ( done ) => {
48
+ ipfs . dht . findProvs ( 'INVALID CID' , ( err ) => {
49
+ expect ( err ) . to . exist ( )
50
+ expect ( err . code ) . to . equal ( 'ERR_INVALID_CID' )
51
+ done ( )
52
+ } )
53
+ } )
54
+ } )
41
55
} )
42
56
43
- describe ( 'findprovs' , ( ) => {
44
- it ( 'should callback with error for invalid CID input' , ( done ) => {
45
- ipfs . dht . findProvs ( 'INVALID CID' , ( err ) => {
46
- expect ( err ) . to . exist ( )
47
- expect ( err . code ) . to . equal ( 'ERR_INVALID_CID' )
57
+ describe ( 'disabled in browser' , ( ) => {
58
+ if ( isNode ) { return }
59
+
60
+ let ipfsd , ipfs
61
+
62
+ before ( function ( done ) {
63
+ this . timeout ( 30 * 1000 )
64
+
65
+ const factory = IPFSFactory . create ( { type : 'proc' } )
66
+
67
+ factory . spawn ( {
68
+ exec : IPFS ,
69
+ initOptions : { bits : 512 } ,
70
+ config : {
71
+ Bootstrap : [ ]
72
+ }
73
+ } , ( err , _ipfsd ) => {
74
+ expect ( err ) . to . not . exist ( )
75
+ ipfsd = _ipfsd
76
+ ipfs = _ipfsd . api
77
+ done ( )
78
+ } )
79
+ } )
80
+
81
+ after ( ( done ) => {
82
+ if ( ipfsd ) {
83
+ ipfsd . stop ( done )
84
+ } else {
48
85
done ( )
86
+ }
87
+ } )
88
+
89
+ describe ( 'put' , ( ) => {
90
+ it ( 'should callback with error for DHT not available' , async ( ) => {
91
+ let res
92
+ try {
93
+ res = await ipfs . dht . put ( Buffer . from ( 'a' ) , Buffer . from ( 'b' ) )
94
+ } catch ( err ) {
95
+ expect ( err ) . to . exist ( )
96
+ expect ( err . code ) . to . equal ( 'ERR_DHT_DISABLED' )
97
+ }
98
+
99
+ expect ( res ) . to . not . exist ( )
49
100
} )
50
101
} )
51
102
} )
0 commit comments