Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
cli init tests /w cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hackergrrl committed Mar 24, 2016
1 parent 8f757fb commit de77790
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/cli/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions src/cli/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ exports.getIPFS = (callback) => {

callback(null, getAPICtl())
}

exports.getRepoPath = () => {
return repoPath
}
22 changes: 21 additions & 1 deletion tests/test-cli/test-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit de77790

Please sign in to comment.