22'use strict'
33
44const importer = require ( './../src' ) . importer
5+ const exporter = require ( './../src' ) . exporter
56
67const extend = require ( 'deep-extend' )
78const chai = require ( 'chai' )
@@ -542,10 +543,23 @@ module.exports = (repo) => {
542543 path = path [ path . length - 1 ] === '/' ? path : path + '/'
543544 return {
544545 path : path + name + '.txt' ,
545- content : Buffer . alloc ( 262144 + 5 ) . fill ( 1 )
546+ content : Buffer . alloc ( size ) . fill ( 1 )
546547 }
547548 }
548549
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+
549563 const options = {
550564 cidVersion : 1 ,
551565 // Ensures we use DirSharded for the data below
@@ -560,23 +574,34 @@ module.exports = (repo) => {
560574
561575 each ( files , ( file , cb ) => {
562576 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+ )
564599 } , done )
565600 }
566601
567602 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 ) ) ) ,
580605 importer ( ipld , options ) ,
581606 pull . collect ( onCollected )
582607 )
0 commit comments