|
1 | 1 | /* eslint-env mocha */
|
2 | 2 | /* globals apiClients */
|
3 |
| -'use strict' |
4 |
| - |
5 |
| -const expect = require('chai').expect |
6 |
| -const isNode = require('detect-node') |
7 |
| -const fs = require('fs') |
8 | 3 |
|
9 |
| -const path = require('path') |
10 |
| -const streamEqual = require('stream-equal') |
| 4 | +'use strict' |
11 | 5 |
|
12 |
| -let testfile |
13 |
| -let testfileBig |
| 6 | +const test = require('interface-ipfs-core') |
14 | 7 |
|
15 |
| -if (isNode) { |
16 |
| - testfile = fs.readFileSync(path.join(__dirname, '/../testfile.txt')) |
17 |
| - testfileBig = fs.createReadStream(path.join(__dirname, '/../15mb.random'), { bufferSize: 128 }) |
18 |
| -} else { |
19 |
| - testfile = require('raw!../testfile.txt') |
| 8 | +const common = { |
| 9 | + setup: function (cb) { |
| 10 | + cb(null, apiClients.a) |
| 11 | + }, |
| 12 | + teardown: function (cb) { |
| 13 | + cb() |
| 14 | + } |
20 | 15 | }
|
21 | 16 |
|
22 |
| -describe('.cat', () => { |
23 |
| - it('cat', (done) => { |
24 |
| - apiClients.a |
25 |
| - .cat('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP', (err, res) => { |
26 |
| - expect(err).to.not.exist |
27 |
| - |
28 |
| - let buf = '' |
29 |
| - res |
30 |
| - .on('error', (err) => { |
31 |
| - expect(err).to.not.exist |
32 |
| - }) |
33 |
| - .on('data', (data) => { |
34 |
| - buf += data |
35 |
| - }) |
36 |
| - .on('end', () => { |
37 |
| - expect(buf).to.be.equal(testfile.toString()) |
38 |
| - done() |
39 |
| - }) |
40 |
| - }) |
41 |
| - }) |
42 |
| - |
43 |
| - it('cat BIG file', (done) => { |
44 |
| - if (!isNode) { |
45 |
| - return done() |
46 |
| - } |
47 |
| - |
48 |
| - apiClients.a.cat('Qme79tX2bViL26vNjPsF3DP1R9rMKMvnPYJiKTTKPrXJjq', (err, res) => { |
49 |
| - expect(err).to.not.exist |
50 |
| - |
51 |
| - // Do not blow out the memory of nodejs :) |
52 |
| - streamEqual(res, testfileBig, (err, equal) => { |
53 |
| - expect(err).to.not.exist |
54 |
| - expect(equal).to.be.true |
55 |
| - done() |
56 |
| - }) |
57 |
| - }) |
58 |
| - }) |
59 |
| - |
60 |
| - describe('promise', () => { |
61 |
| - it('cat', (done) => { |
62 |
| - return apiClients.a.cat('Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP') |
63 |
| - .then((res) => { |
64 |
| - let buf = '' |
65 |
| - res |
66 |
| - .on('error', (err) => { |
67 |
| - throw err |
68 |
| - }) |
69 |
| - .on('data', (data) => { |
70 |
| - buf += data |
71 |
| - }) |
72 |
| - .on('end', () => { |
73 |
| - expect(buf).to.be.equal(testfile.toString()) |
74 |
| - done() |
75 |
| - }) |
76 |
| - }) |
77 |
| - }) |
78 |
| - }) |
79 |
| -}) |
| 17 | +test.files(common) |
0 commit comments