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

'ipfs init': CLI + tests #96

Merged
merged 6 commits into from
Apr 2, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions src/cli/commands/init.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
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 ipfs local configuration',
desc: 'Initialize a local IPFS local node',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double local

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agghghgh thank you. <3


options: {
bits: {
Expand All @@ -22,5 +26,30 @@ module.exports = Command.extend({
}
},

run: () => {}
run: (bits, force, empty) => {
const path = utils.getRepoPath()

const repo = new IpfsRepo(path, {
stores: {
keys: fsBlobStore,
config: fsBlobStore,
datastore: fsBlobStore,
logs: fsBlobStore,
locks: fsBlobStore,
version: fsBlobStore
}
})

var ipfs = new Ipfs(repo)
ipfs.init({
bits: bits,
force: force,
emptyRepo: empty
}, function (err, res) {
if (err) {
console.error(err.toString())
process.exit(1)
}
})
}
})
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
}
72 changes: 72 additions & 0 deletions tests/test-cli/test-init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* eslint-env mocha */

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()
})
})

it('basic', (done) => {
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'init'])
.run((err, stdout, exitcode) => {
expect(err).to.not.exist
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only ensuring that no error is thrown, seems a bit superficial, maybe check for directories/files to exist at least?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. On it!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

done()
})
})

it('bits', (done) => {
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'init', '--bits', '64'])
.run((err, stdout, exitcode) => {
expect(err).to.not.exist
done()
})
})

it('empty', (done) => {
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'init', '--bits', '64', '--empty-repo', 'true'])
.run((err, stdout, exitcode) => {
expect(err).to.not.exist
done()
})
})

it('force', (done) => {
nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'init', '--bits', '64', '--force'])
.run((err, stdout, exitcode) => {
expect(err).to.not.exist
expect(exitcode).to.equal(0)

nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'init', '--bits', '64'])
.run((err, stdout, exitcode) => {
expect(err).to.not.exist
expect(exitcode).to.equal(1)

nexpect.spawn('node', [process.cwd() + '/src/cli/bin.js', 'init', '--bits', '64', '--force'])
.run((err, stdout, exitcode) => {
expect(err).to.not.exist
expect(exitcode).to.equal(0)
done()
})
})
})
})
})