This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
'ipfs init': CLI + tests #96
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
49b77b4
early init cli work
hackergrrl 8f757fb
minor cleanup
hackergrrl de77790
cli init tests /w cleanup
hackergrrl 01eb084
check for repo files during init tests
hackergrrl 583e190
check the repo path each time
hackergrrl 21f875a
uses utils repo path
hackergrrl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* eslint-env mocha */ | ||
|
||
const expect = require('chai').expect | ||
const nexpect = require('nexpect') | ||
const rimraf = require('rimraf') | ||
const path = require('path') | ||
const fs = require('fs') | ||
const utils = require('../../src/cli/utils') | ||
|
||
function repoExistsSync (p) { | ||
return fs.existsSync(path.join(utils.getRepoPath(), p)) | ||
} | ||
|
||
describe('init', function () { | ||
this.timeout(10000) | ||
|
||
var oldRepoPath = process.env.IPFS_PATH | ||
beforeEach((done) => { | ||
oldRepoPath = process.env.IPFS_PATH | ||
const repoPath = '/tmp/ipfs-test-' + Math.random().toString().substring(2, 8) + '/' | ||
process.env.IPFS_PATH = repoPath | ||
done() | ||
}) | ||
|
||
afterEach((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 | ||
expect(repoExistsSync('blocks')).to.equal(true) | ||
expect(repoExistsSync('config')).to.equal(true) | ||
expect(repoExistsSync('version')).to.equal(true) | ||
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 | ||
expect(repoExistsSync('blocks')).to.equal(false) | ||
expect(repoExistsSync('config')).to.equal(true) | ||
expect(repoExistsSync('version')).to.equal(true) | ||
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() | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. On it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.