2
2
'use strict'
3
3
4
4
const expect = require ( 'chai' ) . expect
5
- const nexpect = require ( 'nexpect' )
6
5
const Block = require ( 'ipfs-block' )
7
- const _ = require ( 'lodash' )
8
6
const bs58 = require ( 'bs58' )
9
7
10
8
const HttpAPI = require ( '../../src/http-api' )
11
9
const createTempNode = require ( '../utils/temp-node' )
12
10
const repoPath = require ( './index' ) . repoPath
11
+ const ipfs = require ( '../utils/ipfs' ) ( repoPath )
13
12
14
- describe ( 'bitswap' , function ( ) {
15
- this . timeout ( 40000 )
16
- const env = _ . clone ( process . env )
17
- env . IPFS_PATH = repoPath
18
-
19
- let ipfs
13
+ describe ( 'bitswap' , ( ) => {
14
+ let node
20
15
21
16
before ( ( done ) => {
22
- createTempNode ( 38 , ( err , _ipfs ) => {
17
+ createTempNode ( 38 , ( err , _node ) => {
23
18
expect ( err ) . to . not . exist
24
- ipfs = _ipfs
25
- ipfs . goOnline ( done )
19
+ node = _node
20
+ node . goOnline ( done )
26
21
} )
27
22
} )
28
23
24
+ after ( ( done ) => {
25
+ node . goOffline ( done )
26
+ } )
27
+
29
28
describe ( 'api running' , ( ) => {
30
29
const block = new Block ( 'hello' )
31
30
const key = bs58 . encode ( block . key )
32
-
33
31
let httpAPI
34
32
35
33
before ( ( done ) => {
@@ -41,42 +39,32 @@ describe('bitswap', function () {
41
39
httpAPI . stop ( done )
42
40
} )
43
41
44
- it ( 'wantlist' , ( done ) => {
42
+ it ( 'wantlist' , ( ) => {
45
43
const api = httpAPI . server . select ( 'API' )
46
44
47
45
api . inject ( {
48
46
method : 'GET' ,
49
47
url : `/api/v0/block/get?arg=${ key } `
50
- } , ( res ) => { } )
48
+ } , ( ) => { } )
51
49
52
- nexpect . spawn ( 'node' , [ process . cwd ( ) + '/src/cli/bin.js' , 'bitswap' , 'wantlist' ] , { env} )
53
- . run ( ( err , stdout , exitcode ) => {
54
- expect ( err ) . to . not . exist
55
- expect ( exitcode ) . to . equal ( 0 )
56
- expect ( stdout ) . to . be . eql ( [
57
- key
58
- ] )
59
- done ( )
60
- } )
50
+ return ipfs ( 'bitswap wantlist' ) . then ( ( out ) => {
51
+ expect ( out ) . to . be . eql ( key )
52
+ } )
61
53
} )
62
54
63
- it ( 'stat' , ( done ) => {
64
- nexpect . spawn ( 'node' , [ process . cwd ( ) + '/src/cli/bin.js' , 'bitswap' , 'stat' ] , { env} )
65
- . run ( ( err , stdout , exitcode ) => {
66
- expect ( err ) . to . not . exist
67
- expect ( exitcode ) . to . equal ( 0 )
68
- expect ( stdout ) . to . be . eql ( [
69
- 'bitswap status' ,
70
- ' blocks received: 0' ,
71
- ' dup blocks received: 0' ,
72
- ' dup data received: 0B' ,
73
- ' wantlist [1 keys]' ,
74
- ` ${ key } ` ,
75
- ' partners [0]' ,
76
- ' '
77
- ] )
78
- done ( )
79
- } )
55
+ it ( 'stat' , ( ) => {
56
+ return ipfs ( 'bitswap stat' ) . then ( ( out ) => {
57
+ expect ( out ) . to . be . eql ( [
58
+ 'bitswap status' ,
59
+ ' blocks received: 0' ,
60
+ ' dup blocks received: 0' ,
61
+ ' dup data received: 0B' ,
62
+ ' wantlist [1 keys]' ,
63
+ ` ${ key } ` ,
64
+ ' partners [0]' ,
65
+ ' '
66
+ ] . join ( '\n' ) )
67
+ } )
80
68
} )
81
69
} )
82
70
} )
0 commit comments