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

Commit a8bc46d

Browse files
feat(object): object.put protobuf encoding test
Closes #3
1 parent 6ee77eb commit a8bc46d

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030
"dependencies": {
3131
"bs58": "^3.0.0",
3232
"chai": "^3.5.0",
33-
"ipfs-merkle-dag": "^0.5.1",
34-
"json2yaml": "^1.1.0"
33+
"ipfs-merkle-dag": "^0.5.1"
3534
},
3635
"devDependencies": {
3736
"aegir": "^3.0.1"
@@ -40,4 +39,4 @@
4039
"David Dias <[email protected]>",
4140
"dignifiedquire <[email protected]>"
4241
]
43-
}
42+
}

src/object.js

+12-15
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
const expect = require('chai').expect
55
const DAGNode = require('ipfs-merkle-dag').DAGNode
66
const bs58 = require('bs58')
7-
const jsonToYaml = require('json2yaml')
87

98
module.exports = (common) => {
109
describe('.object', () => {
@@ -79,21 +78,15 @@ module.exports = (common) => {
7978
})
8079
})
8180

82-
// TODO verify that yaml encoded buffers still work in go-ipfs
83-
it.skip('of yaml encoded buffer', (done) => {
84-
const obj = {
85-
Data: new Buffer('Some data').toString(),
86-
Links: []
87-
}
88-
89-
const buf = new Buffer(jsonToYaml.stringify(obj))
81+
it('of protobuf encoded buffer', (done) => {
82+
const dNode = new DAGNode(new Buffer('Some data'))
83+
const buf = dNode.marshal()
9084

91-
ipfs.object.put(buf, { enc: 'yaml' }, (err, node) => {
85+
ipfs.object.put(buf, { enc: 'protobuf' }, (err, node) => {
9286
expect(err).to.not.exist
93-
const nodeJSON = node.toJSON()
94-
expect(obj.Data).to.deep.equal(nodeJSON.Data)
95-
expect(obj.Links).to.deep.equal(nodeJSON.Links)
96-
expect(nodeJSON.Hash).to.equal('QmPb5f92FxKPYdT3QNBd1GKiL4tZUXUrzF4Hkpdr3Gf1gK')
87+
expect(dNode.data).to.deep.equal(node.data)
88+
expect(dNode.links).to.deep.equal(node.links)
89+
expect(dNode.multihash()).to.deep.equal(node.multihash())
9790
done()
9891
})
9992
})
@@ -137,7 +130,11 @@ module.exports = (common) => {
137130
ipfs.object.put(dNode1, (err, node) => {
138131
expect(err).to.not.exist
139132
expect(dNode1.data).to.deep.equal(node.data)
140-
expect(dNode1.links).to.deep.equal(node.links)
133+
expect(
134+
dNode1.links.map((l) => l.toJSON())
135+
).to.deep.equal(
136+
node.links.map((l) => l.toJSON())
137+
)
141138
expect(dNode1.multihash()).to.deep.equal(node.multihash())
142139
done()
143140
})

0 commit comments

Comments
 (0)