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

test: refactor tests #193

Merged
merged 3 commits into from
Nov 8, 2017
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@
"dirty-chai": "^2.0.1",
"ipfs": "~0.26.0",
"ipfs-block-service": "~0.13.0",
"ipfs-repo": "~0.18.2",
"ipfs-repo": "~0.18.3",
"ncp": "^2.0.0",
"pre-commit": "^1.2.2",
"pull-generate": "^2.2.0",
"pull-zip": "^2.0.1",
"rimraf": "^2.6.2",
"sinon": "^4.1.1",
"sinon": "^4.1.2",
"split": "^1.0.1"
},
"dependencies": {
Expand Down
50 changes: 31 additions & 19 deletions test/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,35 @@ describe('IPFS data importing tests on the Browser', function () {
], done)
})

require('./test-builder')(repo)
require('./test-flat-builder')
require('./test-balanced-builder')
require('./test-trickle-builder')
require('./test-fixed-size-chunker')

// relies on data in the repo
// require('./test-exporter')(repo)

require('./test-consumable-buffer')
require('./test-consumable-hash')
require('./test-hamt')
require('./test-importer')(repo)
require('./test-importer-flush')(repo)
require('./test-import-export')(repo)
require('./test-hash-parity-with-go-ipfs')(repo)
require('./test-nested-dir-import-export')(repo)
require('./test-dirbuilder-sharding')(repo)
require('./test-builder-only-hash')(repo)
// HAMT
require('./hamt')
require('./hamt-consumable-buffer')
require('./hamt-consumable-hash')

// Chunkers
require('./chunker-fixed-size')

// Graph Builders
require('./builder')(repo)
require('./builder-flat')
require('./builder-balanced')
require('./builder-trickle-dag')
require('./builder-only-hash')(repo)
// TODO: make these tests not require data on the repo
// require('./builder-dir-sharding')(repo)

// Importer
require('./importer')(repo)
require('./importer-flush')(repo)

// Exporter
// TODO: make these tests not require data on the repo
// require('./exporter')(repo)
// require('./exporter-subtree')(repo)

// Other
require('./import-export')(repo)
require('./import-export-nested-dir')(repo)
require('./hash-parity-with-go-ipfs')(repo)
// require('./with-dag-api')
})
2 changes: 1 addition & 1 deletion test/test-balanced-builder.js → test/builder-balanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const options = {
maxChildrenPerNode: 3
}

