From 114e6443c857d7663c54ae5f57cece0589cd6ce9 Mon Sep 17 00:00:00 2001 From: Stephen Whitmore Date: Thu, 24 Mar 2016 13:21:49 -0700 Subject: [PATCH] cli init tests /w cleanup --- src/cli/commands/init.js | 5 ++++- src/cli/utils.js | 4 ++++ tests/test-cli/test-init.js | 22 +++++++++++++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/cli/commands/init.js b/src/cli/commands/init.js index ce561f2aab..281cb6febc 100644 --- a/src/cli/commands/init.js +++ b/src/cli/commands/init.js @@ -2,6 +2,7 @@ const Command = require('ronin').Command const IpfsRepo = require('ipfs-repo') const Ipfs = require('../../core') const fsBlobStore = require('fs-blob-store') +const utils = require('../utils') module.exports = Command.extend({ desc: 'Initialize a local IPFS local node', @@ -26,7 +27,9 @@ module.exports = Command.extend({ }, run: (bits, force, empty) => { - const repo = new IpfsRepo('/tmp/my-little-repo', { + const path = utils.getRepoPath() + + const repo = new IpfsRepo(path, { stores: { keys: fsBlobStore, config: fsBlobStore, diff --git a/src/cli/utils.js b/src/cli/utils.js index c6e43daf4c..d11fff4424 100644 --- a/src/cli/utils.js +++ b/src/cli/utils.js @@ -44,3 +44,7 @@ exports.getIPFS = (callback) => { callback(null, getAPICtl()) } + +exports.getRepoPath = () => { + return repoPath +} diff --git a/tests/test-cli/test-init.js b/tests/test-cli/test-init.js index 785a8d35e4..9cf6b2304a 100644 --- a/tests/test-cli/test-init.js +++ b/tests/test-cli/test-init.js @@ -2,8 +2,28 @@ const expect = require('chai').expect const nexpect = require('nexpect') +const rimraf = require('rimraf') + +describe('init', function () { + this.timeout(10000) + + var oldRepoPath = process.env.IPFS_PATH + before((done) => { + oldRepoPath = process.env.IPFS_PATH + console.log('old', oldRepoPath) + const repoPath = '/tmp/ipfs-test-' + Math.random().toString().substring(2, 8) + '/' + process.env.IPFS_PATH = repoPath + done() + }) + + after((done) => { + rimraf(process.env.IPFS_PATH, (err) => { + expect(err).to.not.exist + process.env.IPFS_PATH = oldRepoPath + done() + }) + }) -describe('init', () => { it('basic', (done) => { nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'init']) .run((err, stdout, exitcode) => {