@@ -5,6 +5,7 @@ const chai = require('chai')
5
5
chai . use ( require ( 'dirty-chai' ) )
6
6
const expect = chai . expect
7
7
const bufferStream = require ( './fixtures/buffer-stream' )
8
+ const bs58 = require ( 'bs58' )
8
9
9
10
const {
10
11
createMfs
@@ -66,8 +67,23 @@ describe('cp', function () {
66
67
} )
67
68
} )
68
69
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`
70
73
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
+ } )
71
87
} )
72
88
73
89
it ( 'copies a file to new location' , ( ) => {
@@ -89,20 +105,50 @@ describe('cp', function () {
89
105
} )
90
106
} )
91
107
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 } `
97
112
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
+ } )
98
122
} )
99
123
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 ( ) } `
101
127
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
+ } )
102
134
} )
103
135
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
+ } )
106
152
} )
107
153
108
154
it ( 'copies multiple files to new location' , ( ) => {
@@ -141,4 +187,19 @@ describe('cp', function () {
141
187
)
142
188
) )
143
189
} )
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
+ } )
144
205
} )
0 commit comments