|
1 | 1 | /* eslint-env mocha */
|
2 |
| -'use strict' |
3 |
| - |
4 |
| -const expect = require('chai').expect |
5 |
| -const base58 = require('bs58') |
6 |
| -const fs = require('fs') |
7 |
| -const IPFS = require('../../../src/core') |
8 |
| -const Block = require('ipfs-block') |
9 |
| -const path = require('path') |
10 |
| - |
11 |
| -const isNode = require('detect-node') |
12 | 2 |
|
13 |
| -const fileA = isNode |
14 |
| - ? fs.readFileSync(path.join(__dirname, '../../go-ipfs-repo/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data')) |
15 |
| - : require('buffer!./../../go-ipfs-repo/blocks/12207028/122070286b9afa6620a66f715c7020d68af3d10e1a497971629c07606bfdb812303d.data') |
16 |
| - |
17 |
| -// TODO use arrow funtions again when https://github.com/webpack/webpack/issues/1944 is fixed |
18 |
| -describe('block', function () { |
19 |
| - var ipfs |
20 |
| - |
21 |
| - before((done) => { |
22 |
| - ipfs = new IPFS(require('../../utils/repo-path')) |
23 |
| - ipfs.load(done) |
24 |
| - }) |
| 3 | +'use strict' |
25 | 4 |
|
26 |
| - it('get', function (done) { |
27 |
| - const b58mh = 'QmVtU7ths96fMgZ8YSZAbKghyieq7AjxNdcqyVzxTt3qVe' |
28 |
| - const mh = new Buffer(base58.decode(b58mh)) |
29 |
| - ipfs.block.get(mh, (err, block) => { |
30 |
| - expect(err).to.not.exist |
31 |
| - const eq = fileA.equals(block.data) |
32 |
| - expect(eq).to.equal(true) |
33 |
| - done() |
34 |
| - }) |
35 |
| - }) |
| 5 | +const test = require('interface-ipfs-core') |
| 6 | +const IPFSFactory = require('../../utils/factory-core') |
36 | 7 |
|
37 |
| - it('put', (done) => { |
38 |
| - var b = new Block('random data') |
39 |
| - ipfs.block.put(b, function (err) { |
40 |
| - expect(err).to.not.exist |
41 |
| - ipfs.block.get(b.key, function (err, block) { |
42 |
| - expect(err).to.not.exist |
43 |
| - expect(b.data.equals(block.data)).to.equal(true) |
44 |
| - expect(b.key.equals(block.key)).to.equal(true) |
45 |
| - done() |
46 |
| - }) |
47 |
| - }) |
48 |
| - }) |
| 8 | +let factory |
49 | 9 |
|
50 |
| - it('rm', (done) => { |
51 |
| - var b = new Block('I will not last long enough') |
52 |
| - ipfs.block.put(b, function (err) { |
53 |
| - expect(err).to.not.exist |
54 |
| - ipfs.block.get(b.key, function (err, block) { |
55 |
| - expect(err).to.not.exist |
56 |
| - ipfs.block.del(b.key, function (err) { |
57 |
| - expect(err).to.not.exist |
58 |
| - ipfs.block.get(b.key, function (err, block) { |
59 |
| - expect(err).to.exist |
60 |
| - done() |
61 |
| - }) |
62 |
| - }) |
63 |
| - }) |
64 |
| - }) |
65 |
| - }) |
| 10 | +const common = { |
| 11 | + setup: function (cb) { |
| 12 | + factory = new IPFSFactory() |
| 13 | + cb(null, factory) |
| 14 | + }, |
| 15 | + teardown: function (cb) { |
| 16 | + factory.dismantle(cb) |
| 17 | + } |
| 18 | +} |
66 | 19 |
|
67 |
| - it('stat', function (done) { |
68 |
| - const mh = new Buffer(base58 |
69 |
| - .decode('QmVtU7ths96fMgZ8YSZAbKghyieq7AjxNdcqyVzxTt3qVe')) |
70 |
| - ipfs.block.stat(mh, (err, stats) => { |
71 |
| - expect(err).to.not.exist |
72 |
| - expect(stats.Key.equals(mh)).to.equal(true) |
73 |
| - expect(stats.Size).to.equal(309) |
74 |
| - done() |
75 |
| - }) |
76 |
| - }) |
77 |
| -}) |
| 20 | +test.block(common) |
0 commit comments