4
4
const expect = require ( 'chai' ) . expect
5
5
6
6
module . exports = ( common ) => {
7
- describe . only ( '.dht' , ( ) => {
7
+ describe ( '.dht' , ( ) => {
8
8
let ipfs
9
+ let peers
9
10
10
11
before ( ( done ) => {
11
12
common . setup ( ( err , factory ) => {
@@ -21,42 +22,79 @@ module.exports = (common) => {
21
22
after ( ( done ) => {
22
23
common . teardown ( done )
23
24
} )
24
- xdescribe ( '.findpeer' , ( ) => { } )
25
- describe ( '.get' , ( done ) => {
26
- it ( 'errors when getting a non-existent key from the DHT' , ( done ) => {
27
- ipfs . dht . get ( 'non-existing' , { timeout : '100ms' } , ( err , value ) => {
28
- expect ( err ) . to . be . an . instanceof ( Error )
29
- done ( )
25
+
26
+ describe ( 'callback API' , ( ) => {
27
+ describe ( '.get' , ( done ) => {
28
+ it ( 'errors when getting a non-existent key from the DHT' , ( done ) => {
29
+ ipfs . dht . get ( 'non-existing' , { timeout : '100ms' } , ( err , value ) => {
30
+ expect ( err ) . to . be . an . instanceof ( Error )
31
+ done ( )
32
+ } )
30
33
} )
31
34
} )
32
- // belongs in put or integration
33
- it ( 'puts and gets a key value pair in the DHT' , ( done ) => {
34
- ipfs . dht . put ( 'scope' , 'interplanetary' , ( err , res ) => {
35
- expect ( err ) . to . not . exist
36
-
37
- expect ( res ) . to . be . an ( 'array' )
35
+ describe ( '.findprovs' , ( ) => {
36
+ it ( 'finds providers' , ( done ) => {
37
+ ipfs . dht . findprovs ( 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' , ( err , res ) => {
38
+ expect ( err ) . to . not . exist
38
39
40
+ expect ( res ) . to . be . an ( 'array' )
41
+ done ( )
42
+ } )
43
+ } )
44
+ } )
45
+ } )
46
+ describe ( 'promise API' , ( ) => {
47
+ describe ( '.get' , ( done ) => {
48
+ it ( 'errors when getting a non-existent key from the DHT' , ( done ) => {
49
+ ipfs . dht . get ( 'non-existing' , { timeout : '100ms' } ) . catch ( ( err ) => {
50
+ expect ( err ) . to . be . an . instanceof ( Error )
51
+ done ( )
52
+ } )
53
+ } )
54
+ } )
55
+ describe ( '.findprovs' , ( ) => {
56
+ it ( 'finds providers' , ( done ) => {
57
+ ipfs . dht . findprovs ( 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' ) . then ( ( res ) => {
58
+ expect ( res ) . to . be . an ( 'array' )
59
+ done ( )
60
+ } ) . catch ( done )
61
+ } )
62
+ } )
63
+ } )
64
+ // Tests below are tests that haven't been implemented yet or is not
65
+ // passing currently
66
+ xdescribe ( '.findpeer' , ( ) => {
67
+ it ( 'finds other peers' , ( done ) => {
68
+ peers . a . ipfs . dht . findpeer ( peers . b . peerID , ( err , foundPeer ) => {
69
+ expect ( err ) . to . be . empty
70
+ expect ( foundPeer . peerID ) . to . be . equal ( peers . b . peerID )
71
+ done ( )
72
+ } )
73
+ } )
74
+ it ( 'fails to find other peer, if peer doesnt exists' , ( done ) => {
75
+ peers . a . ipfs . dht . findpeer ( 'ARandomPeerID' , ( err , foundPeer ) => {
76
+ expect ( err ) . to . be . instanceof ( Error )
77
+ expect ( foundPeer ) . to . be . equal ( null )
39
78
done ( )
40
- // bug: https://github.com/ipfs/go-ipfs/issues/1923#issuecomment-152932234
41
- // apiClients.a.dht.get('scope', (err, value) => {
42
- // expect(err).to.not.exist
43
- // expect(value).to.be.equal('interplanetary')
44
- // done()
45
- // })
46
79
} )
47
80
} )
48
81
} )
49
- xdescribe ( '.put' , ( ) => { } )
50
- xdescribe ( '.query' , ( ) => { } )
51
- describe ( '.findprovs' , ( ) => {
52
- it ( 'finds providers' , ( done ) => {
53
- ipfs . dht . findprovs ( 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' , ( err , res ) => {
82
+ xdescribe ( '.put & .get' , ( ) => {
83
+ it ( 'puts and gets a key value pair in the DHT' , ( done ) => {
84
+ peers . a . ipfs . dht . put ( 'scope' , 'interplanetary' , ( err , res ) => {
54
85
expect ( err ) . to . not . exist
55
86
56
87
expect ( res ) . to . be . an ( 'array' )
57
- done ( )
88
+
89
+ // bug: https://github.com/ipfs/go-ipfs/issues/1923#issuecomment-152932234
90
+ peers . b . ipfs . dht . get ( 'scope' , ( err , value ) => {
91
+ expect ( err ) . to . not . exist
92
+ expect ( value ) . to . be . equal ( 'interplanetary' )
93
+ done ( )
94
+ } )
58
95
} )
59
96
} )
60
97
} )
98
+ xdescribe ( '.query' , ( ) => { } )
61
99
} )
62
100
}
0 commit comments