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 = {
13
13
query : Joi . object ( ) . keys ( {
14
14
n : Joi . alternatives ( )
15
15
. when ( 'count' , {
16
- is : true ,
16
+ is : Joi . any ( ) . exist ( ) ,
17
17
then : Joi . any ( ) . forbidden ( ) ,
18
18
otherwise : Joi . number ( ) . greater ( 0 )
19
19
} ) ,
20
20
count : Joi . number ( ) . greater ( 0 ) ,
21
- arg : Joi . string ( )
21
+ arg : Joi . string ( ) . required ( )
22
22
} ) . unknown ( )
23
23
} ,
24
24
handler : ( request , reply ) => {
25
25
const ipfs = request . server . app . ipfs
26
26
const peerId = request . query . arg
27
27
// Default count to 10
28
28
const count = request . query . n || request . query . count || 10
29
-
30
29
ipfs . ping ( peerId , count , ( err , pullStream ) => {
31
30
if ( err ) {
32
31
return reply ( boom . badRequest ( err ) )
Original file line number Diff line number Diff line change 4
4
5
5
const chai = require ( 'chai' )
6
6
const dirtyChai = require ( 'dirty-chai' )
7
- const expect = chai . expect
8
- chai . use ( dirtyChai )
9
- const delay = require ( 'delay' )
10
7
const series = require ( 'async/series' )
8
+ const DaemonFactory = require ( 'ipfsd-ctl' )
11
9
const ipfsExec = require ( '../utils/ipfs-exec' )
12
10
13
- const DaemonFactory = require ( 'ipfsd-ctl' )
14
11
const df = DaemonFactory . create ( { type : 'js' } )
12
+ const expect = chai . expect
13
+ chai . use ( dirtyChai )
15
14
16
15
const config = {
17
16
Bootstrap : [ ] ,
@@ -66,6 +65,7 @@ describe('ping', function () {
66
65
} , ( err , _ipfsd ) => {
67
66
expect ( err ) . to . not . exist ( )
68
67
ipfsdA = _ipfsd
68
+ // Without DHT we need to have an already established connection
69
69
ipfsdA . api . swarm . connect ( bMultiaddr , done )
70
70
} )
71
71
} )
@@ -91,7 +91,7 @@ describe('ping', function () {
91
91
ping . stdout . on ( 'end' , ( ) => {
92
92
expect ( result ) . to . have . lengthOf ( 12 )
93
93
expect ( result [ 0 ] ) . to . equal ( `PING ${ ipfsdBId } ` )
94
- for ( let i = 1 ; i < 11 ; i ++ ) {
94
+ for ( let i = 1 ; i < 11 ; i ++ ) {
95
95
expect ( result [ i ] ) . to . match ( / ^ P o n g r e c e i v e d : t i m e = \d + m s $ / )
96
96
}
97
97
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