|
| 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 | +}); |
0 commit comments