This repository has been archived by the owner on Aug 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0ccec3
commit 5ed9c74
Showing
2 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const chai = require('chai') | ||
const dirtyChai = require('dirty-chai') | ||
const expect = chai.expect | ||
chai.use(dirtyChai) | ||
const ipldGit = require('../src') | ||
const multihash = require('multihashes') | ||
const CID = require('cids') | ||
|
||
describe('IPLD format util', () => { | ||
const tagNode = { | ||
gitType: 'tag', | ||
object: {'/': new CID('z8mWaHQaEAKd5KMRNU3npB3saSZmhFh3e').buffer}, | ||
type: 'commit', | ||
tag: 'v0.0.0', | ||
tagger: { | ||
name: 'John Doe', | ||
email: '[email protected]', | ||
date: '1497302532 +0200' | ||
}, | ||
message: 'A message\n' | ||
} | ||
|
||
it('.serialize and .deserialize', (done) => { | ||
ipldGit.util.serialize(tagNode, (err, serialized) => { | ||
expect(err).to.not.exist() | ||
expect(Buffer.isBuffer(serialized)).to.equal(true) | ||
ipldGit.util.deserialize(serialized, (err, deserialized) => { | ||
expect(err).to.not.exist() | ||
expect(tagNode).to.eql(deserialized) | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
it('.cid', (done) => { | ||
ipldGit.util.cid(tagNode, (err, cid) => { | ||
expect(err).to.not.exist() | ||
expect(cid.version).to.equal(1) | ||
expect(cid.codec).to.equal('git-raw') | ||
expect(cid.multihash).to.exist() | ||
const mh = multihash.decode(cid.multihash) | ||
expect(mh.name).to.equal('sha1') | ||
done() | ||
}) | ||
}) | ||
|
||
it('.cid ignores options', (done) => { | ||
ipldGit.util.cid(tagNode, { hashAlg: 'unknown' }, (err, cid) => { | ||
expect(err).to.not.exist() | ||
expect(cid.version).to.equal(1) | ||
expect(cid.codec).to.equal('git-raw') | ||
expect(cid.multihash).to.exist() | ||
const mh = multihash.decode(cid.multihash) | ||
expect(mh.name).to.equal('sha1') | ||
done() | ||
}) | ||
}) | ||
}) |