Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d40146b

Browse files
Joshua GrossoJoshua Grosso
Joshua Grosso
authored and
Joshua Grosso
committedSep 6, 2017
Add specs
1 parent a0033ab commit d40146b

File tree

2 files changed

+399
-2
lines changed

2 files changed

+399
-2
lines changed
 

‎test/tests/commands/version.spec.js

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
import {
2+
expect
3+
} from 'chai';
4+
import sinon from 'sinon';
5+
6+
import {
7+
todo
8+
} from '../../utils';
9+
10+
import {
11+
BAD_CORE_RESPONSE,
12+
Error
13+
} from '../../../build/src/constants';
14+
import {
15+
core
16+
} from '../../../build/src/commands/lfsCommands';
17+
import {
18+
gitVersion,
19+
lfsVersion
20+
} from '../../../build/src/commands/version';
21+
22+
describe('version', () => {
23+
beforeEach(function () {
24+
this.sandbox = sinon.sandbox.create();
25+
});
26+
27+
afterEach(function () {
28+
const {
29+
sandbox
30+
} = this;
31+
32+
sandbox.restore();
33+
});
34+
35+
describe('gitVersion', () => {
36+
it("parses `git --version`'s output", function () {
37+
const {
38+
sandbox
39+
} = this;
40+
41+
sandbox.stub(core, 'git').returns(Promise.resolve({
42+
stdout: 'git version 2.0.0.windows.1'
43+
}));
44+
45+
return gitVersion()
46+
.then((result) => {
47+
expect(core.git).to.have.been.calledWith('--version');
48+
49+
expect(result).to.eql({
50+
errno: Error.CODE.OK,
51+
raw: 'git version 2.0.0.windows.1',
52+
stderr: '',
53+
success: true,
54+
version: '2.0.0'
55+
});
56+
});
57+
});
58+
59+
it('handles errors', function () {
60+
const {
61+
sandbox
62+
} = this;
63+
64+
sandbox.stub(core, 'git').returns(Promise.reject(BAD_CORE_RESPONSE));
65+
66+
return gitVersion()
67+
.then((result) => {
68+
expect(result).to.eql({
69+
errno: BAD_CORE_RESPONSE,
70+
raw: '',
71+
stderr: '',
72+
success: false
73+
});
74+
});
75+
});
76+
});
77+
78+
describe('lfsVersion', () => {
79+
it("parses `git-lfs-version`'s output", function () {
80+
const {
81+
sandbox
82+
} = this;
83+
84+
sandbox.stub(core, 'version').returns(Promise.resolve({
85+
stdout: 'git-lfs/100.100.100 (GitHub; windows amd64; go 1.5.3; git 7de0397)'
86+
}));
87+
88+
return lfsVersion()
89+
.then((result) => {
90+
expect(core.version).to.have.been.called;
91+
92+
expect(result).to.eql({
93+
errno: Error.CODE.OK,
94+
raw: 'git-lfs/100.100.100 (GitHub; windows amd64; go 1.5.3; git 7de0397)',
95+
stderr: '',
96+
success: true,
97+
version: '100.100.100'
98+
});
99+
});
100+
});
101+
102+
it('handles errors', function () {
103+
const {
104+
sandbox
105+
} = this;
106+
107+
sandbox.stub(core, 'version').returns(Promise.resolve({
108+
stdout: 'Some stdout',
109+
stderr: 'git-lfs-version not found!'
110+
}));
111+
112+
return lfsVersion()
113+
.then((result) => {
114+
expect(result).to.eql({
115+
errno: BAD_CORE_RESPONSE,
116+
raw: 'Some stdout',
117+
stderr: 'git-lfs-version not found!',
118+
success: false
119+
});
120+
});
121+
});
122+
});
123+
});
Lines changed: 276 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,280 @@
11
import {
2-
todo
3-
} from '../../utils';
2+
expect
3+
} from 'chai';
4+
import fse from 'fs-extra';
5+
import path from 'path';
6+
import sinon from 'sinon';
7+
8+
import {
9+
emptyRepoPath,
10+
lfsTestRepoPath
11+
} from '../../constants';
12+
13+
import {
14+
BAD_CORE_RESPONSE,
15+
BAD_VERSION,
16+
Error,
17+
minimumVersions
18+
} from '../../../build/src/constants';
19+
import {
20+
core
21+
} from '../../../build/src/commands/lfsCommands';
22+
import {
23+
__TESTING__,
24+
dependencyCheck,
25+
isLfsRepo,
26+
parseVersion
27+
} from '../../../build/src/utils/checkDependencies';
28+
29+
const {
30+
handleVersionResponse,
31+
normalizeVersion
32+
} = __TESTING__;
433

