@@ -6,7 +6,6 @@ const chai = require('chai')
66const dirtyChai = require ( 'dirty-chai' )
77const expect = chai . expect
88chai . use ( dirtyChai )
9- const isNode = require ( 'detect-node' )
109const loadFixture = require ( 'aegir/fixtures' )
1110const mh = require ( 'multihashes' )
1211const CID = require ( 'cids' )
@@ -330,22 +329,80 @@ describe('.files (the MFS API part)', function () {
330329 ipfs . files . flush ( '/' , done )
331330 } )
332331
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- } )
332+ it ( 'files.cp' , ( ) => {
333+ const folder = `/test-folder- ${ Math . random ( ) } `
334+
335+ return ipfs . files . mkdir ( folder )
336+ . then ( ( ) => ipfs . files . cp ( [
337+ '/ipfs/Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' ,
338+ ` ${ folder } /test-file- ${ Math . random ( ) } `
339+ ] ) )
341340 } )
342341
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- } )
342+ it ( 'files.cp with non-array arguments' , ( ) => {
343+ const folder = `/test-folder-${ Math . random ( ) } `
344+
345+ return ipfs . files . mkdir ( folder )
346+ . then ( ( ) => ipfs . files . cp (
347+ '/ipfs/Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' ,
348+ `${ folder } /test-file-${ Math . random ( ) } `
349+ ) )
350+ } )
351+
352+ it ( 'files.mv' , ( ) => {
353+ const folder = `/test-folder-${ Math . random ( ) } `
354+ const source = `${ folder } /test-file-${ Math . random ( ) } `
355+ const dest = `${ folder } /test-file-${ Math . random ( ) } `
356+
357+ return ipfs . files . mkdir ( folder )
358+ . then ( ( ) => ipfs . files . cp (
359+ '/ipfs/Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' ,
360+ source
361+ ) )
362+ . then ( ( ) => ipfs . files . mv ( [
363+ source ,
364+ dest
365+ ] ) )
366+ } )
367+
368+ it ( 'files.mv with non-array arguments' , ( ) => {
369+ const folder = `/test-folder-${ Math . random ( ) } `
370+ const source = `${ folder } /test-file-${ Math . random ( ) } `
371+ const dest = `${ folder } /test-file-${ Math . random ( ) } `
372+
373+ return ipfs . files . mkdir ( folder )
374+ . then ( ( ) => ipfs . files . cp (
375+ '/ipfs/Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' ,
376+ source
377+ ) )
378+ . then ( ( ) => ipfs . files . mv (
379+ source ,
380+ dest
381+ ) )
382+ } )
383+
384+ it ( 'files.ls' , ( ) => {
385+ const folder = `/test-folder-${ Math . random ( ) } `
386+ const file = `${ folder } /test-file-${ Math . random ( ) } `
387+
388+ return ipfs . files . mkdir ( folder )
389+ . then ( ( ) => ipfs . files . write ( file , Buffer . from ( 'Hello, world' ) , {
390+ create : true
391+ } ) )
392+ . then ( ( ) => ipfs . files . ls ( folder ) )
393+ . then ( files => {
394+ expect ( files . length ) . to . equal ( 1 )
395+ } )
396+ } )
397+
398+ it ( 'files.ls mfs root by default' , ( ) => {
399+ const folder = `test-folder-${ Math . random ( ) } `
400+
401+ return ipfs . files . mkdir ( `/${ folder } ` )
402+ . then ( ( ) => ipfs . files . ls ( ) )
403+ . then ( files => {
404+ expect ( files . find ( file => file . name === folder ) ) . to . be . ok ( )
405+ } )
349406 } )
350407
351408 it ( 'files.write' , ( done ) => {
@@ -374,22 +431,27 @@ describe('.files (the MFS API part)', function () {
374431 } )
375432 } )
376433
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
434+ it ( 'files.stat' , ( ) => {
435+ const folder = `/test-folder-${ Math . random ( ) } `
436+ const file = `${ folder } /test-file-${ Math . random ( ) } `
437+
438+ return ipfs . files . mkdir ( folder )
439+ . then ( ( ) => ipfs . files . write ( file , testfile , {
440+ create : true
441+ } ) )
442+ . then ( ( ) => ipfs . files . stat ( file ) )
443+ . then ( ( stats ) => {
444+ expect ( stats ) . to . deep . equal ( {
445+ hash : 'QmQhouoDPAnzhVM148yCa9CbUXK65wSEAZBtgrLGHtmdmP' ,
446+ size : 12 ,
447+ cumulativeSize : 70 ,
448+ blocks : 1 ,
449+ type : 'file' ,
450+ withLocality : false ,
451+ local : undefined ,
452+ sizeLocal : undefined
453+ } )
389454 } )
390-
391- done ( )
392- } )
393455 } )
394456
395457 it ( 'files.stat file that does not exist()' , ( done ) => {
@@ -402,16 +464,18 @@ describe('.files (the MFS API part)', function () {
402464 } )
403465 } )
404466
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- } )
467+ it ( 'files.read' , ( ) => {
468+ const folder = `/test-folder-${ Math . random ( ) } `
469+ const file = `${ folder } /test-file-${ Math . random ( ) } `
470+
471+ return ipfs . files . mkdir ( folder )
472+ . then ( ( ) => ipfs . files . write ( file , testfile , {
473+ create : true
474+ } ) )
475+ . then ( ( ) => ipfs . files . read ( file ) )
476+ . then ( ( buf ) => {
477+ expect ( Buffer . from ( buf ) ) . to . deep . equal ( testfile )
478+ } )
415479 } )
416480
417481 it ( 'files.rm without options' , ( done ) => {
0 commit comments