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

Commit

Permalink
round1 for new aegir
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Nov 3, 2016
1 parent 3a79b79 commit c90fdc2
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 36 deletions.
9 changes: 7 additions & 2 deletions API/block/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ block API

`multihash` is a [multihash][multihash] which can be passed as:

- Buffer, the raw Buffer of the multihash
- Buffer, the raw Buffer of the multihash
- String, the base58 encoded version of the multihash

`callback` must follow `function (err, block) {}` signature, 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.
Expand All @@ -21,7 +21,12 @@ ipfs.block.get(multihash, function (err, block) {
if (err) {
throw err
}
console.log(block.key, block.data)
block.key((err, key) => {
if (err) {
throw err
}
console.log(key, block.data)
})
})
```

Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
"name": "interface-ipfs-core",
"version": "0.16.2",
"description": "A test suite and interface you can use to implement a IPFS core interface.",
"main": "lib/index.js",
"jsnext:main": "src/index.js",
"main": "src/index.js",
"scripts": {
"test": "exit(0)",
"build": "aegir-build node",
"lint": "aegir-lint",
"release": "aegir-release node",
"release-minor": "aegir-release node --type minor",
Expand Down Expand Up @@ -40,7 +38,7 @@
"readable-stream": "1.1.13"
},
"devDependencies": {
"aegir": "^8.1.2"
"aegir": "^9.0.1"
},
"contributors": [
"David Dias <daviddias.p@gmail.com>",
Expand Down
28 changes: 17 additions & 11 deletions src/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ const Block = require('ipfs-block')
const multihash = require('multihashes')
const CID = require('cids')

function expectKey (block, expected, callback) {
block.key((err, key) => {
if (err) {
return callback(err)
}
expect(key).to.be.eql(expected)
callback()
})
}

module.exports = (common) => {
describe('.block', () => {
let ipfs
Expand Down Expand Up @@ -40,9 +50,8 @@ module.exports = (common) => {

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

Expand All @@ -53,9 +62,8 @@ module.exports = (common) => {

ipfs.block.put(blob, cid, (err, block) => {
expect(err).to.not.exist
expect(block.key('sha2-256')).to.eql(multihash.fromB58String(expectedHash))
expect(block.data).to.eql(new Buffer('blorb'))
done()
expectKey(block, multihash.fromB58String(expectedHash), done)
})
})

Expand All @@ -65,17 +73,17 @@ module.exports = (common) => {

ipfs.block.put(blob, (err, block) => {
expect(err).to.not.exist
expect(block.key('sha2-256')).to.eql(multihash.fromB58String(expectedHash))
expect(block.data).to.eql(new Buffer('blorb'))
done()
expectKey(block, multihash.fromB58String(expectedHash), done)
})
})

it('.put error with array of blocks', () => {
it('.put error with array of blocks', (done) => {
const blob = Buffer('blorb')

ipfs.block.put([blob, blob], 'fake cids', (err) => {
expect(err).to.be.an.instanceof(Error)
done()
})
})

Expand All @@ -85,9 +93,8 @@ module.exports = (common) => {

ipfs.block.get(cid, (err, block) => {
expect(err).to.not.exist
expect(block.key('sha2-256')).to.eql(cid.multihash)
expect(block.data).to.eql(new Buffer('blorb'))
done()
expectKey(block, cid.multihash, done)
})
})

Expand All @@ -96,9 +103,8 @@ module.exports = (common) => {

ipfs.block.get(hash, (err, block) => {
expect(err).to.not.exist
expect(block.key('sha2-256')).to.eql(multihash.fromB58String(hash))
expect(block.data).to.eql(new Buffer('blorb'))
done()
expectKey(block, multihash.fromB58String(hash), done)
})
})

Expand Down
25 changes: 11 additions & 14 deletions src/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
const expect = require('chai').expect
const bs58 = require('bs58')
const Readable = require('readable-stream')
const path = require('path')
const fs = require('fs')
const loadFixture = require('aegir/fixtures')
const bl = require('bl')
const concat = require('concat-stream')
const through = require('through2')
Expand All @@ -23,16 +22,16 @@ module.exports = (common) => {
// CI is slow
this.timeout(20 * 1000)

smallFile = fs.readFileSync(path.join(__dirname, './data/testfile.txt'))
bigFile = fs.readFileSync(path.join(__dirname, './data/15mb.random'))
smallFile = loadFixture(__dirname, '../test/fixtures/testfile.txt')
bigFile = loadFixture(__dirname, '../test/fixtures/15mb.random')

directoryContent = {
'pp.txt': fs.readFileSync(path.join(__dirname, './data/test-folder/pp.txt')),
'holmes.txt': fs.readFileSync(path.join(__dirname, './data/test-folder/holmes.txt')),
'jungle.txt': fs.readFileSync(path.join(__dirname, './data/test-folder/jungle.txt')),
'alice.txt': fs.readFileSync(path.join(__dirname, './data/test-folder/alice.txt')),
'files/hello.txt': fs.readFileSync(path.join(__dirname, './data/test-folder/files/hello.txt')),
'files/ipfs.txt': fs.readFileSync(path.join(__dirname, './data/test-folder/files/ipfs.txt'))
'pp.txt': loadFixture(__dirname, '../test/fixtures/test-folder/pp.txt'),
'holmes.txt': loadFixture(__dirname, '../test/fixtures/test-folder/holmes.txt'),
'jungle.txt': loadFixture(__dirname, '../test/fixtures/test-folder/jungle.txt'),
'alice.txt': loadFixture(__dirname, '../test/fixtures/test-folder/alice.txt'),
'files/hello.txt': loadFixture(__dirname, '../test/fixtures/test-folder/files/hello.txt'),
'files/ipfs.txt': loadFixture(__dirname, '../test/fixtures/test-folder/files/ipfs.txt')
}

common.setup((err, factory) => {
Expand Down Expand Up @@ -436,10 +435,9 @@ module.exports = (common) => {
})
})

it('errors on invalid key', (done) => {
it('errors on invalid key', () => {
const hash = 'somethingNotMultihash'
ipfs.files.get(hash)
.then((stream) => {})
return ipfs.files.get(hash)
.catch((err) => {
expect(err).to.exist
const errString = err.toString()
Expand All @@ -449,7 +447,6 @@ module.exports = (common) => {
if (errString === 'Error: Invalid Key') {
expect(err.toString()).to.contain('Error: Invalid Key')
}
done()
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion src/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ module.exports = (common) => {
})

it('object.stat', () => {
return ipfs.object.stat('QmNggDXca24S6cMPEYHZjeuc4QRmofkRrAEqVL3Ms2sdJZ')
return ipfs.object.stat('QmNggDXca24S6cMPEYHZjeuc4QRmofkRrAEqVL3Ms2sdJZ', {enc: 'base58'})
.then((stats) => {
const expected = {
Hash: 'QmNggDXca24S6cMPEYHZjeuc4QRmofkRrAEqVL3Ms2sdJZ',
Expand Down
5 changes: 2 additions & 3 deletions src/pin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
'use strict'

const expect = require('chai').expect
const fs = require('fs')
const path = require('path')
const loadFixture = require('aegir/fixtures')

const testfile = fs.readFileSync(path.join(__dirname, './data/testfile.txt'))
const testfile = loadFixture(__dirname, '../test/fixtures/testfile.txt')

module.exports = (common) => {
describe('.pin', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/swarm.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ module.exports = (common) => {
expect(err).to.not.exist
expect(multiaddrs).to.not.be.empty
expect(multiaddrs).to.be.an('array')
expect(multiaddrs[0].constructor.name).to.be.eql('Peer')
console.log(multiaddrs)
expect(multiaddrs[0].constructor.name).to.be.eql('PeerInfo')
done()
})
})
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit c90fdc2

Please sign in to comment.