@@ -7,6 +7,14 @@ const parallel = require('async/parallel')
7
7
const waterfall = require ( 'async/waterfall' )
8
8
const bl = require ( 'bl' )
9
9
const crypto = require ( 'crypto' )
10
+ const pretty = require ( 'pretty-bytes' )
11
+ const randomFs = require ( 'random-fs' )
12
+ const promisify = require ( 'promisify-es6' )
13
+ const rimraf = require ( 'rimraf' )
14
+
15
+ const rmDir = promisify ( rimraf )
16
+
17
+ const tmpDir = require ( './util' ) . tmpDir
10
18
11
19
const GoDaemon = require ( './daemons/go' )
12
20
const JsDaemon = require ( './daemons/js' )
@@ -19,12 +27,18 @@ const sizes = [
19
27
1024 * 512 ,
20
28
1024 * 768 ,
21
29
1024 * 1023 ,
22
- // starts failing with multiplex
23
30
1024 * 1024 ,
24
31
1024 * 1024 * 4 ,
25
32
1024 * 1024 * 8
26
33
]
27
34
35
+ const dirs = [
36
+ 5 ,
37
+ 10 ,
38
+ 50 ,
39
+ 100
40
+ ]
41
+
28
42
describe ( 'basic' , ( ) => {
29
43
let goDaemon
30
44
let jsDaemon
@@ -107,7 +121,7 @@ describe('basic', () => {
107
121
} )
108
122
109
123
describe ( 'cat file' , ( ) => sizes . forEach ( ( size ) => {
110
- it ( `go -> js: ${ size } bytes ` , ( done ) => {
124
+ it ( `go -> js: ${ pretty ( size ) } ` , ( done ) => {
111
125
const data = crypto . randomBytes ( size )
112
126
waterfall ( [
113
127
( cb ) => goDaemon . api . add ( data , cb ) ,
@@ -120,7 +134,7 @@ describe('basic', () => {
120
134
} )
121
135
} )
122
136
123
- it ( `js -> go: ${ size } bytes ` , ( done ) => {
137
+ it ( `js -> go: ${ pretty ( size ) } ` , ( done ) => {
124
138
const data = crypto . randomBytes ( size )
125
139
waterfall ( [
126
140
( cb ) => jsDaemon . api . add ( data , cb ) ,
@@ -133,7 +147,7 @@ describe('basic', () => {
133
147
} )
134
148
} )
135
149
136
- it ( `js -> js: ${ size } bytes ` , ( done ) => {
150
+ it ( `js -> js: ${ pretty ( size ) } ` , ( done ) => {
137
151
const data = crypto . randomBytes ( size )
138
152
waterfall ( [
139
153
( cb ) => js2Daemon . api . add ( data , cb ) ,
@@ -146,4 +160,57 @@ describe('basic', () => {
146
160
} )
147
161
} )
148
162
} ) )
163
+
164
+ describe ( 'get directory' , ( ) => dirs . forEach ( ( num ) => {
165
+ it ( `go -> js: depth: 5, num: ${ num } ` , ( ) => {
166
+ const dir = tmpDir ( )
167
+ return randomFs ( {
168
+ path : dir ,
169
+ depth : 5 ,
170
+ number : num
171
+ } ) . then ( ( ) => {
172
+ return goDaemon . api . util . addFromFs ( dir , { recursive : true } )
173
+ } ) . then ( ( res ) => {
174
+ const hash = res [ res . length - 1 ] . hash
175
+ return jsDaemon . api . object . get ( hash )
176
+ } ) . then ( ( res ) => {
177
+ expect ( res ) . to . exist
178
+ return rmDir ( dir )
179
+ } )
180
+ } )
181
+
182
+ it ( `js -> go: depth: 5, num: ${ num } ` , ( ) => {
183
+ const dir = tmpDir ( )
184
+ return randomFs ( {
185
+ path : dir ,
186
+ depth : 5 ,
187
+ number : num
188
+ } ) . then ( ( ) => {
189
+ return jsDaemon . api . util . addFromFs ( dir , { recursive : true } )
190
+ } ) . then ( ( res ) => {
191
+ const hash = res [ res . length - 1 ] . hash
192
+ return goDaemon . api . object . get ( hash )
193
+ } ) . then ( ( res ) => {
194
+ expect ( res ) . to . exist
195
+ return rmDir ( dir )
196
+ } )
197
+ } )
198
+
199
+ it ( `js -> js: depth: 5, num: ${ num } ` , ( ) => {
200
+ const dir = tmpDir ( )
201
+ return randomFs ( {
202
+ path : dir ,
203
+ depth : 5 ,
204
+ number : num
205
+ } ) . then ( ( ) => {
206
+ return js2Daemon . api . util . addFromFs ( dir , { recursive : true } )
207
+ } ) . then ( ( res ) => {
208
+ const hash = res [ res . length - 1 ] . hash
209
+ return jsDaemon . api . object . get ( hash )
210
+ } ) . then ( ( res ) => {
211
+ expect ( res ) . to . exist
212
+ return rmDir ( dir )
213
+ } )
214
+ } )
215
+ } ) )
149
216
} )
0 commit comments