@@ -9,7 +9,7 @@ import * as os from 'os'
99import * as path from 'path'
1010import * as testutil from '../../testUtil'
1111import { fs } from '../../../shared'
12- import { findTypescriptCompiler , getVscodeCliPath } from '../../../shared/utilities/pathFind'
12+ import { findSshPath , findTypescriptCompiler , getVscodeCliPath } from '../../../shared/utilities/pathFind'
1313
1414function isWin ( ) : boolean {
1515 return process . platform === 'win32'
@@ -45,7 +45,49 @@ describe('pathFind', function () {
4545 assert . ok ( regex . test ( vscPath ) , `expected regex ${ regex } to match: "${ vscPath } "` )
4646 } )
4747
48- // describe('findSshPath', function () {
48+ describe ( 'findSshPath' , function ( ) {
49+ it ( 'first tries ssh in $PATH' , async function ( ) {
50+ const workspace = await testutil . createTestWorkspaceFolder ( )
51+ const fakeSshPath = path . join ( workspace . uri . fsPath , `ssh${ isWin ( ) ? '.cmd' : '' } ` )
4952
50- // })
53+ await testutil . withEnvPath ( workspace . uri . fsPath , async ( ) => {
54+ const firstResult = await findSshPath ( false )
55+
56+ await testutil . createExecutableFile ( fakeSshPath , 'echo "this is ssh"' )
57+
58+ const secondResult = await findSshPath ( false )
59+
60+ assert . notStrictEqual ( firstResult , secondResult )
61+ assert . strictEqual ( secondResult , 'ssh' )
62+ } )
63+ } )
64+
65+ it ( 'only returns executable ssh path' , async function ( ) {
66+ const workspace = await testutil . createTestWorkspaceFolder ( )
67+ const fakeSshPath = path . join ( workspace . uri . fsPath , `ssh${ isWin ( ) ? '.cmd' : '' } ` )
68+ await fs . writeFile ( fakeSshPath , 'this is not executable' )
69+
70+ await testutil . withEnvPath ( workspace . uri . fsPath , async ( ) => {
71+ const firstResult = await findSshPath ( false )
72+ assert . notStrictEqual ( firstResult , 'ssh' )
73+ } )
74+ } )
75+
76+ it ( 'caches result from previous runs' , async function ( ) {
77+ const workspace = await testutil . createTestWorkspaceFolder ( )
78+ const fakeSshPath = path . join ( workspace . uri . fsPath , `ssh${ isWin ( ) ? '.cmd' : '' } ` )
79+ await testutil . createExecutableFile ( fakeSshPath , 'echo "this is ssh"' )
80+
81+ await testutil . withEnvPath ( workspace . uri . fsPath , async ( ) => {
82+ const firstResult = await findSshPath ( true )
83+
84+ await fs . delete ( fakeSshPath )
85+
86+ const secondResult = await findSshPath ( true )
87+
88+ assert . strictEqual ( firstResult , secondResult )
89+ assert . strictEqual ( secondResult , 'ssh' )
90+ } )
91+ } )
92+ } )
5193} )
0 commit comments