33
44const expect = require ( 'chai' ) . expect
55const isNode = require ( 'detect-node' )
6+ const waterfall = require ( 'async/waterfall' )
7+ const path = require ( 'path' )
8+
69const FactoryClient = require ( '../factory/factory-client' )
10+
711describe ( 'ls' , function ( ) {
12+ if ( ! isNode ) {
13+ return
14+ }
15+
816 let ipfs
917 let fc
18+ let folder
1019
1120 before ( function ( done ) {
1221 this . timeout ( 20 * 1000 ) // slow CI
1322 fc = new FactoryClient ( )
14- fc . spawnNode ( ( err , node ) => {
15- expect ( err ) . to . not . exist
16- ipfs = node
17- done ( )
18- } )
23+ waterfall ( [
24+ ( cb ) => fc . spawnNode ( cb ) ,
25+ ( node , cb ) => {
26+ ipfs = node
27+ const filesPath = path . join ( __dirname , '../data/test-folder' )
28+ ipfs . util . addFromFs ( filesPath , { recursive : true } , cb )
29+ } ,
30+ ( hashes , cb ) => {
31+ folder = hashes [ hashes . length - 1 ] . hash
32+ expect ( folder ) . to . be . eql ( 'QmRNjDeKStKGTQXnJ2NFqeQ9oW23WcpbmvCVrpDHgDg3T6' )
33+ cb ( )
34+ }
35+ ] , done )
1936 } )
2037
2138 after ( ( done ) => {
2239 fc . dismantle ( done )
2340 } )
2441
2542 it ( 'should correctly retrieve links' , function ( done ) {
26- if ( ! isNode ) {
27- return done ( )
28- }
29-
30- ipfs . ls ( 'QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG' , ( err , res ) => {
43+ ipfs . ls ( folder , ( err , res ) => {
3144 expect ( err ) . to . not . exist
3245
3346 expect ( res ) . to . have . a . property ( 'Objects' )
3447 expect ( res . Objects [ 0 ] ) . to . have . a . property ( 'Links' )
35- expect ( res . Objects [ 0 ] ) . to . have . property ( 'Hash' , 'QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG ' )
48+ expect ( res . Objects [ 0 ] ) . to . have . property ( 'Hash' , 'QmRNjDeKStKGTQXnJ2NFqeQ9oW23WcpbmvCVrpDHgDg3T6 ' )
3649 done ( )
3750 } )
3851 } )
@@ -46,8 +59,6 @@ describe('ls', function () {
4659 } )
4760
4861 it ( 'should correctly handle a nonexisting path' , function ( done ) {
49- if ( ! isNode ) return done ( )
50-
5162 ipfs . ls ( 'QmRNjDeKStKGTQXnJ2NFqeQ9oW/folder_that_isnt_there' , ( err , res ) => {
5263 expect ( err ) . to . exist
5364 expect ( res ) . to . not . exist
@@ -57,13 +68,11 @@ describe('ls', function () {
5768
5869 describe ( 'promise' , ( ) => {
5970 it ( 'should correctly retrieve links' , ( ) => {
60- if ( ! isNode ) return
61-
62- return ipfs . ls ( 'QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG' )
71+ return ipfs . ls ( folder )
6372 . then ( ( res ) => {
6473 expect ( res ) . to . have . a . property ( 'Objects' )
6574 expect ( res . Objects [ 0 ] ) . to . have . a . property ( 'Links' )
66- expect ( res . Objects [ 0 ] ) . to . have . property ( 'Hash' , 'QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG ' )
75+ expect ( res . Objects [ 0 ] ) . to . have . property ( 'Hash' , 'QmRNjDeKStKGTQXnJ2NFqeQ9oW23WcpbmvCVrpDHgDg3T6 ' )
6776 } )
6877 } )
6978
@@ -75,8 +84,6 @@ describe('ls', function () {
7584 } )
7685
7786 it ( 'should correctly handle a nonexisting path' , ( ) => {
78- if ( ! isNode ) return
79-
8087 return ipfs . ls ( 'QmRNjDeKStKGTQXnJ3NFqeQ9oW/folder_that_isnt_there' )
8188 . catch ( ( err ) => {
8289 expect ( err ) . to . exist
0 commit comments