Repository navigation
Expand file tree
/
Copy pathgit-temp-dir.test.js
More file actions
72 lines (57 loc) · 2.51 KB
/
Copy pathgit-temp-dir.test.js
File metadata and controls
72 lines (57 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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 options to create a TCP socket on an unbound port', async function() {
const tempDir = new GitTempDir();
await tempDir.ensure();
assert.deepEqual(tempDir.getSocketOptions(), {port: 0, host: 'localhost'});
});
} else {
it('generates a socket path within the directory', async function() {
const tempDir = new GitTempDir();
await tempDir.ensure();
const opts = tempDir.getSocketOptions();
assert.isTrue(opts.path.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/);
});
});