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

feat(object): object.put protobuf encoding test #7

Merged
merged 1 commit into from
May 13, 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
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 <daviddias.p@gmail.com>",
"dignifiedquire <dignifiedquire@gmail.com>"
]
}
}
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