2
2
/* eslint max-nested-callbacks: ["error", 8] */
3
3
'use strict'
4
4
5
+ const hat = require ( 'hat' )
5
6
const chai = require ( 'chai' )
6
7
const dirtyChai = require ( 'dirty-chai' )
7
8
const DaemonFactory = require ( 'ipfsd-ctl' )
@@ -34,7 +35,7 @@ describe('.files', () => {
34
35
35
36
describe ( '.add' , function ( ) {
36
37
it ( 'performs a speculative add, --only-hash' , ( ) => {
37
- const content = String ( Math . random ( ) )
38
+ const content = hat ( )
38
39
39
40
return ipfs . add ( Buffer . from ( content ) , { onlyHash : true } )
40
41
. then ( files => {
@@ -60,7 +61,7 @@ describe('.files', () => {
60
61
} )
61
62
62
63
it ( 'lists files' , ( ) => {
63
- const fileName = `single-file-${ Math . random ( ) } .txt`
64
+ const fileName = `single-file-${ hat ( ) } .txt`
64
65
65
66
return ipfs . files . write ( `/${ fileName } ` , Buffer . from ( 'Hello world' ) , {
66
67
create : true
@@ -73,8 +74,8 @@ describe('.files', () => {
73
74
} )
74
75
75
76
it ( 'lists files in directories' , ( ) => {
76
- const dirName = `dir-${ Math . random ( ) } `
77
- const fileName = `file-in-dir-${ Math . random ( ) } .txt`
77
+ const dirName = `dir-${ hat ( ) } `
78
+ const fileName = `file-in-dir-${ hat ( ) } .txt`
78
79
79
80
return ipfs . files . write ( `/${ dirName } /${ fileName } ` , Buffer . from ( 'Hello world' ) , {
80
81
create : true ,
@@ -90,8 +91,8 @@ describe('.files', () => {
90
91
91
92
describe ( '.cp' , function ( ) {
92
93
it ( 'copies a file' , ( ) => {
93
- const source = `source-file-${ Math . random ( ) } .txt`
94
- const destination = `destination-file-${ Math . random ( ) } .txt`
94
+ const source = `source-file-${ hat ( ) } .txt`
95
+ const destination = `destination-file-${ hat ( ) } .txt`
95
96
96
97
return ipfs . files . write ( `/${ source } ` , Buffer . from ( 'Hello world' ) , {
97
98
create : true
@@ -116,8 +117,8 @@ describe('.files', () => {
116
117
} )
117
118
118
119
it ( 'copies a directory' , ( ) => {
119
- const source = `source-dir-${ Math . random ( ) } `
120
- const destination = `destination-dir-${ Math . random ( ) } `
120
+ const source = `source-dir-${ hat ( ) } `
121
+ const destination = `destination-dir-${ hat ( ) } `
121
122
122
123
return ipfs . files . mkdir ( `/${ source } ` )
123
124
. then ( ( ) => ipfs . files . cp ( `/${ source } ` , `/${ destination } ` ) )
@@ -140,8 +141,8 @@ describe('.files', () => {
140
141
} )
141
142
142
143
it ( 'copies a file with array args' , ( ) => {
143
- const source = `source-file-${ Math . random ( ) } .txt`
144
- const destination = `destination-file-${ Math . random ( ) } .txt`
144
+ const source = `source-file-${ hat ( ) } .txt`
145
+ const destination = `destination-file-${ hat ( ) } .txt`
145
146
146
147
return ipfs . files . write ( `/${ source } ` , Buffer . from ( 'Hello world' ) , {
147
148
create : true
@@ -166,8 +167,8 @@ describe('.files', () => {
166
167
} )
167
168
168
169
it ( 'copies a directory with array args' , ( ) => {
169
- const source = `source-dir-${ Math . random ( ) } `
170
- const destination = `destination-dir-${ Math . random ( ) } `
170
+ const source = `source-dir-${ hat ( ) } `
171
+ const destination = `destination-dir-${ hat ( ) } `
171
172
172
173
return ipfs . files . mkdir ( `/${ source } ` )
173
174
. then ( ( ) => ipfs . files . cp ( [ `/${ source } ` , `/${ destination } ` ] ) )
@@ -192,7 +193,7 @@ describe('.files', () => {
192
193
193
194
describe ( '.mkdir' , function ( ) {
194
195
it ( 'makes a directory' , ( ) => {
195
- const directory = `directory-${ Math . random ( ) } `
196
+ const directory = `directory-${ hat ( ) } `
196
197
197
198
return ipfs . files . mkdir ( `/${ directory } ` )
198
199
. then ( ( ) => ipfs . files . ls ( `/` , {
@@ -210,8 +211,8 @@ describe('.files', () => {
210
211
211
212
describe ( '.mv' , function ( ) {
212
213
it ( 'moves a file' , ( ) => {
213
- const source = `source-file-${ Math . random ( ) } .txt`
214
- const destination = `destination-file-${ Math . random ( ) } .txt`
214
+ const source = `source-file-${ hat ( ) } .txt`
215
+ const destination = `destination-file-${ hat ( ) } .txt`
215
216
216
217
return ipfs . files . write ( `/${ source } ` , Buffer . from ( 'Hello world' ) , {
217
218
create : true
@@ -234,8 +235,8 @@ describe('.files', () => {
234
235
} )
235
236
236
237
it ( 'moves a directory' , ( ) => {
237
- const source = `source-dir-${ Math . random ( ) } `
238
- const destination = `destination-dir-${ Math . random ( ) } `
238
+ const source = `source-dir-${ hat ( ) } `
239
+ const destination = `destination-dir-${ hat ( ) } `
239
240
240
241
return ipfs . files . mkdir ( `/${ source } ` )
241
242
. then ( ( ) => ipfs . files . mv ( `/${ source } ` , `/${ destination } ` ) )
@@ -258,8 +259,8 @@ describe('.files', () => {
258
259
} )
259
260
260
261
it ( 'moves a file with array args' , ( ) => {
261
- const source = `source-file-${ Math . random ( ) } .txt`
262
- const destination = `destination-file-${ Math . random ( ) } .txt`
262
+ const source = `source-file-${ hat ( ) } .txt`
263
+ const destination = `destination-file-${ hat ( ) } .txt`
263
264
264
265
return ipfs . files . write ( `/${ source } ` , Buffer . from ( 'Hello world' ) , {
265
266
create : true
@@ -282,8 +283,8 @@ describe('.files', () => {
282
283
} )
283
284
284
285
it ( 'moves a directory with array args' , ( ) => {
285
- const source = `source-dir-${ Math . random ( ) } `
286
- const destination = `destination-dir-${ Math . random ( ) } `
286
+ const source = `source-dir-${ hat ( ) } `
287
+ const destination = `destination-dir-${ hat ( ) } `
287
288
288
289
return ipfs . files . mkdir ( `/${ source } ` )
289
290
. then ( ( ) => ipfs . files . mv ( [ `/${ source } ` , `/${ destination } ` ] ) )
@@ -308,7 +309,7 @@ describe('.files', () => {
308
309
309
310
describe ( '.read' , function ( ) {
310
311
it ( 'reads a file' , ( ) => {
311
- const fileName = `single-file-${ Math . random ( ) } .txt`
312
+ const fileName = `single-file-${ hat ( ) } .txt`
312
313
const content = Buffer . from ( 'Hello world' )
313
314
314
315
return ipfs . files . write ( `/${ fileName } ` , content , {
@@ -323,7 +324,7 @@ describe('.files', () => {
323
324
324
325
describe ( '.rm' , function ( ) {
325
326
it ( 'removes a file' , ( ) => {
326
- const fileName = `single-file-${ Math . random ( ) } .txt`
327
+ const fileName = `single-file-${ hat ( ) } .txt`
327
328
328
329
return ipfs . files . write ( `/${ fileName } ` , Buffer . from ( 'Hello world' ) , {
329
330
create : true
@@ -340,8 +341,8 @@ describe('.files', () => {
340
341
} )
341
342
342
343
it ( 'removes a directory' , ( ) => {
343
- const dirName = `dir-${ Math . random ( ) } `
344
- const fileName = `file-in-dir-${ Math . random ( ) } .txt`
344
+ const dirName = `dir-${ hat ( ) } `
345
+ const fileName = `file-in-dir-${ hat ( ) } .txt`
345
346
346
347
return ipfs . files . write ( `/${ dirName } /${ fileName } ` , Buffer . from ( 'Hello world' ) , {
347
348
create : true ,
@@ -363,7 +364,7 @@ describe('.files', () => {
363
364
364
365
describe ( '.stat' , function ( ) {
365
366
it ( 'stats a file' , ( ) => {
366
- const fileName = `single-file-${ Math . random ( ) } .txt`
367
+ const fileName = `single-file-${ hat ( ) } .txt`
367
368
368
369
return ipfs . files . write ( `/${ fileName } ` , Buffer . from ( 'Hello world' ) , {
369
370
create : true
@@ -384,7 +385,7 @@ describe('.files', () => {
384
385
} )
385
386
386
387
it ( 'stats a directory' , ( ) => {
387
- const dirName = `dir-${ Math . random ( ) } `
388
+ const dirName = `dir-${ hat ( ) } `
388
389
389
390
return ipfs . files . mkdir ( `/${ dirName } ` )
390
391
. then ( ( ) => ipfs . files . stat ( `/${ dirName } ` ) )
0 commit comments