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

Commit 657fdae

Browse files
authoredNov 8, 2017
test: refactor tests (#193)
* test: refactor tests * now yes * final touch
1 parent 72f4167 commit 657fdae

23 files changed

+149
-160
lines changed
 

‎package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@
4545
"dirty-chai": "^2.0.1",
4646
"ipfs": "~0.26.0",
4747
"ipfs-block-service": "~0.13.0",
48-
"ipfs-repo": "~0.18.2",
48+
"ipfs-repo": "~0.18.3",
4949
"ncp": "^2.0.0",
5050
"pre-commit": "^1.2.2",
5151
"pull-generate": "^2.2.0",
5252
"pull-zip": "^2.0.1",
5353
"rimraf": "^2.6.2",
54-
"sinon": "^4.1.1",
54+
"sinon": "^4.1.2",
5555
"split": "^1.0.1"
5656
},
5757
"dependencies": {

‎test/browser.js

+31-19
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,35 @@ describe('IPFS data importing tests on the Browser', function () {
3434
], done)
3535
})
3636

37-
require('./test-builder')(repo)
38-
require('./test-flat-builder')
39-
require('./test-balanced-builder')
40-
require('./test-trickle-builder')
41-
require('./test-fixed-size-chunker')
42-
43-
// relies on data in the repo
44-
// require('./test-exporter')(repo)
45-
46-
require('./test-consumable-buffer')
47-
require('./test-consumable-hash')
48-
require('./test-hamt')
49-
require('./test-importer')(repo)
50-
require('./test-importer-flush')(repo)
51-
require('./test-import-export')(repo)
52-
require('./test-hash-parity-with-go-ipfs')(repo)
53-
require('./test-nested-dir-import-export')(repo)
54-
require('./test-dirbuilder-sharding')(repo)
55-
require('./test-builder-only-hash')(repo)
37+
// HAMT
38+
require('./hamt')
39+
require('./hamt-consumable-buffer')
40+
require('./hamt-consumable-hash')
41+
42+
// Chunkers
43+
require('./chunker-fixed-size')
44+
45+
// Graph Builders
46+
require('./builder')(repo)
47+
require('./builder-flat')
48+
require('./builder-balanced')
49+
require('./builder-trickle-dag')
50+
require('./builder-only-hash')(repo)
51+
// TODO: make these tests not require data on the repo
52+
// require('./builder-dir-sharding')(repo)
53+
54+
// Importer
55+
require('./importer')(repo)
56+
require('./importer-flush')(repo)
57+
58+
// Exporter
59+
// TODO: make these tests not require data on the repo
60+
// require('./exporter')(repo)
61+
// require('./exporter-subtree')(repo)
62+
63+
// Other
64+
require('./import-export')(repo)
65+
require('./import-export-nested-dir')(repo)
66+
require('./hash-parity-with-go-ipfs')(repo)
67+
// require('./with-dag-api')
5668
})

‎test/test-balanced-builder.js renamed to ‎test/builder-balanced.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const options = {
2020
maxChildrenPerNode: 3
2121
}
2222

