|
5 | 5 |
|
6 | 6 | import assert from 'assert' |
7 | 7 | import * as path from 'path' |
8 | | -import { installCli } from '../../../shared/utilities/cliUtils' |
| 8 | +import sinon from 'sinon' |
| 9 | +import { installCli, updateAwsCli } from '../../../shared/utilities/cliUtils' |
9 | 10 | import globals from '../../../shared/extensionGlobals' |
10 | 11 | import { ChildProcess } from '../../../shared/utilities/processUtils' |
11 | 12 | import { SeverityLevel } from '../vscode/message' |
12 | 13 | import { assertTelemetryCurried } from '../../testUtil' |
13 | 14 | import { getTestWindow } from '../../shared/vscode/window' |
14 | 15 | import { fs } from '../../../shared' |
| 16 | +import { getOpenExternalStub } from '../../globalSetup.test' |
15 | 17 |
|
16 | 18 | describe('cliUtils', async function () { |
| 19 | + let sandbox: sinon.SinonSandbox |
| 20 | + |
| 21 | + beforeEach(function () { |
| 22 | + sandbox = sinon.createSandbox() |
| 23 | + }) |
| 24 | + |
17 | 25 | afterEach(async function () { |
| 26 | + sandbox.restore() |
18 | 27 | await fs.delete(path.join(globals.context.globalStorageUri.fsPath, 'tools'), { recursive: true, force: true }) |
19 | 28 | }) |
20 | 29 |
|
@@ -61,4 +70,78 @@ describe('cliUtils', async function () { |
61 | 70 | }) |
62 | 71 | }) |
63 | 72 | }) |
| 73 | + |
| 74 | + describe('updateAwsCli', function () { |
| 75 | + it('cancels when user does not confirm update', async function () { |
| 76 | + getTestWindow().onDidShowMessage((m) => m.close()) |
| 77 | + |
| 78 | + await assert.rejects(() => updateAwsCli(), /cancelled/) |
| 79 | + }) |
| 80 | + |
| 81 | + it('installs CLI and shows path when user confirms', async function () { |
| 82 | + let messageCount = 0 |
| 83 | + getTestWindow().onDidShowMessage((m) => { |
| 84 | + messageCount++ |
| 85 | + if (messageCount === 1 && m.items.some((i) => i.title === 'Update')) { |
| 86 | + m.selectItem('Update') |
| 87 | + } else if (m.message.includes('not supported')) { |
| 88 | + // Toolkit shows "Auto install of AWS CLI is not supported on your platform" |
| 89 | + // with "Install manually..." button. We close this message to simulate the user dismissing it. |
| 90 | + m.close() |
| 91 | + } |
| 92 | + }) |
| 93 | + sandbox.stub(ChildProcess.prototype, 'run').resolves({ |
| 94 | + exitCode: 0, |
| 95 | + stdout: '/usr/local/bin/aws\n', |
| 96 | + stderr: '', |
| 97 | + } as any) |
| 98 | + |
| 99 | + if (process.platform === 'linux') { |
| 100 | + await assert.rejects(() => updateAwsCli(), /cancelled/) |
| 101 | + } else { |
| 102 | + const result = await updateAwsCli() |
| 103 | + assert.ok(result) |
| 104 | + const messages = getTestWindow().shownMessages |
| 105 | + assert.ok(messages.some((m) => m.message.includes('/usr/local/bin/aws'))) |
| 106 | + } |
| 107 | + }) |
| 108 | + |
| 109 | + it('opens manual install link when user selects "Install manually" on Linux', async function () { |
| 110 | + let messageCount = 0 |
| 111 | + const openExternalStub = getOpenExternalStub().resolves(true) |
| 112 | + |
| 113 | + getTestWindow().onDidShowMessage((m) => { |
| 114 | + messageCount++ |
| 115 | + if (messageCount === 1 && m.items.some((i) => i.title === 'Update')) { |
| 116 | + m.selectItem('Update') |
| 117 | + } else if (m.message.includes('not supported')) { |
| 118 | + // Linux: no installer source defined, so auto-install shows "not supported" message. |
| 119 | + // Simulate user clicking "Install manually..." button |
| 120 | + const manualInstallButton = m.items.find((i) => i.title === 'Install manually...') |
| 121 | + if (manualInstallButton) { |
| 122 | + m.selectItem(manualInstallButton.title) |
| 123 | + } |
| 124 | + } |
| 125 | + }) |
| 126 | + |
| 127 | + if (process.platform === 'linux') { |
| 128 | + await assert.rejects(() => updateAwsCli(), /cancelled/) |
| 129 | + |
| 130 | + // Verify the manual install link was opened |
| 131 | + assert.ok(openExternalStub.calledOnce) |
| 132 | + const openedUrl = openExternalStub.firstCall.args.toString() |
| 133 | + assert.ok(openedUrl.includes('getting-started-install.html')) |
| 134 | + } else { |
| 135 | + // Non-Linux platforms should succeed (existing behavior) |
| 136 | + sandbox.stub(ChildProcess.prototype, 'run').resolves({ |
| 137 | + exitCode: 0, |
| 138 | + stdout: '/usr/local/bin/aws', |
| 139 | + stderr: '', |
| 140 | + } as any) |
| 141 | + |
| 142 | + const result = await updateAwsCli() |
| 143 | + assert.ok(result) |
| 144 | + } |
| 145 | + }) |
| 146 | + }) |
64 | 147 | }) |
0 commit comments