Skip to content

Commit

Permalink
Adds another repo creation test.
Browse files Browse the repository at this point in the history
  • Loading branch information
hackergrrl committed Apr 21, 2016
1 parent e770808 commit 3638a95
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
],
"homepage": "https://github.com/ipfs/js-ipfs-repo",
"devDependencies": {
"abstract-blob-store": "^3.2.0",
"aegir": "^2.1.1",
"async": "^1.5.2",
"bl": "^1.1.2",
Expand Down
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
const stores = require('./stores')

function Repo (repoPath, options) {
if (!(this instanceof Repo)) {
return new Repo(repoPath, options)
}
if (!options) { throw new Error('missing options param') }
if (!options.stores) { throw new Error('missing options.stores param') }

Expand Down
27 changes: 27 additions & 0 deletions test/repo-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

'use strict'

const Repo = require('../src/index')
const expect = require('chai').expect
const base58 = require('bs58')
const bl = require('bl')
Expand All @@ -14,6 +15,32 @@ const fileAExt = fs.readFileSync(join(__dirname, 'test-repo/blocks/12207028/1220

module.exports = function (repo) {
describe('IPFS Repo Tests', function () {
it('can init repo /wo new', (done) => {
var repo
function run () {
repo = Repo('foo', { stores: require('abstract-blob-store') })
}
expect(run).to.not.throw(Error)
expect(repo).to.be.an.instanceof(Repo)
done()
})

it('bad repo init 1', (done) => {
function run () {
new Repo()
}
expect(run).to.throw(Error)
done()
})

it('bad repo init 2', (done) => {
function run () {
new Repo('', {})
}
expect(run).to.throw(Error)
done()
})

it('check if Repo exists', (done) => {
repo.exists((err, exists) => {
expect(err).to.not.exist
Expand Down

0 comments on commit 3638a95

Please sign in to comment.