Skip to content

Commit bdb42d8

Browse files
author
Joshua Grosso
committed
Add spec stubs [WIP]
1 parent e6ad388 commit bdb42d8

19 files changed

+307
-393
lines changed

src/commands/push.js

-7
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,6 @@ import {
1010
verifyOutput
1111
} from '../helpers';
1212

13-
/**
14-
* Note to future maintainers, I do not like this; at all. But at the moment this is the
15-
* best we got, inorder to parse the result from git core. Any slight change to the LFS output
16-
* in subsequent versions of CORE for LFS, will surely break this. Until we migrate off
17-
* git core dependency, we will have to regex the output. Godspeed.
18-
*/
19-
2013
const isValidLine = str => str !== '';
2114

2215
const generatePushStats = (raw) => {

src/index.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import initialize from './initialize';
22
import register from './register';
33
import unregister from './unregister';
44
import { core } from './commands/lfsCommands';
5-
import { loadGitattributeFiltersFromRepo, repoHasLfs } from './helpers';
5+
import {
6+
loadGitattributeFiltersFromRepo,
7+
repoHasLfs
8+
} from './helpers';
69
import checkout from './commands/checkout';
710
import push from './commands/push';
811
import track from './commands/track';

src/utils/spawnHelper.js

+29-5
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,28 @@ const buildSocketPath = () => tmp.dir()
2424
return path.join(prefix, cleanedPath, 'echo.sock');
2525
});
2626

27+
/**
28+
* Flow type definition:
29+
*
30+
* type BuildCredentialsCallbackProcess =
31+
* (
32+
* spawnedProcess: ChildProcess,
33+
* callback: (
34+
* passwordOnly: boolean,
35+
* callback: (usernamePrompt: boolean) =>
36+
* (username: string, password: ?string, cancel: boolean) =>
37+
* void
38+
* )
39+
* ),
40+
* reject: Error => Promise<void>
41+
* ) =>
42+
* (chunk: Buffer) =>
43+
* string;
44+
*/
2745
const buildCredentialsCallbackProcess = (spawnedProcess, callback, reject) => {
2846
let credentials = {};
2947
const credentialsCallback = needsUsername => (username, password, cancel) => {
3048
if (cancel) {
31-
// we are done here
3249
spawnedProcess.destroy();
3350
return reject(new Error('LFS action cancelled'));
3451
}
@@ -42,22 +59,23 @@ const buildCredentialsCallbackProcess = (spawnedProcess, callback, reject) => {
4259
const output = chunk.toString();
4360

4461
if (output.match(regex.USERNAME)) {
62+
// We're caching the username in-memory in case the process asks for the username several
63+
// times (for example, LFS re-prompts for credentials on every file).
4564
if (credentials.username) {
4665
spawnedProcess.write(credentials.username);
4766
spawnedProcess.write(EOL);
4867
} else {
49-
// If we have a username we need to make sure to prompt for it
5068
callback(true, credentialsCallback(true));
5169
}
5270
} else if (output.match(regex.PASSWORD)) {
5371
if (credentials.password) {
5472
spawnedProcess.write(credentials.password);
5573
spawnedProcess.write(EOL);
5674
} else {
57-
// no username so maybe ssh?
5875
callback(false, credentialsCallback(false));
5976
}
6077
}
78+
6179
return output;
6280
};
6381
};
@@ -69,8 +87,7 @@ const buildSocket = (size, closeProcess, socketName, mainResolve, mainReject) =>
6987
let resolved = false;
7088

7189
const closedOrEnded = () => {
72-
// For some reason this fires twice so after
73-
// the first fire let's move on
90+
// Don't fire this callback if it's already been called.
7491
if (!resolved) {
7592
mainResolve({ stdout: Buffer.concat(bufferList) });
7693
resolved = true;
@@ -90,6 +107,7 @@ const buildSocket = (size, closeProcess, socketName, mainResolve, mainReject) =>
90107
});
91108
socket.on('error', mainReject);
92109
});
110+
93111
socketServer.listen(socketName);
94112
socketServer.on('listening', () => {
95113
resolve(socketName);
@@ -200,3 +218,9 @@ const spawn = (command, opts = {}, callback) => new Promise(
200218
});
201219

202220
export default spawn;
221+
222+
export const __TESTING__ = { // eslint-disable-line no-underscore-dangle
223+
buildCredentialsCallbackProcess,
224+
buildSocket,
225+
buildSocketPath
226+
};

test/tests/commands/checkout.spec.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {
2+
todo
3+
} from '../../utils';
4+
5+
describe('checkout', () => {
6+
it('can checkout in the provided repo', todo);
7+
8+
it('responds appropriately on error', todo);
9+
});

test/tests/commands/clone.spec.js

+3-22
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import {
1313
populateRemoteBranch
1414
} from '../../server/server';
1515
import {
16-
fail
16+
fail,
17+
todo
1718
} from '../../utils';
1819

1920
import {
20-
BAD_CORE_RESPONSE,
2121
BAD_REGEX_PARSE_RESULT
2222
} from '../../../build/src/constants';
2323
import {
@@ -168,24 +168,5 @@ describe('Clone', () => {
168168
}
169169
});
170170

171-
it('should return an appropriate result on error', function () {
172-
const {
173-
NodeGitLFS
174-
} = this;
175-
176-
return NodeGitLFS.LFS.clone(
177-
'invalid',
178-
testReposPath
179-
)
180-
.then((result) => {
181-
expect(result.errno).to.equal(BAD_CORE_RESPONSE);
182-
expect(result.stderr).to.equal(
183-
`fatal: repository 'invalid' does not exist
184-
Error(s) during clone:
185-
git clone failed: exit status 128
186-
`,
187-
);
188-
expect(result.success).to.be.false;
189-
});
190-
});
171+
it('should return an appropriate result on error', todo);
191172
});
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import {
2+
todo
3+
} from '../../utils';
4+
5+
describe('lfsCommands', () => {
6+
it('can run `git lfs checkout`', todo);
7+
8+
it('can run `git lfs clone`', todo);
9+
10+
it('can run `git lfs fetch`', todo);
11+
12+
it('can run `git lfs fsck`', todo);
13+
14+
it('can run any `git` command', todo);
15+
16+
it('can run `git lfs install`', todo);
17+
18+
it('can run `git lfs logs`', todo);
19+
20+
it('can run `git lfs ls-files`', todo);
21+
22+
it('can run `git lfs pointer`', todo);
23+
24+
it('can run `git lfs prune`', todo);
25+
26+
it('can run `git lfs pull`', todo);
27+
28+
it('can run `git lfs push`', todo);
29+
30+
it('can run `git lfs status`', todo);
31+
32+
it('can run `git lfs track`', todo);
33+
34+
it('can run `git lfs untrack`', todo);
35+
36+
it('can run `git lfs update`', todo);
37+
38+
it('can run `git lfs version`', todo);
39+
});

