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

Commit

Permalink
fix: use fixtures for refs tests (#471)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dirkmc authored and alanshaw committed May 16, 2019
1 parent 2456471 commit 3f30830
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/files-regular/refs-tests.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-env mocha */
'use strict'

const map = require('async/map')
const mapSeries = require('async/mapSeries')
const { getDescribe, getIt, expect } = require('../utils/mocha')
const loadFixture = require('aegir/fixtures')

module.exports = (createCommon, suiteName, ipfsRefs, options) => {
const describe = getDescribe(options)
Expand Down Expand Up @@ -125,20 +126,20 @@ function getMockObjects () {
return {
animals: {
land: {
'african.txt': ['elephant', 'rhinocerous'],
'americas.txt': ['ñandu', 'tapir'],
'australian.txt': ['emu', 'kangaroo']
'african.txt': loadFixture('test/fixtures/refs-test/animals/land/african.txt', 'interface-ipfs-core'),
'americas.txt': loadFixture('test/fixtures/refs-test/animals/land/americas.txt', 'interface-ipfs-core'),
'australian.txt': loadFixture('test/fixtures/refs-test/animals/land/australian.txt', 'interface-ipfs-core')
},
sea: {
'atlantic.txt': ['dolphin', 'whale'],
'indian.txt': ['cuttlefish', 'octopus']
'atlantic.txt': loadFixture('test/fixtures/refs-test/animals/sea/atlantic.txt', 'interface-ipfs-core'),
'indian.txt': loadFixture('test/fixtures/refs-test/animals/sea/indian.txt', 'interface-ipfs-core')
}
},
fruits: {
'tropical.txt': ['banana', 'pineapple']
'tropical.txt': loadFixture('test/fixtures/refs-test/fruits/tropical.txt', 'interface-ipfs-core')
},
'atlantic-animals': ['dolphin', 'whale'],
'mushroom.txt': ['mushroom']
'atlantic-animals': loadFixture('test/fixtures/refs-test/atlantic-animals', 'interface-ipfs-core'),
'mushroom.txt': loadFixture('test/fixtures/refs-test/mushroom.txt', 'interface-ipfs-core')
}
}

Expand Down Expand Up @@ -354,9 +355,9 @@ function loadPbContent (ipfs, node, callback) {
function loadDagContent (ipfs, node, callback) {
const store = {
putData: (data, cb) => {
ipfs.add(Buffer.from(data), (err, res) => {
ipfs.add(data, (err, res) => {
if (err) {
return callback(err)
return cb(err)
}
return cb(null, res[0].hash)
})
Expand All @@ -373,14 +374,14 @@ function loadDagContent (ipfs, node, callback) {
}

function loadContent (ipfs, store, node, callback) {
if (Array.isArray(node)) {
return store.putData(node.join('\n'), callback)
if (Buffer.isBuffer(node)) {
return store.putData(node, callback)
}

if (typeof node === 'object') {
const entries = Object.entries(node)
const sorted = entries.sort((a, b) => a[0] > b[0] ? 1 : a[0] < b[0] ? -1 : 0)
map(sorted, ([name, child], cb) => {
mapSeries(sorted, ([name, child], cb) => {
loadContent(ipfs, store, child, (err, cid) => {
cb(err, { name, cid: cid && cid.toString() })
})
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/refs-test/animals/land/african.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
elephant
rhinocerous
2 changes: 2 additions & 0 deletions test/fixtures/refs-test/animals/land/americas.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ñandu
tapir
2 changes: 2 additions & 0 deletions test/fixtures/refs-test/animals/land/australian.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
emu
kangaroo
2 changes: 2 additions & 0 deletions test/fixtures/refs-test/animals/sea/atlantic.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dolphin
whale
2 changes: 2 additions & 0 deletions test/fixtures/refs-test/animals/sea/indian.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cuttlefish
octopus
2 changes: 2 additions & 0 deletions test/fixtures/refs-test/atlantic-animals
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dolphin
whale
2 changes: 2 additions & 0 deletions test/fixtures/refs-test/fruits/tropical.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
banana
pineapple
1 change: 1 addition & 0 deletions test/fixtures/refs-test/mushroom.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mushroom

0 comments on commit 3f30830

Please sign in to comment.