This repository has been archived by the owner on Dec 15, 2022. It is now read-only.
Test coverage for GitTempDir #1901
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import fs from 'fs-extra'; | ||
import path from 'path'; | ||
|
||
import GitTempDir, {BIN_SCRIPTS} from '../lib/git-temp-dir'; | ||
|
||
describe('GitTempDir', function() { | ||
it('ensures that a temporary directory is populated', async function() { | ||
const tempDir = new GitTempDir(); | ||
await tempDir.ensure(); | ||
|
||
const root = tempDir.getRootPath(); | ||
for (const scriptName in BIN_SCRIPTS) { | ||
const script = BIN_SCRIPTS[scriptName]; | ||
const stat = await fs.stat(path.join(root, script)); | ||
assert.isTrue(stat.isFile()); | ||
if (script.endsWith('.sh') && process.platform !== 'win32') { | ||
// eslint-disable-next-line no-bitwise | ||
assert.isTrue((stat.mode & fs.constants.S_IXUSR) === fs.constants.S_IXUSR); | ||
} | ||
} | ||
|
||
await tempDir.ensure(); | ||
assert.strictEqual(root, tempDir.getRootPath()); | ||
}); | ||
|
||
it('generates getters for script paths', async function() { | ||
const tempDir = new GitTempDir(); | ||
await tempDir.ensure(); | ||
|
||
const scriptPath = tempDir.getScriptPath('git-credential-atom.js'); | ||
assert.isTrue(scriptPath.startsWith(tempDir.getRootPath())); | ||
assert.isTrue(scriptPath.endsWith('git-credential-atom.js')); | ||
|
||
assert.strictEqual(tempDir.getCredentialHelperJs(), tempDir.getScriptPath('git-credential-atom.js')); | ||
assert.strictEqual(tempDir.getCredentialHelperSh(), tempDir.getScriptPath('git-credential-atom.sh')); | ||
assert.strictEqual(tempDir.getAskPassJs(), tempDir.getScriptPath('git-askpass-atom.js')); | ||
}); | ||
|
||
it('fails when the temp dir is not yet created', function() { | ||
const tempDir = new GitTempDir(); | ||
assert.throws(() => tempDir.getAskPassJs(), /uninitialized GitTempDir/); | ||
}); | ||
|
||
if (process.platform === 'win32') { | ||
it('generates a valid named pipe path for its socket', async function() { | ||
const tempDir = new GitTempDir(); | ||
await tempDir.ensure(); | ||
|
||
assert.match(tempDir.getSocketPath(), /^\\\\\?\\pipe\\/); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fun regex. oh, windows. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Named pipes are fun 🙃 |
||
}); | ||
} else { | ||
it('generates a socket path within the directory', async function() { | ||
const tempDir = new GitTempDir(); | ||
await tempDir.ensure(); | ||
|
||
assert.isTrue(tempDir.getSocketPath().startsWith(tempDir.getRootPath())); | ||
}); | ||
} | ||
|
||
it('deletes the directory on dispose', async function() { | ||
const tempDir = new GitTempDir(); | ||
await tempDir.ensure(); | ||
|
||
const beforeStat = await fs.stat(tempDir.getRootPath()); | ||
assert.isTrue(beforeStat.isDirectory()); | ||
|
||
await tempDir.dispose(); | ||
|
||
await assert.isRejected(fs.stat(tempDir.getRootPath()), /ENOENT/); | ||
}); | ||
}); |
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.
just for my own education...
you assign
root = tempDir.getRootPath
on line 11, and then assert that that these are still equal. With this assertion, are you testing thatensure()
does not change the root path?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.
Yup, exactly. I wanted to assert that multiple calls to
ensure()
wouldn't create new temp directories, basically.