test/tests/commands/ls.spec.js

+4-13
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
1-
import {
2-
lfsTestRepoPath
3-
} from '../../constants';
41
import {
52
todo
63
} from '../../utils';
74

8-
import ls from '../../../build/src/commands/ls';
9-
105
describe('ls-files', () => {
11-
it('does generate ls response', function () {
12-
const {
13-
NodeGitLFS
14-
} = this;
6+
it('builds args from the provided options', todo);
7+
8+
it('can list LFS-tracked files in the provided repo', todo);
159

16-
return NodeGitLFS.Repository.open(lfsTestRepoPath)
17-
.then(repo => ls(repo, { long: true }))
18-
.then(() => todo());
19-
});
10+
it('returns the correct response on error', todo);
2011
});

test/tests/commands/pointer.spec.js

+3-16
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
1-
import path from 'path';
2-
3-
import {
4-
lfsTestRepoPath
5-
} from '../../constants';
61
import {
72
todo
83
} from '../../utils';
94

10-
import pointer from '../../../build/src/commands/pointer';
11-
125
describe('Pointer', () => {
13-
it('does generate pointer response', function () {
14-
const {
15-
NodeGitLFS
16-
} = this;
6+
it('creates args from provided file and pointer paths', todo);
177

18-
const packageJson = path.join(lfsTestRepoPath, 'package.json');
8+
it('can build a pointer', todo);
199

20-
return NodeGitLFS.Repository.open(lfsTestRepoPath)
21-
.then(repo => pointer(repo, packageJson))
22-
.then(() => todo());
23-
});
10+
it('responds appropriately on error', todo);
2411
});

test/tests/commands/prune.spec.js

+2-13
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,9 @@
1-
import {
2-
lfsTestRepoPath
3-
} from '../../constants';
41
import {
52
todo
63
} from '../../utils';
74

