@@ -330,22 +330,80 @@ describe('.files (the MFS API part)', function () {
330
330
ipfs . files . flush ( '/' , done )
331
331
} )
332
332
333
- it ( 'files.cp' , ( done ) => {
334
- ipfs . files . cp ( [
335
- '/ipfs/Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' ,
336
- '/test- folder/test-file'
337
- ] , ( err ) => {
338
- expect ( err ) . to . not . exist ( )
339
- done ( )
340
- } )
333
+ it ( 'files.cp' , ( ) => {
334
+ const folder = `/test-folder- ${ Math . random ( ) } `
335
+
336
+ return ipfs . files . mkdir ( folder )
337
+ . then ( ( ) => ipfs . files . cp ( [
338
+ '/ipfs/Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' ,
339
+ ` ${ folder } /test-file- ${ Math . random ( ) } `
340
+ ] ) )
341
341
} )
342
342
343
- it ( 'files.ls' , ( done ) => {
344
- ipfs . files . ls ( '/test-folder' , ( err , res ) => {
345
- expect ( err ) . to . not . exist ( )
346
- expect ( res . length ) . to . equal ( 1 )
347
- done ( )
348
- } )
343
+ it ( 'files.cp with non-array arguments' , ( ) => {
344
+ const folder = `/test-folder-${ Math . random ( ) } `
345
+
346
+ return ipfs . files . mkdir ( folder )
347
+ . then ( ( ) => ipfs . files . cp (
348
+ '/ipfs/Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' ,
349
+ `${ folder } /test-file-${ Math . random ( ) } `
350
+ ) )
351
+ } )
352
+
353
+ it ( 'files.mv' , ( ) => {
354
+ const folder = `/test-folder-${ Math . random ( ) } `
355
+ const source = `${ folder } /test-file-${ Math . random ( ) } `
356
+ const dest = `${ folder } /test-file-${ Math . random ( ) } `
357
+
358
+ return ipfs . files . mkdir ( folder )
359
+ . then ( ( ) => ipfs . files . cp (
360
+ '/ipfs/Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' ,
361
+ source
362
+ ) )
363
+ . then ( ( ) => ipfs . files . mv ( [
364
+ source ,
365
+ dest
366
+ ] ) )
367
+ } )
368
+
369
+ it ( 'files.mv with non-array arguments' , ( ) => {
370
+ const folder = `/test-folder-${ Math . random ( ) } `
371
+ const source = `${ folder } /test-file-${ Math . random ( ) } `
372
+ const dest = `${ folder } /test-file-${ Math . random ( ) } `
373
+
374
+ return ipfs . files . mkdir ( folder )
375
+ . then ( ( ) => ipfs . files . cp (
376
+ '/ipfs/Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' ,
377
+ source
378
+ ) )
379
+ . then ( ( ) => ipfs . files . mv (
380
+ source ,
381
+ dest
382
+ ) )
383
+ } )
384
+
385
+ it ( 'files.ls' , ( ) => {
386
+ const folder = `/test-folder-${ Math . random ( ) } `
387
+ const file = `${ folder } /test-file-${ Math . random ( ) } `
388
+
389
+ return ipfs . files . mkdir ( folder )
390
+ . then ( ( ) => ipfs . files . write ( file , Buffer . from ( 'Hello, world' ) , {
391
+ create : true
392
+ } ) )
393
+ . then ( ( ) => ipfs . files . ls ( folder ) )
394
+ . then ( files => {
395
+ expect ( files . length ) . to . equal ( 1 )
396
+ } )
397
+ } )
398
+
399
+ it ( 'files.ls mfs root by default' , ( ) => {
400
+ const folder = `/test-folder-${ Math . random ( ) } `
401
+
402
+ return ipfs . files . mkdir ( folder )
403
+ . then ( ( ) => ipfs . files . ls ( ) )
404
+ . then ( files => {
405
+ expect ( files . length ) . to . equal ( 1 )
406
+ } )
349
407
} )
350
408
351
409
it ( 'files.write' , ( done ) => {
@@ -374,22 +432,27 @@ describe('.files (the MFS API part)', function () {
374
432
} )
375
433
} )
376
434
377
- it ( 'files.stat' , ( done ) => {
378
- ipfs . files . stat ( '/test-folder/test-file' , ( err , res ) => {
379
- expect ( err ) . to . not . exist ( )
380
- expect ( res ) . to . deep . equal ( {
381
- hash : 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' ,
382
- size : 12 ,
383
- cumulativeSize : 20 ,
384
- blocks : 0 ,
385
- type : 'file' ,
386
- withLocality : false ,
387
- local : undefined ,
388
- sizeLocal : undefined
435
+ it ( 'files.stat' , ( ) => {
436
+ const folder = `/test-folder-${ Math . random ( ) } `
437
+ const file = `${ folder } /test-file-${ Math . random ( ) } `
438
+
439
+ return ipfs . files . mkdir ( folder )
440
+ . then ( ( ) => ipfs . files . write ( file , testfile , {
441
+ create : true
442
+ } ) )
443
+ . then ( ( ) => ipfs . files . stat ( file ) )
444
+ . then ( ( stats ) => {
445
+ expect ( stats ) . to . deep . equal ( {
446
+ hash : 'QmQhouoDPAnzhVM148yCa9CbUXK65wSEAZBtgrLGHtmdmP' ,
447
+ size : 12 ,
448
+ cumulativeSize : 70 ,
449
+ blocks : 1 ,
450
+ type : 'file' ,
451
+ withLocality : false ,
452
+ local : undefined ,
453
+ sizeLocal : undefined
454
+ } )
389
455
} )
390
-
391
- done ( )
392
- } )
393
456
} )
394
457
395
458
it ( 'files.stat file that does not exist()' , ( done ) => {
@@ -402,16 +465,18 @@ describe('.files (the MFS API part)', function () {
402
465
} )
403
466
} )
404
467
405
- it ( 'files.read' , ( done ) => {
406
- if ( ! isNode ) {
407
- return done ( )
408
- }
409
-
410
- ipfs . files . read ( '/test-folder/test-file' , ( err , buf ) => {
411
- expect ( err ) . to . not . exist ( )
412
- expect ( Buffer . from ( buf ) ) . to . deep . equal ( testfile )
413
- done ( )
414
- } )
468
+ it ( 'files.read' , ( ) => {
469
+ const folder = `/test-folder-${ Math . random ( ) } `
470
+ const file = `${ folder } /test-file-${ Math . random ( ) } `
471
+
472
+ return ipfs . files . mkdir ( folder )
473
+ . then ( ( ) => ipfs . files . write ( file , testfile , {
474
+ create : true
475
+ } ) )
476
+ . then ( ( ) => ipfs . files . read ( file ) )
477
+ . then ( ( buf ) => {
478
+ expect ( Buffer . from ( buf ) ) . to . deep . equal ( testfile )
479
+ } )
415
480
} )
416
481
417
482
it ( 'files.rm without options' , ( done ) => {
0 commit comments