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

Commit 42952a4

Browse files
committed
cat interface-core
1 parent 4a7991f commit 42952a4

File tree

1 file changed

+10
-72
lines changed

1 file changed

+10
-72
lines changed

test/api/cat.spec.js

Lines changed: 10 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,17 @@
11
/* eslint-env mocha */
22
/* globals apiClients */
3-
'use strict'
4-
5-
const expect = require('chai').expect
6-
const isNode = require('detect-node')
7-
const fs = require('fs')
83

9-
const path = require('path')
10-
const streamEqual = require('stream-equal')
4+
'use strict'
115

12-
let testfile
13-
let testfileBig
6+
const test = require('interface-ipfs-core')
147

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+
}
2015
}
2116

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

Comments
 (0)