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

Commit 1d33e4a

Browse files
committed
feat(block): correct tests, update interface
1 parent dad7f81 commit 1d33e4a

File tree

3 files changed

+34
-21
lines changed

3 files changed

+34
-21
lines changed

API/block/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ If no `callback` is passed, a promise is returned.
6161

6262
```JavaScript
6363
{
64-
Key: 'QmPTkMuuL6PD8L2SwTwbcs1NPg14U8mRzerB1ZrrBrkSDD',
65-
Size: 10
64+
key: 'QmPTkMuuL6PD8L2SwTwbcs1NPg14U8mRzerB1ZrrBrkSDD',
65+
size: 10
6666
}
6767
```
6868

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "interface-ipfs-core",
33
"version": "0.13.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)",
@@ -33,7 +33,9 @@
3333
"chai": "^3.5.0",
3434
"concat-stream": "^1.5.1",
3535
"detect-node": "^2.0.3",
36+
"ipfs-block": "^0.3.0",
3637
"ipfs-merkle-dag": "^0.6.2",
38+
"multihashes": "^0.2.2",
3739
"readable-stream": "1.1.13",
3840
"run-series": "^1.1.4"
3941
},
@@ -48,4 +50,4 @@
4850
"greenkeeperio-bot <[email protected]>",
4951
"nginnever <[email protected]>"
5052
]
51-
}
53+
}

src/block.js

+28-17
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
'use strict'
55

66
const expect = require('chai').expect
7+
const Block = require('ipfs-block')
8+
const multihash = require('multihashes')
79

810
module.exports = (common) => {
9-
describe('.block', () => {
11+
describe.only('.block', () => {
1012
let ipfs
1113

1214
before(function (done) {
@@ -30,13 +32,26 @@ module.exports = (common) => {
3032
})
3133

3234
describe('callback API', () => {
33-
it('.put', (done) => {
35+
it('.put a buffer', (done) => {
3436
const expectedHash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
3537
const blob = Buffer('blorb')
3638

37-
ipfs.block.put(blob, (err, res) => {
39+
ipfs.block.put(blob, (err, block) => {
3840
expect(err).to.not.exist
39-
expect(res).to.have.a.property('Key', expectedHash)
41+
expect(block.key).to.eql(multihash.fromB58String(expectedHash))
42+
expect(block).to.have.a.property('data', blob)
43+
done()
44+
})
45+
})
46+
47+
it('.put a block', (done) => {
48+
const expectedHash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
49+
const blob = new Block(new Buffer('blorb'))
50+
51+
ipfs.block.put(blob, (err, block) => {
52+
expect(err).to.not.exist
53+
expect(block.key).to.eql(multihash.fromB58String(expectedHash))
54+
expect(block.data).to.eql(new Buffer('blorb'))
4055
done()
4156
})
4257
})
@@ -52,30 +67,26 @@ module.exports = (common) => {
5267
it('block.get', (done) => {
5368
const hash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
5469

55-
ipfs.block.get(hash, (err, res) => {
70+
ipfs.block.get(hash, (err, block) => {
5671
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-
})
72+
expect(block.key).to.eql(multihash.fromB58String(hash))
73+
expect(block.data).to.eql(new Buffer('blorb'))
74+
done()
6675
})
6776
})
6877

6978
it('block.stat', (done) => {
7079
const hash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
7180

72-
ipfs.block.stat(hash, (err, res) => {
81+
ipfs.block.stat(hash, (err, stats) => {
7382
expect(err).to.not.exist
74-
expect(res).to.have.property('Key')
75-
expect(res).to.have.property('Size')
83+
expect(stats).to.have.property('key')
84+
expect(stats).to.have.property('size')
7685
done()
7786
})
7887
})
88+
89+
it.skip('block.rm', (done) => {}) // TODO once block.rm is shipped in go-ipfs
7990
})
8091

8192
describe('promise API', () => {

0 commit comments

Comments
 (0)