534
describe('checkDependencies', () => {
35+
beforeEach(function () {
36+
this.sandbox = sinon.sandbox.create();
37+
});
38+
39+
afterEach(function () {
40+
const {
41+
sandbox
42+
} = this;
43+
44+
sandbox.restore();
45+
});
46+
47+
describe('normalizeVersion', () => {
48+
it('converts an array of version segments into a version string', () => {
49+
expect(normalizeVersion(['12'])).to.equal('12');
50+
expect(normalizeVersion(['12', '34', '56', '78'])).to.equal('12.34.56.78');
51+
});
52+
53+
describe('when no array is provided', () => {
54+
it('returns `BAD_VERSION`', () => {
55+
expect(normalizeVersion()).to.equal(BAD_VERSION);
56+
});
57+
});
58+
59+
describe('when an empty array is provided', () => {
60+
it('returns `BAD_VERSION`', () => {
61+
expect(normalizeVersion([])).to.equal(BAD_VERSION);
62+
});
63+
});
64+
});
65+
66+
describe('parseVersion', () => {
67+
const versionRegex = /\s(.+)-(.+)-(.+)\//;
68+
69+
it('extracts a version string from the provided input', () => {
70+
expect(parseVersion('my-program 12-34-56/', versionRegex)).to.equal('12.34.56');
71+
});
72+
73+
describe('when no input is provided', () => {
74+
it('returns `BAD_VERSION`', () => {
75+
expect(parseVersion('', versionRegex)).to.equal(BAD_VERSION);
76+
});
77+
});
78+
79+
describe('when the provided input does not match the provided regex', () => {
80+
it('returns `BAD_VERSION`', () => {
81+
expect(parseVersion('nope', versionRegex)).to.equal(BAD_VERSION);
82+
});
83+
});
84+
85+
describe('when the matched version segments are not numbers', () => {
86+
it('returns `BAD_VERSION`', () => {
87+
expect(parseVersion(' test1-test2-test3/', versionRegex)).to.equal(BAD_VERSION);
88+
});
89+
});
90+
});
91+
92+
describe('isLfsRepo', () => {
93+
describe('when the provided working directory contains a `.git/lfs` folder', () => {
94+
it('returns `true`', () =>
95+
fse.mkdir(path.join(lfsTestRepoPath, '.git', 'lfs'))
96+
.then(() => isLfsRepo(lfsTestRepoPath))
97+
.then((result) => {
98+
expect(result).to.be.true;
99+
})
100+
);
101+
});
102+
103+
describe('when the provided working directory does not contain a `.git/lfs` folder', () => {
104+
it('returns `false`', () =>
105+
isLfsRepo(emptyRepoPath)
106+
.then((result) => {
107+
expect(result).to.be.false;
108+
})
109+
);
110+
});
111+
});
112+
113+
describe('handleVersionResponse', () => {
114+
it('handles a Git version check response', () => {
115+
expect(handleVersionResponse(
116+
'GIT',
117+
{
118+
errno: Error.CODE.OK,
119+
raw: `git version ${minimumVersions.GIT}.windows.1`,
120+
stderr: '',
121+
success: true,
122+
version: minimumVersions.GIT
123+
}
124+
)).to.eql({
125+
git_exists: true,
126+
git_meets_version: true,
127+
git_raw: `git version ${minimumVersions.GIT}.windows.1`
128+
});
129+
130+
expect(handleVersionResponse(
131+
'GIT',
132+
{
133+
errno: Error.CODE.OK,
134+
raw: 'git version 100.100.100.windows.1',
135+
stderr: '',
136+
success: true,
137+
version: '100.100.100'
138+
}
139+
)).to.eql({
140+
git_exists: true,
141+
git_meets_version: true,
142+
git_raw: 'git version 100.100.100.windows.1'
143+
});
144+
});
145+
146+
it('handles an LFS version check response', () => {
147+
expect(handleVersionResponse(
148+
'LFS',
149+
{
150+
errno: Error.CODE.OK,
151+
raw: `git-lfs/${minimumVersions.LFS} (GitHub; windows amd64; go 1.5.3; git 7de0397)`,
152+
stderr: '',
153+
success: true,
154+
version: minimumVersions.LFS
155+
}
156+
)).to.eql({
157+
lfs_exists: true,
158+
lfs_meets_version: true,
159+
lfs_raw: `git-lfs/${minimumVersions.LFS} (GitHub; windows amd64; go 1.5.3; git 7de0397)`
160+
});
161+
162+
expect(handleVersionResponse(
163+
'LFS',
164+
{
165+
errno: Error.CODE.OK,
166+
raw: 'git-lfs/100.100.100 (GitHub; windows amd64; go 1.5.3; git 7de0397)',
167+
stderr: '',
168+
success: true,
169+
version: '100.100.100'
170+
}
171+
)).to.eql({
172+
lfs_exists: true,
173+
lfs_meets_version: true,
174+
lfs_raw: 'git-lfs/100.100.100 (GitHub; windows amd64; go 1.5.3; git 7de0397)'
175+
});
176+
});
177+
178+
describe('when a dependency does not exist', () => {
179+
it('sets `<dependency name>_exists` to `false`', () => {
180+
expect(handleVersionResponse(
181+
'SOME_DEPENDENCY',
182+
{
183+
errno: Error.CODE.OK,
184+
raw: 'invalid output even though the exit code was presumably `0`',
185+
stderr: '',
186+
success: true,
187+
version: BAD_VERSION
188+
}
189+
)).to.eql({
190+
some_dependency_exists: false,
191+
some_dependency_meets_version: false,
192+
some_dependency_raw: 'invalid output even though the exit code was presumably `0`'
193+
});
194+
});
195+
});
196+
197+
describe('when Git is incompatible', () => {
198+
it('sets `git_meets_version` to `false`', () => {
199+
expect(handleVersionResponse(
200+
'GIT',
201+
{
202+
errno: Error.CODE.OK,
203+
raw: 'git version 0.100.100.windows.1',
204+
stderr: '',
205+
success: true,
206+
version: '0.100.100'
207+
}
208+
)).to.eql({
209+
git_exists: true,
210+
git_meets_version: false,
211+
git_raw: 'git version 0.100.100.windows.1'
212+
});
213+
});
214+
});
215+
216+
describe('when LFS is incompatible', () => {
217+
it('sets `lfs_meets_version` to `false`', () => {
218+
expect(handleVersionResponse(
219+
'LFS',
220+
{
221+
errno: Error.CODE.OK,
222+
raw: 'git-lfs/0.100.100 (GitHub; windows amd64; go 1.5.3; git 7de0397)',
223+
stderr: '',
224+
success: true,
225+
version: '0.100.100'
226+
}
227+
)).to.eql({
228+
lfs_exists: true,
229+
lfs_meets_version: false,
230+
lfs_raw: 'git-lfs/0.100.100 (GitHub; windows amd64; go 1.5.3; git 7de0397)'
231+
});
232+
});
233+
});
234+
235+
describe('when the provided version check response failed', () => {
236+
it('throws the provided response', () => {
237+
const response = {
238+
errno: BAD_CORE_RESPONSE,
239+
raw: '',
240+
stderr: 'some_dependency not found!',
241+
success: false
242+
};
243+
244+
expect(() => handleVersionResponse('SOME_DEPENDENCY', response))
245+
.throw().and.to.equal(response);
246+
});
247+
});
248+
});
249+
250+
describe('dependencyCheck', () => {
251+
it('checks the versions of Git and LFS', function () {
252+
const {
253+
sandbox
254+
} = this;
255+
256+
sandbox.stub(core, 'git').returns(Promise.resolve({
257+
stdout: 'git version 100.100.100.windows.1'
258+
}));
259+
sandbox.stub(core, 'version').returns(Promise.resolve({
260+
stdout: 'git-lfs/100.100.100 (GitHub; windows amd64; go 1.5.3; git 7de0397)'
261+
}));
262+
263+
return dependencyCheck()
264+
.then((result) => {
265+
expect(result).to.eql({
266+
errno: Error.CODE.OK,
267+
git_exists: true,
268+
git_meets_version: true,
269+
git_raw: 'git version 100.100.100.windows.1',
270+
lfs_exists: true,
271+
lfs_meets_version: true,
272+
lfs_raw: 'git-lfs/100.100.100 (GitHub; windows amd64; go 1.5.3; git 7de0397)',
273+
raw: '',
274+
stderr: '',
275+
success: true
276+
});
277+
});
278+
});
279+
});
6280
});

0 commit comments

Comments
 (0)
Please sign in to comment.