22'use strict'
33
44const expect = require ( 'chai' ) . expect
5- const nexpect = require ( 'nexpect' )
65const Block = require ( 'ipfs-block' )
7- const _ = require ( 'lodash' )
86const bs58 = require ( 'bs58' )
97
108const HttpAPI = require ( '../../src/http-api' )
119const createTempNode = require ( '../utils/temp-node' )
1210const repoPath = require ( './index' ) . repoPath
11+ const ipfs = require ( '../utils/ipfs' ) ( repoPath )
1312
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
2015
2116 before ( ( done ) => {
22- createTempNode ( 38 , ( err , _ipfs ) => {
17+ createTempNode ( 38 , ( err , _node ) => {
2318 expect ( err ) . to . not . exist
24- ipfs = _ipfs
25- ipfs . goOnline ( done )
19+ node = _node
20+ node . goOnline ( done )
2621 } )
2722 } )
2823
24+ after ( ( done ) => {
25+ node . goOffline ( done )
26+ } )
27+
2928 describe ( 'api running' , ( ) => {
3029 const block = new Block ( 'hello' )
3130 const key = bs58 . encode ( block . key )
32-
3331 let httpAPI
3432
3533 before ( ( done ) => {
@@ -41,42 +39,32 @@ describe('bitswap', function () {
4139 httpAPI . stop ( done )
4240 } )
4341
44- it ( 'wantlist' , ( done ) => {
42+ it ( 'wantlist' , ( ) => {
4543 const api = httpAPI . server . select ( 'API' )
4644
4745 api . inject ( {
4846 method : 'GET' ,
4947 url : `/api/v0/block/get?arg=${ key } `
50- } , ( res ) => { } )
48+ } , ( ) => { } )
5149
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+ } )
6153 } )
6254
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+ } )
8068 } )
8169 } )
8270} )
0 commit comments