8-
import prune from '../../../build/src/commands/prune';
9-
105
describe('Prune', () => {
11-
it('does generate prune response', function () {
12-
const {
13-
NodeGitLFS
14-
} = this;
6+
it('can prune the provided repository', todo);
157

16-
return NodeGitLFS.Repository.open(lfsTestRepoPath)
17-
.then(repo => prune(repo))
18-
.then(() => todo());
19-
});
8+
it('responds appropriately on error', todo);
209
});

test/tests/commands/push.spec.js

+3-20
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,9 @@
1-
import path from 'path';
2-
3-
import {
4-
lfsTestRepoPath
5-
} from '../../constants';
61
import {
7-
createDummyFile,
82
todo
93
} from '../../utils';
104

11-
import exec from '../../../build/src/utils/execHelper';
12-
135
describe('Push', () => {
14-
it('should generate push response', function () {
15-
const {
16-
NodeGitLFS
17-
} = this;
6+
it('defaults to the current branch and its upstream', todo);
187

19-
return createDummyFile(path.join(lfsTestRepoPath, 'test_file.txt'), 20)
20-
.then(() => exec('git add test_file.txt', { cwd: lfsTestRepoPath }))
21-
.then(() => exec('git commit -m "LFS: push unit test"', { cwd: lfsTestRepoPath }))
22-
.then(() => NodeGitLFS.Repository.open(lfsTestRepoPath))
23-
.then(repo => NodeGitLFS.LFS.push(repo, 'origin', 'test'))
24-
.then(() => todo());
25-
});
26-
}).timeout(5000);
8+
it('responds appropriately on error', todo);
9+
});

test/tests/commands/track.spec.js

+4-13
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
1-
import {
2-
lfsTestRepoPath
3-
} from '../../constants';
41
import {
52
todo
63
} from '../../utils';
74

8-
import track from '../../../build/src/commands/track';
9-
105
describe('Track', () => {
11-
it('does generate track response', function () {
12-
const {
13-
NodeGitLFS
14-
} = this;
6+
it('requires globs to be provided', todo);
7+
8+
it('can track files', todo);
159

16-
return NodeGitLFS.Repository.open(lfsTestRepoPath)
17-
.then(repo => track(repo, ['*.png', '*.dmg']))
18-
.then(() => todo());
19-
});
10+
it('responds appropriately on error', todo);
2011
});

test/tests/commands/untrack.spec.js

+3-19
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,11 @@
1-
import {
2-
lfsTestRepoPath
3-
} from '../../constants';
41
import {
52
todo
63
} from '../../utils';
74

8-
import track from '../../../build/src/commands/track';
9-
import untrack from '../../../build/src/commands/untrack';
10-
115
describe('Untrack', () => {
12-
it('does generate untrack response', function () {
13-
const {
14-
NodeGitLFS
15-
} = this;
6+
it('requires globs to be provided', todo);
167

17-
let repository;
8+
it('can untrack currently-tracked files', todo);
189

19-
return NodeGitLFS.Repository.open(lfsTestRepoPath)
20-
.then((repo) => {
21-
repository = repo;
22-
return track(repo, ['*.png', '*.dmg', '*.txt', '*.a']);
23-
})
24-
.then(() => untrack(repository, ['*.dmg', '*.a']))
25-
.then(() => todo());
26-
});
10+
it('responds appropriately on error', todo);
2711
});

test/tests/constants.spec.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import {
2+
todo
3+
} from '../utils';
4+
5+
describe('Constants', () => {
6+
describe('Regexes', () => {
7+
it('GIT', todo);
8+
9+
it('LFS', todo);
10+
11+
it('PASSWORD', todo);
12+
13+
it('SKIPPED_BYTES', todo);
14+
15+
it('SKIPPED_FILES', todo);
16+
17+
it('TOTAL_BYTES', todo);
18+
19+
it('TOTAL_FILES', todo);
20+
21+
it('TRACK', todo);
22+
23+
it('USERNAME', todo);
24+
25+
it('VERSION', todo);
26+
});
27+
});

test/tests/helpers.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ describe('helpers', () => {
5454
repo
5555
} = this;
5656

57-
return track(repo, ['"*.md"', 'test.txt'])
57+
return track(repo, ['*.md', 'test.txt'])
5858
.then(() => helpers.loadGitattributeFiltersFromRepo(repo))
5959
.then((result) => {
6060
expect(result).to.have.members(['*.md', 'test.txt']);

0 commit comments

Comments
 (0)