1
1
/* eslint-env mocha */
2
2
'use strict'
3
3
4
- const map = require ( 'async/map ' )
4
+ const mapSeries = require ( 'async/mapSeries ' )
5
5
const { getDescribe, getIt, expect } = require ( '../utils/mocha' )
6
+ const loadFixture = require ( 'aegir/fixtures' )
6
7
7
8
module . exports = ( createCommon , suiteName , ipfsRefs , options ) => {
8
9
const describe = getDescribe ( options )
@@ -125,20 +126,20 @@ function getMockObjects () {
125
126
return {
126
127
animals : {
127
128
land : {
128
- 'african.txt' : [ 'elephant ', 'rhinocerous' ] ,
129
- 'americas.txt' : [ 'ñandu ', 'tapir' ] ,
130
- 'australian.txt' : [ 'emu ', 'kangaroo' ]
129
+ 'african.txt' : loadFixture ( 'test/fixtures/refs-test/animals/land/african.txt ', 'interface-ipfs-core' ) ,
130
+ 'americas.txt' : loadFixture ( 'test/fixtures/refs-test/animals/land/americas.txt ', 'interface-ipfs-core' ) ,
131
+ 'australian.txt' : loadFixture ( 'test/fixtures/refs-test/animals/land/australian.txt ', 'interface-ipfs-core' )
131
132
} ,
132
133
sea : {
133
- 'atlantic.txt' : [ 'dolphin ', 'whale' ] ,
134
- 'indian.txt' : [ 'cuttlefish ', 'octopus' ]
134
+ 'atlantic.txt' : loadFixture ( 'test/fixtures/refs-test/animals/sea/atlantic.txt ', 'interface-ipfs-core' ) ,
135
+ 'indian.txt' : loadFixture ( 'test/fixtures/refs-test/animals/sea/indian.txt ', 'interface-ipfs-core' )
135
136
}
136
137
} ,
137
138
fruits : {
138
- 'tropical.txt' : [ 'banana ', 'pineapple' ]
139
+ 'tropical.txt' : loadFixture ( 'test/fixtures/refs-test/fruits/tropical.txt ', 'interface-ipfs-core' )
139
140
} ,
140
- 'atlantic-animals' : [ 'dolphin ', 'whale' ] ,
141
- 'mushroom.txt' : [ ' mushroom' ]
141
+ 'atlantic-animals' : loadFixture ( 'test/fixtures/refs-test/atlantic-animals ', 'interface-ipfs-core' ) ,
142
+ 'mushroom.txt' : loadFixture ( 'test/fixtures/refs-test/ mushroom.txt' , 'interface-ipfs-core' )
142
143
}
143
144
}
144
145
@@ -354,9 +355,9 @@ function loadPbContent (ipfs, node, callback) {
354
355
function loadDagContent ( ipfs , node , callback ) {
355
356
const store = {
356
357
putData : ( data , cb ) => {
357
- ipfs . add ( Buffer . from ( data ) , ( err , res ) => {
358
+ ipfs . add ( data , ( err , res ) => {
358
359
if ( err ) {
359
- return callback ( err )
360
+ return cb ( err )
360
361
}
361
362
return cb ( null , res [ 0 ] . hash )
362
363
} )
@@ -373,14 +374,14 @@ function loadDagContent (ipfs, node, callback) {
373
374
}
374
375
375
376
function loadContent ( ipfs , store , node , callback ) {
376
- if ( Array . isArray ( node ) ) {
377
- return store . putData ( node . join ( '\n' ) , callback )
377
+ if ( Buffer . isBuffer ( node ) ) {
378
+ return store . putData ( node , callback )
378
379
}
379
380
380
381
if ( typeof node === 'object' ) {
381
382
const entries = Object . entries ( node )
382
383
const sorted = entries . sort ( ( a , b ) => a [ 0 ] > b [ 0 ] ? 1 : a [ 0 ] < b [ 0 ] ? - 1 : 0 )
383
- map ( sorted , ( [ name , child ] , cb ) => {
384
+ mapSeries ( sorted , ( [ name , child ] , cb ) => {
384
385
loadContent ( ipfs , store , child , ( err , cid ) => {
385
386
cb ( err , { name, cid : cid && cid . toString ( ) } )
386
387
} )
0 commit comments