Skip to content

Commit 7c2018c

Browse files
committed
test: add error code to test connection failure
1 parent a512982 commit 7c2018c

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

packages/core/src/awsService/ec2/model.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
SshError,
2727
startSshAgent,
2828
startVscodeRemote,
29-
testSshConnection,
29+
testSsmConnection,
3030
} from '../../shared/extensions/ssh'
3131
import { getLogger } from '../../shared/logger/logger'
3232
import { CancellationError, Timeout } from '../../shared/utilities/timeoutUtils'
@@ -36,7 +36,7 @@ import { SshKeyPair } from './sshKeyPair'
3636
import { Ec2SessionTracker } from './remoteSessionManager'
3737
import { getEc2SsmEnv } from './utils'
3838

39-
export type Ec2ConnectErrorCode = 'EC2SSMStatus' | 'EC2SSMPermission' | 'EC2SSMConnect' | 'EC2SSMAgentStatus'
39+
export type Ec2ConnectErrorCode = 'EC2SSMStatus' | 'EC2SSMPermission' | 'EC2SSMTestConnect' | 'EC2SSMAgentStatus'
4040

4141
export interface Ec2RemoteEnv extends VscodeRemoteConnection {
4242
selection: Ec2Selection
@@ -200,7 +200,7 @@ export class Ec2Connecter implements vscode.Disposable {
200200
const remoteEnv = await this.prepareEc2RemoteEnvWithProgress(selection, remoteUser)
201201
const testSession = await this.ssmClient.startSession(selection.instanceId, 'AWS-StartSSHSession')
202202
try {
203-
await testSshConnection(
203+
await testSsmConnection(
204204
remoteEnv.SessionProcess,
205205
remoteEnv.hostname,
206206
remoteEnv.sshPath,
@@ -216,7 +216,7 @@ export class Ec2Connecter implements vscode.Disposable {
216216
)
217217
} catch (err) {
218218
const message = err instanceof SshError ? 'Testing SSH connection to instance failed' : ''
219-
this.throwConnectionError(message, selection, err as Error)
219+
this.throwConnectionError(message, selection, { ...(err as Error), code: 'EC2SSMTestConnect' })
220220
} finally {
221221
await this.ssmClient.terminateSession(testSession)
222222
}

packages/core/src/shared/extensions/ssh.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export class RemoteSshSettings extends Settings.define('remote.SSH', remoteSshTy
130130
}
131131
}
132132

133-
export async function testSshConnection(
133+
export async function testSsmConnection(
134134
ProcessClass: typeof ChildProcess,
135135
hostname: string,
136136
sshPath: string,
@@ -150,7 +150,7 @@ export async function testSshConnection(
150150
})
151151
return result
152152
} catch (error) {
153-
throw new SshError('SSH connection test failed', { cause: error as Error })
153+
throw new SshError('SSH connection test failed', { cause: error as Error, code: 'SSMTestConnectionFailed' })
154154
}
155155
}
156156

packages/core/src/test/shared/extensions/ssh.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
import * as assert from 'assert'
66
import { ChildProcess } from '../../../shared/utilities/processUtils'
7-
import { startSshAgent, testSshConnection } from '../../../shared/extensions/ssh'
7+
import { startSshAgent, testSsmConnection } from '../../../shared/extensions/ssh'
88
import { createBoundProcess } from '../../../shared/remoteSession'
99
import { createExecutableFile, createTestWorkspaceFolder } from '../../testUtil'
1010
import { WorkspaceFolder } from 'vscode'
@@ -74,7 +74,7 @@ describe('testSshConnection', function () {
7474
} as SSM.StartSessionResponse
7575

7676
await createExecutableFile(sshPath, echoEnvVarsCmd(['MY_VAR']))
77-
const r = await testSshConnection(process, 'localhost', sshPath, 'test-user', session)
77+
const r = await testSsmConnection(process, 'localhost', sshPath, 'test-user', session)
7878
assertOutputContains(r.stdout, 'yes')
7979
})
8080

@@ -97,15 +97,15 @@ describe('testSshConnection', function () {
9797
const process = createBoundProcess(envProvider)
9898

9999
await createExecutableFile(sshPath, echoEnvVarsCmd(['SESSION_ID', 'STREAM_URL', 'TOKEN']))
100-
const r = await testSshConnection(process, 'localhost', sshPath, 'test-user', newSession)
100+
const r = await testSsmConnection(process, 'localhost', sshPath, 'test-user', newSession)
101101
assertOutputContains(r.stdout, `${newSession.SessionId} ${newSession.StreamUrl} ${newSession.TokenValue}`)
102102
})
103103

104104
it('passes proper args to the ssh invoke', async function () {
105105
const executableFileContent = isWin() ? `echo "%1 %2"` : `echo "$1 $2"`
106106
const process = createBoundProcess(async () => ({}))
107107
await createExecutableFile(sshPath, executableFileContent)
108-
const r = await testSshConnection(process, 'localhost', sshPath, 'test-user', {} as SSM.StartSessionResponse)
108+
const r = await testSsmConnection(process, 'localhost', sshPath, 'test-user', {} as SSM.StartSessionResponse)
109109
assertOutputContains(r.stdout, '-T')
110110
assertOutputContains(r.stdout, 'test-user@localhost')
111111
})

0 commit comments

Comments
 (0)