@@ -7,6 +7,14 @@ const parallel = require('async/parallel')
77const waterfall = require ( 'async/waterfall' )
88const bl = require ( 'bl' )
99const 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
1018
1119const GoDaemon = require ( './daemons/go' )
1220const JsDaemon = require ( './daemons/js' )
@@ -19,12 +27,18 @@ const sizes = [
1927 1024 * 512 ,
2028 1024 * 768 ,
2129 1024 * 1023 ,
22- // starts failing with multiplex
2330 1024 * 1024 ,
2431 1024 * 1024 * 4 ,
2532 1024 * 1024 * 8
2633]
2734
35+ const dirs = [
36+ 5 ,
37+ 10 ,
38+ 50 ,
39+ 100
40+ ]
41+
2842describe ( 'basic' , ( ) => {
2943 let goDaemon
3044 let jsDaemon
@@ -107,7 +121,7 @@ describe('basic', () => {
107121 } )
108122
109123 describe ( 'cat file' , ( ) => sizes . forEach ( ( size ) => {
110- it ( `go -> js: ${ size } bytes ` , ( done ) => {
124+ it ( `go -> js: ${ pretty ( size ) } ` , ( done ) => {
111125 const data = crypto . randomBytes ( size )
112126 waterfall ( [
113127 ( cb ) => goDaemon . api . add ( data , cb ) ,
@@ -120,7 +134,7 @@ describe('basic', () => {
120134 } )
121135 } )
122136
123- it ( `js -> go: ${ size } bytes ` , ( done ) => {
137+ it ( `js -> go: ${ pretty ( size ) } ` , ( done ) => {
124138 const data = crypto . randomBytes ( size )
125139 waterfall ( [
126140 ( cb ) => jsDaemon . api . add ( data , cb ) ,
@@ -133,7 +147,7 @@ describe('basic', () => {
133147 } )
134148 } )
135149
136- it ( `js -> js: ${ size } bytes ` , ( done ) => {
150+ it ( `js -> js: ${ pretty ( size ) } ` , ( done ) => {
137151 const data = crypto . randomBytes ( size )
138152 waterfall ( [
139153 ( cb ) => js2Daemon . api . add ( data , cb ) ,
@@ -146,4 +160,57 @@ describe('basic', () => {
146160 } )
147161 } )
148162 } ) )
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+ } ) )
149216} )
0 commit comments