Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
fix: DAGLink tests
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Nov 20, 2016
1 parent 6e3ab23 commit eec00da
Show file tree
Hide file tree
Showing 17 changed files with 16 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/dag-link/index.js
@@ -1,13 +1,14 @@
'use strict'

const mh = require('multihashes')
const assert = require('assert')

// Link represents an IPFS Merkle DAG Link between Nodes.
class DAGLink {
constructor (name, size, multihash) {
assert(multihash, 'A link requires a multihash to point to')
this._name = name
this._size = size
this._multihash = null

if (typeof multihash === 'string') {
this._multihash = mh.fromB58String(multihash)
Expand Down
2 changes: 1 addition & 1 deletion test/browser.js
Expand Up @@ -5,7 +5,7 @@ const series = require('async/series')
const Store = require('idb-pull-blob-store')
const _ = require('lodash')
const IPFSRepo = require('ipfs-repo')
const repoContext = require.context('buffer!./example-repo', true)
const repoContext = require.context('buffer!./test-repo', true)
const pull = require('pull-stream')

const idb = window.indexedDB ||
Expand Down
18 changes: 10 additions & 8 deletions test/dag-link-test.js
Expand Up @@ -3,35 +3,37 @@

const expect = require('chai').expect
const mh = require('multihashes')
const DAGLink = require('../src/dag-link')
const DAGLink = require('../src').DAGLink

module.exports = (repo) => {
describe('DAGLink', () => {
describe('hash', () => {
describe('create with multihash as b58 encoded string', () => {
it('string', () => {
const link = new DAGLink('hello', 3, 'QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39U')

expect(link.multihash.toString('hex'))
.to.equal('12208ab7a6c5e74737878ac73863cb76739d15d4666de44e5756bf55a2f9e9ab5f43')
})

it('Buffer', () => {
it('create with multihash as a multihash Buffer', () => {
const link = new DAGLink('hello', 3, new Buffer('12208ab7a6c5e74737878ac73863cb76739d15d4666de44e5756bf55a2f9e9ab5f43', 'hex'))

expect(mh.toB58String(link.multihash))
.to.equal('QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39U')
})

it('missing', () => {
const link = new DAGLink('hello', 3)
expect(link.multihash).to.not.exist
it('fail to create without multihash', () => {
expect(() => {
const link = new DAGLink('hello', 3)
expect(link).to.not.exist
}).to.throw
})
})

it('json', () => {
it('toJSON', () => {
const link = new DAGLink('hello', 3, 'QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39U')

expect(link.json).to.eql({
expect(link.toJSON()).to.eql({
name: 'hello',
size: 3,
hash: 'QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39U'
Expand Down
2 changes: 1 addition & 1 deletion test/dag-node-test.js
Expand Up @@ -19,7 +19,7 @@ const CID = require('cids')
const bs58 = require('bs58')

module.exports = (repo) => {
describe.only('DAGNode', () => {
describe('DAGNode', () => {
it('create a node', (done) => {
expect(7).checks(done)
const data = new Buffer('some data')
Expand Down
2 changes: 1 addition & 1 deletion test/node.js
Expand Up @@ -7,7 +7,7 @@ const IPFSRepo = require('ipfs-repo')
const Store = require('fs-pull-blob-store')

describe('Node.js Tests', () => {
const repoExample = process.cwd() + '/test/example-repo'
const repoExample = process.cwd() + '/test/test-repo'
const repoTests = process.cwd() + '/test/repo-just-for-test' + Date.now()

before((done) => {
Expand Down
2 changes: 1 addition & 1 deletion test/resolver.spec.js
Expand Up @@ -12,7 +12,7 @@ const parallel = require('async/parallel')

const Block = require('ipfs-block')

describe('IPLD format resolver (local)', () => {
describe.skip('IPLD Format resolver (local)', () => {
let emptyNodeBlock
let linksNodeBlock
let dataLinksNodeBlock
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.

0 comments on commit eec00da

Please sign in to comment.