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

Fix: use fixtures for refs tests #471

Merged
merged 5 commits into from
May 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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