Skip to content

Commit 43f9f24

Browse files
committed
try a more advanced parsing scheme
1 parent cc03cb0 commit 43f9f24

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ function echoEnvVarsCmd(varNames: string[]) {
4242
return `echo "${varNames.map(toShell).join(' ')}"`
4343
}
4444

45+
function parseOutput(output: string) {
46+
// On Windows the final line is the result of the script.
47+
return isWin() ? output.split('\n').at(-1) : output
48+
}
49+
4550
describe('testSshConnection', function () {
4651
let testWorkspace: WorkspaceFolder
4752
let sshPath: string
@@ -70,7 +75,8 @@ describe('testSshConnection', function () {
7075
assert.strictEqual(r.stdout, 'yes')
7176
await createExecutableFile(sshPath, echoEnvVarsCmd(['UNDEFINED_VAR']))
7277
const r2 = await testSshConnection(process, 'localhost', sshPath, 'test-user', session)
73-
assert.strictEqual(r2.stdout, '')
78+
79+
assert.strictEqual(parseOutput(r2.stdout), '')
7480
})
7581

7682
it('injects new session into env', async function () {
@@ -93,14 +99,17 @@ describe('testSshConnection', function () {
9399

94100
await createExecutableFile(sshPath, echoEnvVarsCmd(['SESSION_ID', 'STREAM_URL', 'TOKEN']))
95101
const r = await testSshConnection(process, 'localhost', sshPath, 'test-user', newSession)
96-
assert.strictEqual(r.stdout, `${newSession.SessionId} ${newSession.StreamUrl} ${newSession.TokenValue}`)
102+
assert.strictEqual(
103+
parseOutput(r.stdout),
104+
`${newSession.SessionId} ${newSession.StreamUrl} ${newSession.TokenValue}`
105+
)
97106
})
98107

99108
it('passes proper args to the ssh invoke', async function () {
100-
const executableFileContent = isWin() ? `echo "$Args[0] $Args[1]"` : `echo "$1 $2"`
109+
const executableFileContent = isWin() ? `echo "%1 %2"` : `echo "$1 $2"`
101110
const process = createBoundProcess(async () => ({}))
102111
await createExecutableFile(sshPath, executableFileContent)
103112
const r = await testSshConnection(process, 'localhost', sshPath, 'test-user', {} as SSM.StartSessionResponse)
104-
assert.strictEqual(r.stdout, '-T test-user@localhost')
113+
assert.strictEqual(parseOutput(r.stdout), '-T test-user@localhost')
105114
})
106115
})

0 commit comments

Comments
 (0)