describe('balanced builder', () => {
describe('builder: balanced', () => {
it('reduces one value into itself', (callback) => {
pull(
pull.values([1]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const setImmediate = require('async/setImmediate')
const leftPad = require('left-pad')

module.exports = (repo) => {
describe('dirbuilder sharding', function () {
describe('builder: directory sharding', function () {
this.timeout(20 * 1000)

let ipldResolver
Expand Down
6 changes: 2 additions & 4 deletions test/test-flat-builder.js → test/builder-flat.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function reduce (leaves, callback) {
}
}

describe('flat builder', () => {
describe('builder: flat', () => {
it('reduces one value into itself', (callback) => {
pull(
pull.values([1]),
Expand All @@ -35,9 +35,7 @@ describe('flat builder', () => {
builder(reduce),
pull.collect((err, result) => {
expect(err).to.not.exist()
expect(result).to.be.eql([{
children: [1, 2]
}])
expect(result).to.eql([{ children: [1, 2] }])
callback()
})
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const createBuilder = require('../src/builder')
const FixedSizeChunker = require('../src/chunker/fixed-size')

module.exports = (repo) => {
describe('builder', () => {
describe('builder: onlyHash', () => {
let ipldResolver

before(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const options = {
layerRepeat: 2
}

describe('trickle builder', () => {
describe('builder: trickle', () => {
it('reduces one value into itself', callback => {
pull(
pull.values([1]),
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ describe('chunker: fixed size', () => {

it('256 KiB chunks', (done) => {
const KiB256 = 262144

pull(
pull.values(rawFile),
chunker(KiB256),
Expand Down Expand Up @@ -88,7 +89,7 @@ describe('chunker: fixed size', () => {
}
})

expect(counter).to.be.eql(1)
expect(counter).to.equal(1)
done()
})
)
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const expect = require('chai').expect

const ConsumableBuffer = require('../src/hamt/consumable-buffer')

describe('consumable buffer', () => {
describe('HAMT: consumable buffer', () => {
let buf

it('can create an empty one', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const whilst = require('async/whilst')

const ConsumableHash = require('../src/hamt/consumable-hash')

describe('consumable hash', () => {
describe('HAMT: consumable hash', () => {
let hash, h
const maxIter = 100
const values = []
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = (repo) => {
strategy: strategy
}

describe(strategy + ' importer', () => {
describe('go-ipfs interop using importer:' + strategy, () => {
let ipldResolver

before(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const map = require('async/map')
const unixFSEngine = require('./../')

module.exports = (repo) => {
describe('import adn export big nested dir', () => {
describe('import and export: directory', () => {
const rootHash = 'QmdCrquDwd7RfZ6GCZFEVADwe8uyyw1YmF9mtAB7etDgmK'
let ipldResolver

Expand Down
69 changes: 69 additions & 0 deletions test/import-export.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* eslint-env mocha */
'use strict'

const chai = require('chai')
chai.use(require('dirty-chai'))
const expect = chai.expect
const BlockService = require('ipfs-block-service')
const IPLDResolver = require('ipld-resolver')
const pull = require('pull-stream')
const loadFixture = require('aegir/fixtures')
const bigFile = loadFixture(__dirname, 'fixtures/1.2MiB.txt')

const unixFSEngine = require('./../')
const exporter = unixFSEngine.exporter

const strategies = [
'flat',
'balanced',
'trickle'
]

function fileEql (f1, fileData, callback) {
pull(
f1.content,
pull.concat((err, data) => {
expect(err).to.not.exist()
// TODO: eql is super slow at comparing large buffers
// expect(data).to.eql(fileData)
callback()
})
)
}

module.exports = (repo) => {
describe('import and export', () => {
strategies.forEach((strategy) => {
const importerOptions = { strategy: strategy }

describe('using builder: ' + strategy, () => {
let ipldResolver

before(() => {
const bs = new BlockService(repo)
ipldResolver = new IPLDResolver(bs)
})

it('import and export', (done) => {
const path = strategy + '-big.dat'

pull(
pull.values([{ path: path, content: pull.values(bigFile) }]),
unixFSEngine.importer(ipldResolver, importerOptions),
pull.map((file) => {
expect(file.path).to.eql(path)

return exporter(file.multihash, ipldResolver)
}),
pull.flatten(),
pull.collect((err, files) => {
expect(err).to.not.exist()
expect(files[0].size).to.eql(bigFile.length)
fileEql(files[0], bigFile, done)
})
)
})
})
})
})
}
2 changes: 1 addition & 1 deletion test/test-importer-flush.js → test/importer-flush.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const pull = require('pull-stream')
const pushable = require('pull-pushable')

module.exports = (repo) => {
describe('importer flush', () => {
describe('importer: flush', () => {
let ipldResolver

before(() => {
Expand Down
2 changes: 1 addition & 1 deletion test/test-importer.js → test/importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ module.exports = (repo) => {

const expected = extend({}, defaultResults, strategies[strategy])

describe(strategy + ' importer', function () {
describe('importer: ' + strategy, function () {
this.timeout(20 * 1000)

let ipldResolver
Expand Down
50 changes: 31 additions & 19 deletions test/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
const ncp = require('ncp').ncp
const rimraf = require('rimraf')
const path = require('path')
const os = require('os')
const IPFSRepo = require('ipfs-repo')
const mkdirp = require('mkdirp')
const series = require('async/series')

describe('IPFS UnixFS Engine', () => {
const repoExample = path.join(process.cwd(), '/test/test-repo')
const repoTests = path.join(process.cwd(), '/test/repo-tests' + Date.now())
const repoTests = path.join(os.tmpdir(), '/unixfs-tests-' + Date.now())

const repo = new IPFSRepo(repoTests)

Expand All @@ -36,22 +37,33 @@ describe('IPFS UnixFS Engine', () => {
], done)
})

require('./test-builder')(repo)
require('./test-flat-builder')
require('./test-balanced-builder')
require('./test-trickle-builder')
require('./test-fixed-size-chunker')
require('./test-consumable-buffer')
require('./test-consumable-hash')
require('./test-hamt')
require('./test-exporter')(repo)
require('./test-export-subtree')(repo)
require('./test-importer')(repo)
require('./test-importer-flush')(repo)
require('./test-import-export')(repo)
require('./test-hash-parity-with-go-ipfs')(repo)
require('./test-nested-dir-import-export')(repo)
require('./test-dirbuilder-sharding')(repo)
require('./test-dag-api')
require('./test-builder-only-hash')(repo)
// HAMT
require('./hamt')
require('./hamt-consumable-buffer')
require('./hamt-consumable-hash')

// Chunkers
require('./chunker-fixed-size')

// Graph Builders
require('./builder')(repo)
require('./builder-flat')
require('./builder-balanced')
require('./builder-trickle-dag')
require('./builder-only-hash')(repo)
require('./builder-dir-sharding')(repo)

// Importer
require('./importer')(repo)
require('./importer-flush')(repo)

// Exporter
require('./exporter')(repo)
require('./exporter-subtree')(repo)

// Other
require('./import-export')(repo)
require('./import-export-nested-dir')(repo)
require('./hash-parity-with-go-ipfs')(repo)
require('./with-dag-api')
})
Loading