From 3638a952cfbfc11d2fbde5a5dea24e082cb67fba Mon Sep 17 00:00:00 2001 From: Stephen Whitmore Date: Thu, 21 Apr 2016 10:19:17 -0700 Subject: [PATCH] Adds another repo creation test. --- package.json | 1 + src/index.js | 3 +++ test/repo-test.js | 27 +++++++++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/package.json b/package.json index 5e039c0e..5da4eef2 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/index.js b/src/index.js index 347ea788..e481fe70 100644 --- a/src/index.js +++ b/src/index.js @@ -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') } diff --git a/test/repo-test.js b/test/repo-test.js index e332442c..7bf32230 100644 --- a/test/repo-test.js +++ b/test/repo-test.js @@ -2,6 +2,7 @@ 'use strict' +const Repo = require('../src/index') const expect = require('chai').expect const base58 = require('bs58') const bl = require('bl') @@ -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