Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 3f30830

Browse files
dirkmcAlan Shaw
authored and
Alan Shaw
committed
fix: use fixtures for refs tests (#471)
* fix: use fixtures for refs tests * fix: config set test * fix: refs tests load data callback * fix: use mapSeries when loading in refs tests * fix: skip failing test for now
1 parent 2456471 commit 3f30830

File tree

9 files changed

+30
-14
lines changed

9 files changed

+30
-14
lines changed

src/files-regular/refs-tests.js

+15-14
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/* eslint-env mocha */
22
'use strict'
33

4-
const map = require('async/map')
4+
const mapSeries = require('async/mapSeries')
55
const { getDescribe, getIt, expect } = require('../utils/mocha')
6+
const loadFixture = require('aegir/fixtures')
67

78
module.exports = (createCommon, suiteName, ipfsRefs, options) => {
89
const describe = getDescribe(options)
@@ -125,20 +126,20 @@ function getMockObjects () {
125126
return {
126127
animals: {
127128
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')
131132
},
132133
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')
135136
}
136137
},
137138
fruits: {
138-
'tropical.txt': ['banana', 'pineapple']
139+
'tropical.txt': loadFixture('test/fixtures/refs-test/fruits/tropical.txt', 'interface-ipfs-core')
139140
},
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')
142143
}
143144
}
144145

@@ -354,9 +355,9 @@ function loadPbContent (ipfs, node, callback) {
354355
function loadDagContent (ipfs, node, callback) {
355356
const store = {
356357
putData: (data, cb) => {
357-
ipfs.add(Buffer.from(data), (err, res) => {
358+
ipfs.add(data, (err, res) => {
358359
if (err) {
359-
return callback(err)
360+
return cb(err)
360361
}
361362
return cb(null, res[0].hash)
362363
})
@@ -373,14 +374,14 @@ function loadDagContent (ipfs, node, callback) {
373374
}
374375

375376
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)
378379
}
379380

380381
if (typeof node === 'object') {
381382
const entries = Object.entries(node)
382383
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) => {
384385
loadContent(ipfs, store, child, (err, cid) => {
385386
cb(err, { name, cid: cid && cid.toString() })
386387
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
elephant
2+
rhinocerous
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ñandu
2+
tapir
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
emu
2+
kangaroo
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dolphin
2+
whale
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cuttlefish
2+
octopus
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dolphin
2+
whale
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
banana
2+
pineapple

test/fixtures/refs-test/mushroom.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mushroom

0 commit comments

Comments
 (0)