2
2
'use strict'
3
3
4
4
const importer = require ( './../src' ) . importer
5
+ const exporter = require ( './../src' ) . exporter
5
6
6
7
const extend = require ( 'deep-extend' )
7
8
const chai = require ( 'chai' )
@@ -542,10 +543,23 @@ module.exports = (repo) => {
542
543
path = path [ path . length - 1 ] === '/' ? path : path + '/'
543
544
return {
544
545
path : path + name + '.txt' ,
545
- content : Buffer . alloc ( 262144 + 5 ) . fill ( 1 )
546
+ content : Buffer . alloc ( size ) . fill ( 1 )
546
547
}
547
548
}
548
549
550
+ const inputFiles = [
551
+ createInputFile ( '/foo' , 10 ) ,
552
+ createInputFile ( '/foo' , 60 ) ,
553
+ createInputFile ( '/foo/bar' , 78 ) ,
554
+ createInputFile ( '/foo/baz' , 200 ) ,
555
+ // Bigger than maxChunkSize
556
+ createInputFile ( '/foo' , 262144 + 45 ) ,
557
+ createInputFile ( '/foo/bar' , 262144 + 134 ) ,
558
+ createInputFile ( '/foo/bar' , 262144 + 79 ) ,
559
+ createInputFile ( '/foo/bar' , 262144 + 876 ) ,
560
+ createInputFile ( '/foo/bar' , 262144 + 21 )
561
+ ]
562
+
549
563
const options = {
550
564
cidVersion : 1 ,
551
565
// Ensures we use DirSharded for the data below
@@ -560,23 +574,34 @@ module.exports = (repo) => {
560
574
561
575
each ( files , ( file , cb ) => {
562
576
const cid = new CID ( file . multihash ) . toV1 ( )
563
- ipld . get ( cid , cb )
577
+ const inputFile = inputFiles . find ( f => f . path === file . path )
578
+
579
+ // Just check the intermediate directory can be retrieved
580
+ if ( ! inputFile ) {
581
+ return ipld . get ( cid , cb )
582
+ }
583
+
584
+ // Check the imported content is correct
585
+ pull (
586
+ exporter ( cid , ipld ) ,
587
+ pull . collect ( ( err , nodes ) => {
588
+ expect ( err ) . to . not . exist ( )
589
+ pull (
590
+ nodes [ 0 ] . content ,
591
+ pull . collect ( ( err , chunks ) => {
592
+ expect ( err ) . to . not . exist ( )
593
+ expect ( Buffer . concat ( chunks ) ) . to . deep . equal ( inputFile . content )
594
+ cb ( )
595
+ } )
596
+ )
597
+ } )
598
+ )
564
599
} , done )
565
600
}
566
601
567
602
pull (
568
- pull . values ( [
569
- createInputFile ( '/foo' , 10 ) ,
570
- createInputFile ( '/foo' , 60 ) ,
571
- createInputFile ( '/foo/bar' , 78 ) ,
572
- createInputFile ( '/foo/baz' , 200 ) ,
573
- // Bigger than maxChunkSize
574
- createInputFile ( '/foo' , 262144 + 45 ) ,
575
- createInputFile ( '/foo/bar' , 262144 + 134 ) ,
576
- createInputFile ( '/foo/bar' , 262144 + 79 ) ,
577
- createInputFile ( '/foo/bar' , 262144 + 876 ) ,
578
- createInputFile ( '/foo/bar' , 262144 + 21 )
579
- ] ) ,
603
+ // Pass a copy of inputFiles, since the importer mutates them
604
+ pull . values ( inputFiles . map ( f => Object . assign ( { } , f ) ) ) ,
580
605
importer ( ipld , options ) ,
581
606
pull . collect ( onCollected )
582
607
)
0 commit comments