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

Make block API spec and tests coherent. #64

Merged
merged 1 commit into from
Aug 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions API/block/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ If no `callback` is passed, a promise is returned.

```JavaScript
{
Key: 'QmPTkMuuL6PD8L2SwTwbcs1NPg14U8mRzerB1ZrrBrkSDD',
Size: 10
key: 'QmPTkMuuL6PD8L2SwTwbcs1NPg14U8mRzerB1ZrrBrkSDD',
size: 10
}
```

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
"chai": "^3.5.0",
"concat-stream": "^1.5.1",
"detect-node": "^2.0.3",
"ipfs-block": "^0.3.0",
"ipfs-merkle-dag": "^0.6.2",
"multihashes": "^0.2.2",
"readable-stream": "1.1.13",
"run-series": "^1.1.4"
},
Expand All @@ -48,4 +50,4 @@
"greenkeeperio-bot <support@greenkeeper.io>",
"nginnever <ginneversource@gmail.com>"
]
}
}
43 changes: 27 additions & 16 deletions src/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
'use strict'

const expect = require('chai').expect
const Block = require('ipfs-block')
const multihash = require('multihashes')

module.exports = (common) => {
describe('.block', () => {
Expand All @@ -30,13 +32,26 @@ module.exports = (common) => {
})

describe('callback API', () => {
it('.put', (done) => {
it('.put a buffer', (done) => {
const expectedHash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
const blob = Buffer('blorb')

ipfs.block.put(blob, (err, res) => {
ipfs.block.put(blob, (err, block) => {
expect(err).to.not.exist
expect(res).to.have.a.property('Key', expectedHash)
expect(block.key).to.eql(multihash.fromB58String(expectedHash))
expect(block).to.have.a.property('data', blob)
done()
})
})

it('.put a block', (done) => {
const expectedHash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'
const blob = new Block(new Buffer('blorb'))

ipfs.block.put(blob, (err, block) => {
expect(err).to.not.exist
expect(block.key).to.eql(multihash.fromB58String(expectedHash))
expect(block.data).to.eql(new Buffer('blorb'))
done()
})
})
Expand All @@ -52,30 +67,26 @@ module.exports = (common) => {
it('block.get', (done) => {
const hash = 'QmPv52ekjS75L4JmHpXVeuJ5uX2ecSfSZo88NSyxwA3rAQ'

ipfs.block.get(hash, (err, res) => {
ipfs.block.get(hash, (err, block) => {
expect(err).to.not.exist

// TODO review this
let buf = ''
res
.on('data', function (data) { buf += data })
.on('end', function () {
expect(buf).to.be.equal('blorb')
done()
})
expect(block.key).to.eql(multihash.fromB58String(hash))
expect(block.data).to.eql(new Buffer('blorb'))
done()
})
})

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

ipfs.block.stat(hash, (err, res) => {
ipfs.block.stat(hash, (err, stats) => {
expect(err).to.not.exist
expect(res).to.have.property('Key')
expect(res).to.have.property('Size')
expect(stats).to.have.property('key')
expect(stats).to.have.property('size')
done()
})
})

it.skip('block.rm', (done) => {}) // TODO once block.rm is shipped in go-ipfs
})

describe('promise API', () => {
Expand Down