@@ -12,7 +12,7 @@ module.exports = (createCommon, suiteName, ipfsRefs, options) => {
12
12
describe ( suiteName , function ( ) {
13
13
this . timeout ( 40 * 1000 )
14
14
15
- let ipfs , rootCid
15
+ let ipfs , pbRootCb , dagRootCid
16
16
17
17
before ( function ( done ) {
18
18
// CI takes longer to instantiate the daemon, so we need to increase the
@@ -30,9 +30,17 @@ module.exports = (createCommon, suiteName, ipfsRefs, options) => {
30
30
} )
31
31
32
32
before ( function ( done ) {
33
- loadContent ( ipfs , getMockObjects ( ) , ( err , cid ) => {
33
+ loadPbContent ( ipfs , getMockObjects ( ) , ( err , cid ) => {
34
34
expect ( err ) . to . not . exist ( )
35
- rootCid = cid
35
+ pbRootCb = cid
36
+ done ( )
37
+ } )
38
+ } )
39
+
40
+ before ( function ( done ) {
41
+ loadDagContent ( ipfs , getMockObjects ( ) , ( err , cid ) => {
42
+ expect ( err ) . to . not . exist ( )
43
+ dagRootCid = cid
36
44
done ( )
37
45
} )
38
46
} )
@@ -55,7 +63,7 @@ module.exports = (createCommon, suiteName, ipfsRefs, options) => {
55
63
}
56
64
57
65
// Call out to IPFS
58
- const p = ( path ? path ( rootCid ) : rootCid )
66
+ const p = ( path ? path ( pbRootCb ) : pbRootCb )
59
67
ipfsRefs ( ipfs ) ( p , params , ( err , refs ) => {
60
68
if ( ! done ) {
61
69
// Already timed out
@@ -84,6 +92,32 @@ module.exports = (createCommon, suiteName, ipfsRefs, options) => {
84
92
} )
85
93
} )
86
94
}
95
+
96
+ it ( 'dag refs test' , function ( done ) {
97
+ this . timeout ( 20 * 1000 )
98
+
99
+ // Call out to IPFS
100
+ ipfsRefs ( ipfs ) ( `/ipfs/${ dagRootCid } ` , { recursive : true } , ( err , refs ) => {
101
+ // Check there was no error and the refs match what was expected
102
+ expect ( err ) . to . not . exist ( )
103
+ expect ( refs . map ( r => r . ref ) . sort ( ) ) . to . eql ( [
104
+ 'QmPDqvcuA4AkhBLBuh2y49yhUB98rCnxPxa3eVNC1kAbSC' ,
105
+ 'QmVwtsLUHurA6wUirPSdGeEW5tfBEqenXpeRaqr8XN7bNY' ,
106
+ 'QmXGL3ZdYV5rNLCfHe1QsFSQGekRFzgbBu1B3XGZ7DV9fd' ,
107
+ 'QmcSVZRN5E814KkPy4EHnftNAR7htbFvVhRKKqFs4FBwDG' ,
108
+ 'QmcSVZRN5E814KkPy4EHnftNAR7htbFvVhRKKqFs4FBwDG' ,
109
+ 'QmdBcHbK7uDQav8YrHsfKju3EKn48knxjd96KRMFs3gtS9' ,
110
+ 'QmeX96opBHZHLySMFoNiWS5msxjyX6rqtr3Rr1u7uxn7zJ' ,
111
+ 'Qmf8MwTnY7VdcnF8WcoJ3GB24NmNd1HsGzuEWCtUYDP38x' ,
112
+ 'zdpuAkqPgGuEFBFLcixZyFezWw3bsGUWVS6W7c8YhV5sdAc6E' ,
113
+ 'zdpuArVVBgigTbs6FdyqFFWUSsXymdruTtCVoboc91L3WTXi1' ,
114
+ 'zdpuAsrruPqzPDYs9c1FGNR5Wuyx8on64no6z62SRPv3viHGL' ,
115
+ 'zdpuAxTXSfaHaZNed3JG2WvcYNgd64v27ztB2zknrz5noPhz5'
116
+ ] )
117
+
118
+ done ( )
119
+ } )
120
+ } )
87
121
} )
88
122
}
89
123
@@ -121,7 +155,7 @@ function getRefsTests () {
121
155
} ,
122
156
123
157
'prints files in edges format' : {
124
- params : { e : true } ,
158
+ params : { edges : true } ,
125
159
expected : [
126
160
'Qmd5MhNjx3NSZm3L2QKG1TFvqkTRbtZwGJinqEfqpfHH7s -> QmYEJ7qQNZUvBnv4SZ3rEbksagaan3sGvnUq948vSG8Z34' ,
127
161
'Qmd5MhNjx3NSZm3L2QKG1TFvqkTRbtZwGJinqEfqpfHH7s -> QmUXzZKa3xhTauLektUiK4GiogHskuz1c57CnnoP4TgYJD' ,
@@ -161,7 +195,7 @@ function getRefsTests () {
161
195
162
196
'follows a path with recursion, <hash>/<subdir>' : {
163
197
path : ( cid ) => `/ipfs/${ cid } /animals` ,
164
- params : { format : '<linkname>' , r : true } ,
198
+ params : { format : '<linkname>' , recursive : true } ,
165
199
expected : [
166
200
'land' ,
167
201
'african.txt' ,
@@ -174,7 +208,7 @@ function getRefsTests () {
174
208
} ,
175
209
176
210
'recursively follows folders, -r' : {
177
- params : { format : '<linkname>' , r : true } ,
211
+ params : { format : '<linkname>' , recursive : true } ,
178
212
expected : [
179
213
'animals' ,
180
214
'land' ,
@@ -192,7 +226,7 @@ function getRefsTests () {
192
226
} ,
193
227
194
228
'recursive with unique option' : {
195
- params : { format : '<linkname>' , r : true , u : true } ,
229
+ params : { format : '<linkname>' , recursive : true , unique : true } ,
196
230
expected : [
197
231
'animals' ,
198
232
'land' ,
@@ -209,7 +243,7 @@ function getRefsTests () {
209
243
} ,
210
244
211
245
'max depth of 1' : {
212
- params : { format : '<linkname>' , r : true , 'max-depth' : 1 } ,
246
+ params : { format : '<linkname>' , recursive : true , maxDepth : 1 } ,
213
247
expected : [
214
248
'animals' ,
215
249
'atlantic-animals' ,
@@ -219,7 +253,7 @@ function getRefsTests () {
219
253
} ,
220
254
221
255
'max depth of 2' : {
222
- params : { format : '<linkname>' , r : true , 'max-depth' : 2 } ,
256
+ params : { format : '<linkname>' , recursive : true , maxDepth : 2 } ,
223
257
expected : [
224
258
'animals' ,
225
259
'land' ,
@@ -232,7 +266,7 @@ function getRefsTests () {
232
266
} ,
233
267
234
268
'max depth of 3' : {
235
- params : { format : '<linkname>' , r : true , 'max-depth' : 3 } ,
269
+ params : { format : '<linkname>' , recursive : true , maxDepth : 3 } ,
236
270
expected : [
237
271
'animals' ,
238
272
'land' ,
@@ -250,13 +284,13 @@ function getRefsTests () {
250
284
} ,
251
285
252
286
'max depth of 0' : {
253
- params : { r : true , 'max-depth' : 0 } ,
287
+ params : { recursive : true , maxDepth : 0 } ,
254
288
expected : [ ]
255
289
} ,
256
290
257
291
'follows a path with max depth 1, <hash>/<subdir>' : {
258
292
path : ( cid ) => `/ipfs/${ cid } /animals` ,
259
- params : { format : '<linkname>' , r : true , 'max-depth' : 1 } ,
293
+ params : { format : '<linkname>' , recursive : true , maxDepth : 1 } ,
260
294
expected : [
261
295
'land' ,
262
296
'sea'
@@ -265,7 +299,7 @@ function getRefsTests () {
265
299
266
300
'follows a path with max depth 2, <hash>/<subdir>' : {
267
301
path : ( cid ) => `/ipfs/${ cid } /animals` ,
268
- params : { format : '<linkname>' , r : true , 'max-depth' : 2 } ,
302
+ params : { format : '<linkname>' , recursive : true , maxDepth : 2 } ,
269
303
expected : [
270
304
'land' ,
271
305
'african.txt' ,
@@ -277,8 +311,23 @@ function getRefsTests () {
277
311
]
278
312
} ,
279
313
314
+ 'prints refs for multiple paths' : {
315
+ path : ( cid ) => [ `/ipfs/${ cid } /animals` , `/ipfs/${ cid } /fruits` ] ,
316
+ params : { format : '<linkname>' , recursive : true } ,
317
+ expected : [
318
+ 'land' ,
319
+ 'african.txt' ,
320
+ 'americas.txt' ,
321
+ 'australian.txt' ,
322
+ 'sea' ,
323
+ 'atlantic.txt' ,
324
+ 'indian.txt' ,
325
+ 'tropical.txt'
326
+ ]
327
+ } ,
328
+
280
329
'cannot specify edges and format' : {
281
- params : { format : '<linkname>' , e : true } ,
330
+ params : { format : '<linkname>' , edges : true } ,
282
331
expectError : true
283
332
} ,
284
333
@@ -289,27 +338,58 @@ function getRefsTests () {
289
338
}
290
339
}
291
340
292
- function loadContent ( ipfs , node , callback ) {
341
+ function loadPbContent ( ipfs , node , callback ) {
342
+ const store = {
343
+ putData : ( data , cb ) => ipfs . object . put ( { Data : data , Links : [ ] } , cb ) ,
344
+ putLinks : ( links , cb ) => {
345
+ ipfs . object . put ( {
346
+ Data : '' ,
347
+ Links : links . map ( ( { name, cid } ) => ( { Name : name , Hash : cid , Size : 8 } ) )
348
+ } , cb )
349
+ }
350
+ }
351
+ loadContent ( ipfs , store , node , callback )
352
+ }
353
+
354
+ function loadDagContent ( ipfs , node , callback ) {
355
+ const store = {
356
+ putData : ( data , cb ) => {
357
+ ipfs . add ( Buffer . from ( data ) , ( err , res ) => {
358
+ if ( err ) {
359
+ return callback ( err )
360
+ }
361
+ return cb ( null , res [ 0 ] . hash )
362
+ } )
363
+ } ,
364
+ putLinks : ( links , cb ) => {
365
+ const obj = { }
366
+ for ( const { name, cid } of links ) {
367
+ obj [ name ] = { '/' : cid }
368
+ }
369
+ ipfs . dag . put ( obj , cb )
370
+ }
371
+ }
372
+ loadContent ( ipfs , store , node , callback )
373
+ }
374
+
375
+ function loadContent ( ipfs , store , node , callback ) {
293
376
if ( Array . isArray ( node ) ) {
294
- ipfs . object . put ( { Data : node . join ( '\n' ) , Links : [ ] } , callback )
377
+ return store . putData ( node . join ( '\n' ) , callback )
295
378
}
296
379
297
380
if ( typeof node === 'object' ) {
298
381
const entries = Object . entries ( node )
299
382
const sorted = entries . sort ( ( a , b ) => a [ 0 ] > b [ 0 ] ? 1 : a [ 0 ] < b [ 0 ] ? - 1 : 0 )
300
383
map ( sorted , ( [ name , child ] , cb ) => {
301
- loadContent ( ipfs , child , ( err , cid ) => {
384
+ loadContent ( ipfs , store , child , ( err , cid ) => {
302
385
cb ( err , { name, cid : cid && cid . toString ( ) } )
303
386
} )
304
387
} , ( err , res ) => {
305
388
if ( err ) {
306
389
return callback ( err )
307
390
}
308
391
309
- ipfs . object . put ( {
310
- Data : '' ,
311
- Links : res . map ( ( { name, cid } ) => ( { Name : name , Hash : cid , Size : 8 } ) )
312
- } , callback )
392
+ store . putLinks ( res , callback )
313
393
} )
314
394
}
315
395
}
0 commit comments