3
3
4
4
const expect = require ( 'chai' ) . expect
5
5
const isNode = require ( 'detect-node' )
6
+ const waterfall = require ( 'async/waterfall' )
7
+ const path = require ( 'path' )
8
+
6
9
const FactoryClient = require ( '../factory/factory-client' )
10
+
7
11
describe ( 'ls' , function ( ) {
12
+ if ( ! isNode ) {
13
+ return
14
+ }
15
+
8
16
let ipfs
9
17
let fc
18
+ let folder
10
19
11
20
before ( function ( done ) {
12
21
this . timeout ( 20 * 1000 ) // slow CI
13
22
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 )
19
36
} )
20
37
21
38
after ( ( done ) => {
22
39
fc . dismantle ( done )
23
40
} )
24
41
25
42
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 ) => {
31
44
expect ( err ) . to . not . exist
32
45
33
46
expect ( res ) . to . have . a . property ( 'Objects' )
34
47
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 ' )
36
49
done ( )
37
50
} )
38
51
} )
@@ -46,8 +59,6 @@ describe('ls', function () {
46
59
} )
47
60
48
61
it ( 'should correctly handle a nonexisting path' , function ( done ) {
49
- if ( ! isNode ) return done ( )
50
-
51
62
ipfs . ls ( 'QmRNjDeKStKGTQXnJ2NFqeQ9oW/folder_that_isnt_there' , ( err , res ) => {
52
63
expect ( err ) . to . exist
53
64
expect ( res ) . to . not . exist
@@ -57,13 +68,11 @@ describe('ls', function () {
57
68
58
69
describe ( 'promise' , ( ) => {
59
70
it ( 'should correctly retrieve links' , ( ) => {
60
- if ( ! isNode ) return
61
-
62
- return ipfs . ls ( 'QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG' )
71
+ return ipfs . ls ( folder )
63
72
. then ( ( res ) => {
64
73
expect ( res ) . to . have . a . property ( 'Objects' )
65
74
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 ' )
67
76
} )
68
77
} )
69
78
@@ -75,8 +84,6 @@ describe('ls', function () {
75
84
} )
76
85
77
86
it ( 'should correctly handle a nonexisting path' , ( ) => {
78
- if ( ! isNode ) return
79
-
80
87
return ipfs . ls ( 'QmRNjDeKStKGTQXnJ3NFqeQ9oW/folder_that_isnt_there' )
81
88
. catch ( ( err ) => {
82
89
expect ( err ) . to . exist
0 commit comments