|
1 | 1 | 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__; |
4 | 33 |
|
5 | 34 | 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 | + }); |
6 | 280 | });
|
0 commit comments