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

Commit de77790

Browse files
committed
cli init tests /w cleanup
1 parent 8f757fb commit de77790

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

src/cli/commands/init.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const Command = require('ronin').Command
22
const IpfsRepo = require('ipfs-repo')
33
const Ipfs = require('../../core')
44
const fsBlobStore = require('fs-blob-store')
5+
const utils = require('../utils')
56

67
module.exports = Command.extend({
78
desc: 'Initialize a local IPFS local node',
@@ -26,7 +27,9 @@ module.exports = Command.extend({
2627
},
2728

2829
run: (bits, force, empty) => {
29-
const repo = new IpfsRepo('/tmp/my-little-repo', {
30+
const path = utils.getRepoPath()
31+
32+
const repo = new IpfsRepo(path, {
3033
stores: {
3134
keys: fsBlobStore,
3235
config: fsBlobStore,

src/cli/utils.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,7 @@ exports.getIPFS = (callback) => {
4444

4545
callback(null, getAPICtl())
4646
}
47+
48+
exports.getRepoPath = () => {
49+
return repoPath
50+
}

tests/test-cli/test-init.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,28 @@
22

33
const expect = require('chai').expect
44
const nexpect = require('nexpect')
5+
const rimraf = require('rimraf')
6+
7+
describe('init', function () {
8+
this.timeout(10000)
9+
10+
var oldRepoPath = process.env.IPFS_PATH
11+
before((done) => {
12+
oldRepoPath = process.env.IPFS_PATH
13+
console.log('old', oldRepoPath)
14+
const repoPath = '/tmp/ipfs-test-' + Math.random().toString().substring(2, 8) + '/'
15+
process.env.IPFS_PATH = repoPath
16+
done()
17+
})
18+
19+
after((done) => {
20+
rimraf(process.env.IPFS_PATH, (err) => {
21+
expect(err).to.not.exist
22+
process.env.IPFS_PATH = oldRepoPath
23+
done()
24+
})
25+
})
526

6-
describe('init', () => {
727
it('basic', (done) => {
828
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'init'])
929
.run((err, stdout, exitcode) => {

0 commit comments

Comments
 (0)