Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
feat(object): object.put protobuf encoding test
Browse files Browse the repository at this point in the history
Closes #3
  • Loading branch information
dignifiedquire committed May 13, 2016
1 parent 6ee77eb commit a8bc46d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
"dependencies": {
"bs58": "^3.0.0",
"chai": "^3.5.0",
"ipfs-merkle-dag": "^0.5.1",
"json2yaml": "^1.1.0"
"ipfs-merkle-dag": "^0.5.1"
},
"devDependencies": {
"aegir": "^3.0.1"
Expand All @@ -40,4 +39,4 @@
"David Dias <[email protected]>",
"dignifiedquire <[email protected]>"
]
}
}
27 changes: 12 additions & 15 deletions src/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
const expect = require('chai').expect
const DAGNode = require('ipfs-merkle-dag').DAGNode
const bs58 = require('bs58')
const jsonToYaml = require('json2yaml')

module.exports = (common) => {
describe('.object', () => {
Expand Down Expand Up @@ -79,21 +78,15 @@ module.exports = (common) => {
})
})

// TODO verify that yaml encoded buffers still work in go-ipfs
it.skip('of yaml encoded buffer', (done) => {
const obj = {
Data: new Buffer('Some data').toString(),
Links: []
}

const buf = new Buffer(jsonToYaml.stringify(obj))
it('of protobuf encoded buffer', (done) => {
const dNode = new DAGNode(new Buffer('Some data'))
const buf = dNode.marshal()

ipfs.object.put(buf, { enc: 'yaml' }, (err, node) => {
ipfs.object.put(buf, { enc: 'protobuf' }, (err, node) => {
expect(err).to.not.exist
const nodeJSON = node.toJSON()
expect(obj.Data).to.deep.equal(nodeJSON.Data)
expect(obj.Links).to.deep.equal(nodeJSON.Links)
expect(nodeJSON.Hash).to.equal('QmPb5f92FxKPYdT3QNBd1GKiL4tZUXUrzF4Hkpdr3Gf1gK')
expect(dNode.data).to.deep.equal(node.data)
expect(dNode.links).to.deep.equal(node.links)
expect(dNode.multihash()).to.deep.equal(node.multihash())
done()
})
})
Expand Down Expand Up @@ -137,7 +130,11 @@ module.exports = (common) => {
ipfs.object.put(dNode1, (err, node) => {
expect(err).to.not.exist
expect(dNode1.data).to.deep.equal(node.data)
expect(dNode1.links).to.deep.equal(node.links)
expect(
dNode1.links.map((l) => l.toJSON())
).to.deep.equal(
node.links.map((l) => l.toJSON())
)
expect(dNode1.multihash()).to.deep.equal(node.multihash())
done()
})
Expand Down

0 comments on commit a8bc46d

Please sign in to comment.