This repository was archived by the owner on Feb 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +59
-8
lines changed Expand file tree Collapse file tree 3 files changed +59
-8
lines changed Original file line number Diff line number Diff line change @@ -13,20 +13,19 @@ exports.get = {
1313 query : Joi . object ( ) . keys ( {
1414 n : Joi . alternatives ( )
1515 . when ( 'count' , {
16- is : true ,
16+ is : Joi . any ( ) . exist ( ) ,
1717 then : Joi . any ( ) . forbidden ( ) ,
1818 otherwise : Joi . number ( ) . greater ( 0 )
1919 } ) ,
2020 count : Joi . number ( ) . greater ( 0 ) ,
21- arg : Joi . string ( )
21+ arg : Joi . string ( ) . required ( )
2222 } ) . unknown ( )
2323 } ,
2424 handler : ( request , reply ) => {
2525 const ipfs = request . server . app . ipfs
2626 const peerId = request . query . arg
2727 // Default count to 10
2828 const count = request . query . n || request . query . count || 10
29-
3029 ipfs . ping ( peerId , count , ( err , pullStream ) => {
3130 if ( err ) {
3231 return reply ( boom . badRequest ( err ) )
Original file line number Diff line number Diff line change 44
55const chai = require ( 'chai' )
66const dirtyChai = require ( 'dirty-chai' )
7- const expect = chai . expect
8- chai . use ( dirtyChai )
9- const delay = require ( 'delay' )
107const series = require ( 'async/series' )
8+ const DaemonFactory = require ( 'ipfsd-ctl' )
119const ipfsExec = require ( '../utils/ipfs-exec' )
1210
13- const DaemonFactory = require ( 'ipfsd-ctl' )
1411const df = DaemonFactory . create ( { type : 'js' } )
12+ const expect = chai . expect
13+ chai . use ( dirtyChai )
1514
1615const config = {
1716 Bootstrap : [ ] ,
@@ -66,6 +65,7 @@ describe('ping', function () {
6665 } , ( err , _ipfsd ) => {
6766 expect ( err ) . to . not . exist ( )
6867 ipfsdA = _ipfsd
68+ // Without DHT we need to have an already established connection
6969 ipfsdA . api . swarm . connect ( bMultiaddr , done )
7070 } )
7171 } )
@@ -91,7 +91,7 @@ describe('ping', function () {
9191 ping . stdout . on ( 'end' , ( ) => {
9292 expect ( result ) . to . have . lengthOf ( 12 )
9393 expect ( result [ 0 ] ) . to . equal ( `PING ${ ipfsdBId } ` )
94- for ( let i = 1 ; i < 11 ; i ++ ) {
94+ for ( let i = 1 ; i < 11 ; i ++ ) {
9595 expect ( result [ i ] ) . to . match ( / ^ P o n g r e c e i v e d : t i m e = \d + m s $ / )
9696 }
9797 expect ( result [ 11 ] ) . to . match ( / ^ A v e r a g e l a t e n c y : \d + ( .\d + ) ? m s $ / )
Original file line number Diff line number Diff line change 1+ /* eslint max-nested-callbacks: ["error", 8] */
2+ /* eslint-env mocha */
3+ 'use strict'
4+
5+ const chai = require ( 'chai' )
6+ const dirtyChai = require ( 'dirty-chai' )
7+
8+ const expect = chai . expect
9+ chai . use ( dirtyChai )
10+
11+ module . exports = ( http ) => {
12+ describe ( '/ping' , function ( ) {
13+ let api
14+
15+ before ( ( ) => {
16+ api = http . api . server . select ( 'API' )
17+ } )
18+
19+ it ( 'returns 400 if both n and count are provided' , ( done ) => {
20+ api . inject ( {
21+ method : 'GET' ,
22+ url : `/api/v0/ping?arg=someRandomId&n=1&count=1`
23+ } , ( res ) => {
24+ expect ( res . statusCode ) . to . equal ( 400 )
25+ done ( )
26+ } )
27+ } )
28+
29+ it ( 'returns 400 if arg is not provided' , ( done ) => {
30+ api . inject ( {
31+ method : 'GET' ,
32+ url : `/api/v0/ping?count=1`
33+ } , ( res ) => {
34+ expect ( res . statusCode ) . to . equal ( 400 )
35+ done ( )
36+ } )
37+ } )
38+
39+ it ( 'returns 200 and the response stream with the ping result' , ( done ) => {
40+ api . inject ( {
41+ method : 'GET' ,
42+ url : `/api/v0/ping?arg=someRandomId`
43+ } , ( res ) => {
44+ expect ( res . statusCode ) . to . equal ( 200 )
45+ expect ( res . headers [ 'x-chunked-output' ] ) . to . equal ( '1' )
46+ expect ( res . headers [ 'transfer-encoding' ] ) . to . equal ( 'chunked' )
47+ expect ( res . headers [ 'content-type' ] ) . to . include ( 'application/json' )
48+ done ( )
49+ } )
50+ } )
51+ } )
52+ }
You can’t perform that action at this time.
0 commit comments