@@ -5,6 +5,7 @@ const chai = require('chai')
55chai . use ( require ( 'dirty-chai' ) )
66const expect = chai . expect
77const bufferStream = require ( './fixtures/buffer-stream' )
8+ const bs58 = require ( 'bs58' )
89
910const {
1011 createMfs
@@ -66,8 +67,23 @@ describe('cp', function () {
6667 } )
6768 } )
6869
69- it . skip ( 'refuses to copy multiple files to one file' , ( ) => {
70+ it ( 'refuses to copy files to an exsting file' , ( ) => {
71+ const source = `/source-file-${ Math . random ( ) } .txt`
72+ const destination = `/dest-file-${ Math . random ( ) } .txt`
7073
74+ return mfs . write ( source , bufferStream ( 100 ) , {
75+ create : true
76+ } )
77+ . then ( ( ) => mfs . write ( destination , bufferStream ( 100 ) , {
78+ create : true
79+ } ) )
80+ . then ( ( ) => mfs . cp ( source , destination ) )
81+ . then ( ( ) => {
82+ throw new Error ( 'No error was thrown for a non-existent file' )
83+ } )
84+ . catch ( error => {
85+ expect ( error . message ) . to . contain ( 'Directory already has entry by that name' )
86+ } )
7187 } )
7288
7389 it ( 'copies a file to new location' , ( ) => {
@@ -89,20 +105,50 @@ describe('cp', function () {
89105 } )
90106 } )
91107
92- it . skip ( 'copies a file to a directory' , ( ) => {
93-
94- } )
95-
96- it . skip ( 'copies directories' , ( ) => {
108+ it ( 'copies a file to a pre-existing directory' , ( ) => {
109+ const source = `/source-file-${ Math . random ( ) } .txt`
110+ const directory = `/dest-directory-${ Math . random ( ) } `
111+ const destination = `${ directory } ${ source } `
97112
113+ return mfs . write ( source , bufferStream ( 500 ) , {
114+ create : true
115+ } )
116+ . then ( ( ) => mfs . mkdir ( directory ) )
117+ . then ( ( ) => mfs . cp ( source , directory ) )
118+ . then ( ( ) => mfs . stat ( destination ) )
119+ . then ( ( stats ) => {
120+ expect ( stats . size ) . to . equal ( 500 )
121+ } )
98122 } )
99123
100- it . skip ( 'refuses to copy directories recursively without the recursive flag' , ( ) => {
124+ it ( 'copies directories' , ( ) => {
125+ const source = `/source-directory-${ Math . random ( ) } `
126+ const destination = `/dest-directory-${ Math . random ( ) } `
101127
128+ return mfs . mkdir ( source )
129+ . then ( ( ) => mfs . cp ( source , destination ) )
130+ . then ( ( ) => mfs . stat ( destination ) )
131+ . then ( ( stats ) => {
132+ expect ( stats . type ) . to . equal ( 'directory' )
133+ } )
102134 } )
103135
104- it . skip ( 'copies directories recursively' , ( ) => {
105-
136+ it ( 'copies directories recursively' , ( ) => {
137+ const directory = `/source-directory-${ Math . random ( ) } `
138+ const subDirectory = `/source-directory-${ Math . random ( ) } `
139+ const source = `${ directory } /${ subDirectory } `
140+ const destination = `/dest-directory-${ Math . random ( ) } `
141+
142+ return mfs . mkdir ( source )
143+ . then ( ( ) => mfs . cp ( directory , destination ) )
144+ . then ( ( ) => mfs . stat ( destination ) )
145+ . then ( ( stats ) => {
146+ expect ( stats . type ) . to . equal ( 'directory' )
147+ } )
148+ . then ( ( ) => mfs . stat ( `${ destination } /${ subDirectory } ` ) )
149+ . then ( ( stats ) => {
150+ expect ( stats . type ) . to . equal ( 'directory' )
151+ } )
106152 } )
107153
108154 it ( 'copies multiple files to new location' , ( ) => {
@@ -141,4 +187,19 @@ describe('cp', function () {
141187 )
142188 ) )
143189 } )
190+
191+ it . skip ( 'copies files from ipfs paths' , ( ) => {
192+ const source = `/source-file-${ Math . random ( ) } .txt`
193+ const destination = `/dest-file-${ Math . random ( ) } .txt`
194+
195+ return mfs . write ( source , bufferStream ( 100 ) , {
196+ create : true
197+ } )
198+ . then ( ( ) => mfs . stat ( source ) )
199+ . then ( ( stats ) => mfs . cp ( `/ipfs/${ bs58 . encode ( stats . hash ) } ` , destination ) )
200+ . then ( ( ) => mfs . stat ( destination ) )
201+ . then ( ( stats ) => {
202+ expect ( stats . size ) . to . equal ( 100 )
203+ } )
204+ } )
144205} )
0 commit comments