23-
describe('balanced builder', () => {
23+
describe('builder: balanced', () => {
2424
it('reduces one value into itself', (callback) => {
2525
pull(
2626
pull.values([1]),

‎test/test-dirbuilder-sharding.js renamed to ‎test/builder-dir-sharding.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const setImmediate = require('async/setImmediate')
1717
const leftPad = require('left-pad')
1818

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

2323
let ipldResolver

‎test/test-flat-builder.js renamed to ‎test/builder-flat.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function reduce (leaves, callback) {
1616
}
1717
}
1818

19-
describe('flat builder', () => {
19+
describe('builder: flat', () => {
2020
it('reduces one value into itself', (callback) => {
2121
pull(
2222
pull.values([1]),
@@ -35,9 +35,7 @@ describe('flat builder', () => {
3535
builder(reduce),
3636
pull.collect((err, result) => {
3737
expect(err).to.not.exist()
38-
expect(result).to.be.eql([{
39-
children: [1, 2]
40-
}])
38+
expect(result).to.eql([{ children: [1, 2] }])
4139
callback()
4240
})
4341
)

‎test/test-builder-only-hash.js renamed to ‎test/builder-only-hash.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const createBuilder = require('../src/builder')
1212
const FixedSizeChunker = require('../src/chunker/fixed-size')
1313

1414
module.exports = (repo) => {
15-
describe('builder', () => {
15+
describe('builder: onlyHash', () => {
1616
let ipldResolver
1717

1818
before(() => {

‎test/test-trickle-builder.js renamed to ‎test/builder-trickle-dag.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const options = {
2121
layerRepeat: 2
2222
}
2323

24-
describe('trickle builder', () => {
24+
describe('builder: trickle', () => {
2525
it('reduces one value into itself', callback => {
2626
pull(
2727
pull.values([1]),
File renamed without changes.

‎test/test-fixed-size-chunker.js renamed to ‎test/chunker-fixed-size.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ describe('chunker: fixed size', () => {
5252

5353
it('256 KiB chunks', (done) => {
5454
const KiB256 = 262144
55+
5556
pull(
5657
pull.values(rawFile),
5758
chunker(KiB256),
@@ -88,7 +89,7 @@ describe('chunker: fixed size', () => {
8889
}
8990
})
9091

91-
expect(counter).to.be.eql(1)
92+
expect(counter).to.equal(1)
9293
done()
9394
})
9495
)
File renamed without changes.
File renamed without changes.

‎test/test-consumable-buffer.js renamed to ‎test/hamt-consumable-buffer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const expect = require('chai').expect
55

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

8-
describe('consumable buffer', () => {
8+
describe('HAMT: consumable buffer', () => {
99
let buf
1010

1111
it('can create an empty one', () => {

‎test/test-consumable-hash.js renamed to ‎test/hamt-consumable-hash.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const whilst = require('async/whilst')
99

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

12-
describe('consumable hash', () => {
12+
describe('HAMT: consumable hash', () => {
1313
let hash, h
1414
const maxIter = 100
1515
const values = []
File renamed without changes.

‎test/test-hash-parity-with-go-ipfs.js renamed to ‎test/hash-parity-with-go-ipfs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module.exports = (repo) => {
3030
strategy: strategy
3131
}
3232

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

3636
before(() => {

‎test/test-nested-dir-import-export.js renamed to ‎test/import-export-nested-dir.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const map = require('async/map')
1313
const unixFSEngine = require('./../')
1414

1515
module.exports = (repo) => {
16-
describe('import adn export big nested dir', () => {
16+
describe('import and export: directory', () => {
1717
const rootHash = 'QmdCrquDwd7RfZ6GCZFEVADwe8uyyw1YmF9mtAB7etDgmK'
1818
let ipldResolver
1919

‎test/import-export.js

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/* eslint-env mocha */
2+
'use strict'
3+
4+
const chai = require('chai')
5+
chai.use(require('dirty-chai'))
6+
const expect = chai.expect
7+
const BlockService = require('ipfs-block-service')
8+
const IPLDResolver = require('ipld-resolver')
9+
const pull = require('pull-stream')
10+
const loadFixture = require('aegir/fixtures')
11+
const bigFile = loadFixture(__dirname, 'fixtures/1.2MiB.txt')
12+
13+
const unixFSEngine = require('./../')
14+
const exporter = unixFSEngine.exporter
15+
16+
const strategies = [
17+
'flat',
18+
'balanced',
19+
'trickle'
20+
]
21+
22+
function fileEql (f1, fileData, callback) {
23+
pull(
24+
f1.content,
25+
pull.concat((err, data) => {
26+
expect(err).to.not.exist()
27+
// TODO: eql is super slow at comparing large buffers
28+
// expect(data).to.eql(fileData)
29+
callback()
30+
})
31+
)
32+
}
33+
34+
module.exports = (repo) => {
35+
describe('import and export', () => {
36+
strategies.forEach((strategy) => {
37+
const importerOptions = { strategy: strategy }
38+
39+
describe('using builder: ' + strategy, () => {
40+
let ipldResolver
41+
42+
before(() => {
43+
const bs = new BlockService(repo)
44+
ipldResolver = new IPLDResolver(bs)
45+
})
46+
47+
it('import and export', (done) => {
48+
const path = strategy + '-big.dat'
49+
50+
pull(
51+
pull.values([{ path: path, content: pull.values(bigFile) }]),
52+
unixFSEngine.importer(ipldResolver, importerOptions),
53+
pull.map((file) => {
54+
expect(file.path).to.eql(path)
55+
56+
return exporter(file.multihash, ipldResolver)
57+
}),
58+
pull.flatten(),
59+
pull.collect((err, files) => {
60+
expect(err).to.not.exist()
61+
expect(files[0].size).to.eql(bigFile.length)
62+
fileEql(files[0], bigFile, done)
63+
})
64+
)
65+
})
66+
})
67+
})
68+
})
69+
}

‎test/test-importer-flush.js renamed to ‎test/importer-flush.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const pull = require('pull-stream')
1212
const pushable = require('pull-pushable')
1313

1414
module.exports = (repo) => {
15-
describe('importer flush', () => {
15+
describe('importer: flush', () => {
1616
let ipldResolver
1717

1818
before(() => {

‎test/test-importer.js renamed to ‎test/importer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ module.exports = (repo) => {
160160

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

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

166166
let ipldResolver

‎test/node.js

+31-19
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
const ncp = require('ncp').ncp
55
const rimraf = require('rimraf')
66
const path = require('path')
7+
const os = require('os')
78
const IPFSRepo = require('ipfs-repo')
89
const mkdirp = require('mkdirp')
910
const series = require('async/series')
1011

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

1516
const repo = new IPFSRepo(repoTests)
1617

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

39-
require('./test-builder')(repo)
40-
require('./test-flat-builder')
41-
require('./test-balanced-builder')
42-
require('./test-trickle-builder')
43-
require('./test-fixed-size-chunker')
44-
require('./test-consumable-buffer')
45-
require('./test-consumable-hash')
46-
require('./test-hamt')
47-
require('./test-exporter')(repo)
48-
require('./test-export-subtree')(repo)
49-
require('./test-importer')(repo)
50-
require('./test-importer-flush')(repo)
51-
require('./test-import-export')(repo)
52-
require('./test-hash-parity-with-go-ipfs')(repo)
53-
require('./test-nested-dir-import-export')(repo)
54-
require('./test-dirbuilder-sharding')(repo)
55-
require('./test-dag-api')
56-
require('./test-builder-only-hash')(repo)
40+
// HAMT
41+
require('./hamt')
42+
require('./hamt-consumable-buffer')
43+
require('./hamt-consumable-hash')
44+
45+
// Chunkers
46+
require('./chunker-fixed-size')
47+
48+
// Graph Builders
49+
require('./builder')(repo)
50+
require('./builder-flat')
51+
require('./builder-balanced')
52+
require('./builder-trickle-dag')
53+
require('./builder-only-hash')(repo)
54+
require('./builder-dir-sharding')(repo)
55+
56+
// Importer
57+
require('./importer')(repo)
58+
require('./importer-flush')(repo)
59+
60+
// Exporter
61+
require('./exporter')(repo)
62+
require('./exporter-subtree')(repo)
63+
64+
// Other
65+
require('./import-export')(repo)
66+
require('./import-export-nested-dir')(repo)
67+
require('./hash-parity-with-go-ipfs')(repo)
68+
require('./with-dag-api')
5769
})

‎test/test-import-export.js

-103
This file was deleted.

‎test/test-repo/version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5
1+
6

‎test/test-dag-api.js renamed to ‎test/with-dag-api.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ describe('with dag-api', () => {
158158

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

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

164164
let node

0 commit comments

Comments
 (0)
This repository has been archived.