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

Commit 7c935c4

Browse files
committed
create file.js test file
1 parent 42952a4 commit 7c935c4

File tree

3 files changed

+90
-10
lines changed

3 files changed

+90
-10
lines changed

src/api/files.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const argCommand = require('../cmd-helpers').argCommand
44

55
module.exports = (send) => {
66
return {
7+
cat: argCommand(send, 'cat'),
78
cp: argCommand(send, 'files/cp'),
89
ls: argCommand(send, 'files/ls'),
910
mkdir: argCommand(send, 'files/mkdir'),

test/api/cat.spec.js

Lines changed: 72 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,79 @@
11
/* eslint-env mocha */
22
/* globals apiClients */
3-
43
'use strict'
54

6-
const test = require('interface-ipfs-core')
5+
const expect = require('chai').expect
6+
const isNode = require('detect-node')
7+
const fs = require('fs')
8+
9+
const path = require('path')
10+
const streamEqual = require('stream-equal')
711

8-
const common = {
9-
setup: function (cb) {
10-
cb(null, apiClients.a)
11-
},
12-
teardown: function (cb) {
13-
cb()
14-
}
12+
let testfile
13+
let testfileBig
14+
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')
1520
}
1621

17-
test.files(common)
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+
})

test/api/file.spec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* eslint-env mocha */
2+
/* globals apiClients */
3+
4+
'use strict'
5+
6+
const test = require('interface-ipfs-core')
7+
8+
const common = {
9+
setup: function (cb) {
10+
cb(null, apiClients.a)
11+
},
12+
teardown: function (cb) {
13+
cb()
14+
}
15+
}
16+
17+
test.files(common)

0 commit comments

Comments
 (0)