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

Commit fcd7143

Browse files
committed
fix(block): tests
1 parent 4333c2e commit fcd7143

File tree

3 files changed

+62
-65
lines changed

3 files changed

+62
-65
lines changed

API/block/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Where `block` can be:
4040
- `Buffer` - the raw bytes of the Block
4141
- [`Block`][block] instance
4242

43-
`callback` has the signature `function (err) {}`, where `err` is an error if the operation was not successful.
43+
`callback` has the signature `function (err, block) {}`, where `err` is an error if the operation was not successful and `block` is a [Block][block] type object, containing both the data and the hash of the block.
4444

4545
If no `callback` is passed, a promise is returned.
4646

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "interface-ipfs-core",
33
"version": "0.11.0",
44
"description": "A test suite and interface you can use to implement a IPFS core interface.",
5-
"main": "lib/index.js",
5+
"main": "src/index.js",
66
"jsnext:main": "src/index.js",
77
"scripts": {
88
"test": "exit(0)",
@@ -47,4 +47,4 @@
4747
"greenkeeperio-bot <support@greenkeeper.io>",
4848
"nginnever <ginneversource@gmail.com>"
4949
]
50-
}
50+
}

src/block.js

Lines changed: 59 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,84 @@
11
/* eslint-env mocha */
2-
/* globals apiClients */
2+
/* eslint max-nested-callbacks: ["error", 8] */
3+
34
'use strict'
45

56
const expect = require('chai').expect
67

78
module.exports = (common) => {
8-
describe.only('.block', () => {
9-
const blorbKey = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
10-
const blorb = Buffer('blorb')
11-
12-
it('returns an error when putting an array of files', () => {
13-
return apiClients.a.block.put([blorb, blorb], (err) => {
14-
console.log(err)
15-
expect(err).to.be.an.instanceof(Error)
16-
})
17-
})
9+
describe('.block', () => {
10+
let ipfs
1811

19-
it('block.put', (done) => {
20-
apiClients.a.block.put(blorb, (err, res) => {
21-
expect(err).to.not.exist
22-
expect(res).to.have.a.property('Key', 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ')
23-
done()
24-
})
25-
})
12+
before(function (done) {
13+
// CI takes longer to instantiate the daemon,
14+
// so we need to increase the timeout for the
15+
// before step
16+
this.timeout(20 * 1000)
2617

27-
it('block.get', (done) => {
28-
apiClients.a.block.get(blorbKey, (err, res) => {
18+
common.setup((err, factory) => {
2919
expect(err).to.not.exist
30-
31-
let buf = ''
32-
res
33-
.on('data', function (data) { buf += data })
34-
.on('end', function () {
35-
expect(buf).to.be.equal('blorb')
36-
done()
37-
})
20+
factory.spawnNode((err, node) => {
21+
expect(err).to.not.exist
22+
ipfs = node
23+
done()
24+
})
3825
})
3926
})
4027

41-
it('block.stat', (done) => {
42-
apiClients.a.block.stat(blorbKey, (err, res) => {
43-
expect(err).to.not.exist
44-
expect(res).to.have.property('Key')
45-
expect(res).to.have.property('Size')
46-
done()
47-
})
28+
after((done) => {
29+
common.teardown(done)
4830
})
4931

50-
describe('promise', () => {
51-
it('returns an error when putting an array of files', () => {
52-
return apiClients.a.block.put([blorb, blorb])
53-
.catch((err) => {
54-
expect(err).to.be.an.instanceof(Error)
55-
})
32+
describe('callback API', () => {
33+
it('.put', (done) => {
34+
const expectedHash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
35+
const blob = Buffer('blorb')
36+
37+
ipfs.block.put(blob, (err, res) => {
38+
expect(err).to.not.exist
39+
expect(res).to.have.a.property('Key', expectedHash)
40+
done()
41+
})
5642
})
5743

58-
it('block.put', () => {
59-
return apiClients.a.block.put(blorb)
60-
.then((res) => {
61-
expect(res).to.have.a.property('Key', 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ')
62-
})
44+
it('.put error with array of blocks', () => {
45+
const blob = Buffer('blorb')
46+
47+
return ipfs.block.put([blob, blob], (err) => {
48+
expect(err).to.be.an.instanceof(Error)
49+
})
6350
})
6451

6552
it('block.get', (done) => {
66-
return apiClients.a.block.get(blorbKey)
67-
.then((res) => {
68-
let buf = ''
69-
res
70-
.on('data', function (data) { buf += data })
71-
.on('end', function () {
72-
expect(buf).to.be.equal('blorb')
73-
done()
74-
})
75-
})
53+
const hash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
54+
55+
ipfs.block.get(hash, (err, res) => {
56+
expect(err).to.not.exist
57+
58+
// TODO review this
59+
let buf = ''
60+
res
61+
.on('data', function (data) { buf += data })
62+
.on('end', function () {
63+
expect(buf).to.be.equal('blorb')
64+
done()
65+
})
66+
})
7667
})
7768

78-
it('block.stat', () => {
79-
return apiClients.a.block.stat(blorbKey)
80-
.then((res) => {
81-
expect(res).to.have.property('Key')
82-
expect(res).to.have.property('Size')
83-
})
69+
it('block.stat', (done) => {
70+
const hash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
71+
72+
ipfs.block.stat(hash, (err, res) => {
73+
expect(err).to.not.exist
74+
expect(res).to.have.property('Key')
75+
expect(res).to.have.property('Size')
76+
done()
77+
})
8478
})
8579
})
80+
81+
describe('promise API', () => {
82+
})
8683
})
8784
}

0 commit comments

Comments
 (0)