@@ -702,4 +702,129 @@ describe('IPFS Node.js API wrapper tests', function () {
702
702
} )
703
703
} )
704
704
} )
705
+
706
+ describe ( '.files' , function ( ) {
707
+ it ( 'files.mkdir' , function ( done ) {
708
+ this . timeout ( 20000 )
709
+
710
+ apiClients [ 'a' ] . files . mkdir ( '/test-folder' , function ( err ) {
711
+ assert ( ! err )
712
+ if ( err ) {
713
+ return done ( )
714
+ }
715
+ done ( )
716
+ } )
717
+ } )
718
+
719
+ it ( 'files.cp' , function ( done ) {
720
+ this . timeout ( 20000 )
721
+
722
+ apiClients [ 'a' ] . files
723
+ . cp ( [ '/ipfs/Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' , '/test-folder/test-file' ] , function ( err ) {
724
+ assert ( ! err )
725
+ if ( err ) {
726
+ return done ( )
727
+ }
728
+ done ( )
729
+ } )
730
+ } )
731
+
732
+ it ( 'files.ls' , function ( done ) {
733
+ this . timeout ( 20000 )
734
+
735
+ apiClients [ 'a' ] . files . ls ( '/test-folder' , function ( err , res ) {
736
+ assert ( ! err )
737
+ if ( err ) {
738
+ return done ( )
739
+ }
740
+ assert . equal ( res . Entries . length , 1 )
741
+ done ( )
742
+ } )
743
+ } )
744
+
745
+ it ( 'files.stat' , function ( done ) {
746
+ this . timeout ( 20000 )
747
+
748
+ apiClients [ 'a' ] . files . stat ( '/test-folder/test-file' , function ( err , res ) {
749
+ assert ( ! err )
750
+
751
+ if ( err ) {
752
+ return done ( )
753
+ }
754
+ assert . deepEqual ( res , {
755
+ Hash : 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP' ,
756
+ Size : 12 ,
757
+ CumulativeSize : 20 ,
758
+ Blocks : 0
759
+ } )
760
+
761
+ done ( )
762
+ } )
763
+ } )
764
+
765
+ // -
766
+
767
+ it ( 'files.read' , function ( done ) {
768
+ this . timeout ( 20000 )
769
+
770
+ apiClients [ 'a' ] . files . read ( '/test-folder/test-file' , function ( err , stream ) {
771
+ if ( err ) {
772
+ throw err
773
+ }
774
+
775
+ var buf = ''
776
+ stream
777
+ . on ( 'error' , function ( err ) { throw err } )
778
+ . on ( 'data' , function ( data ) { buf += data } )
779
+ . on ( 'end' , function ( ) {
780
+ assert . equal ( buf , fs . readFileSync ( testfilePath ) )
781
+ done ( )
782
+ } )
783
+ } )
784
+ } )
785
+
786
+ it ( 'files.read for file that does not exist' , function ( done ) {
787
+ this . timeout ( 20000 )
788
+
789
+ apiClients [ 'a' ] . files . read ( '/test-folder/test-file-not-exist' , function ( err , stream ) {
790
+ if ( err ) {
791
+ done ( )
792
+ }
793
+ } )
794
+ } )
795
+
796
+ it ( 'files.write' , function ( done ) {
797
+ this . timeout ( 20000 )
798
+
799
+ apiClients [ 'a' ] . files . write ( '/test-folder/test-file' , new Buffer ( 'bananas' ) , function ( err ) {
800
+ if ( err ) {
801
+ throw err
802
+ }
803
+ done ( )
804
+ } )
805
+ } )
806
+
807
+ it ( 'files.mv' , function ( done ) {
808
+ this . timeout ( 20000 )
809
+
810
+ apiClients [ 'a' ] . files . mv ( [ '/test-folder/test-file' , '/test-folder/test-file2' ] , function ( err ) {
811
+ if ( err ) throw err
812
+ done ( )
813
+ } )
814
+ } )
815
+
816
+ // -
817
+
818
+ it ( 'files.rm' , function ( done ) {
819
+ this . timeout ( 20000 )
820
+
821
+ apiClients [ 'a' ] . files . rm ( '/test-folder' , { 'recursive' : true } , function ( err ) {
822
+ assert ( ! err )
823
+ if ( err ) {
824
+ return done ( )
825
+ }
826
+ done ( )
827
+ } )
828
+ } )
829
+ } )
705
830
} )
0 commit comments