@@ -9,8 +9,8 @@ import * as os from 'os'
99import * as path from 'path'
1010import * as testutil from '../../testUtil'
1111import { fs } from '../../../shared'
12- import { findSshPath , findTypescriptCompiler , getVscodeCliPath } from '../../../shared/utilities/pathFind'
13- import { isWin } from '../../../shared/vscode/env'
12+ import { findSshPath , findTypescriptCompiler , getVscodeCliPath , tryRun } from '../../../shared/utilities/pathFind'
13+ import { isCI , isWin } from '../../../shared/vscode/env'
1414
1515describe ( 'pathFind' , function ( ) {
1616 it ( 'findTypescriptCompiler()' , async function ( ) {
@@ -53,7 +53,11 @@ describe('pathFind', function () {
5353 testutil . setEnv ( previousEnv )
5454 } )
5555
56- it ( 'first tries ssh in $PATH' , async function ( ) {
56+ it ( 'first tries ssh in $PATH (Non-Windows)' , async function ( ) {
57+ // skip on windows because ssh in path will never work with .exe extension.
58+ if ( isWin ( ) ) {
59+ return
60+ }
5761 const workspace = await testutil . createTestWorkspaceFolder ( )
5862 const fakeSshPath = path . join ( workspace . uri . fsPath , `ssh` )
5963
@@ -68,30 +72,54 @@ describe('pathFind', function () {
6872 assert . strictEqual ( secondResult , 'ssh' )
6973 } )
7074
71- it ( 'only returns executable ssh path' , async function ( ) {
72- const workspace = await testutil . createTestWorkspaceFolder ( )
73- const fakeSshPath = path . join ( workspace . uri . fsPath , `ssh` )
74- await fs . writeFile ( fakeSshPath , 'this is not executable' )
75-
76- testutil . setEnv ( testutil . envWithNewPath ( workspace . uri . fsPath ) )
77- const firstResult = await findSshPath ( false )
78- assert . notStrictEqual ( firstResult , 'ssh' )
75+ it ( 'only returns valid executable ssh path (CI + Local Non-Windows)' , async function ( ) {
76+ // In CI, we can assume Windows machines will have ssh.
77+ if ( ! isCI ( ) ) {
78+ return
79+ }
80+ // On local non-windows, we can overwrite path and create our own executable to find.
81+ if ( ! isWin ( ) ) {
82+ const workspace = await testutil . createTestWorkspaceFolder ( )
83+ const fakeSshPath = path . join ( workspace . uri . fsPath , `ssh` )
84+
85+ testutil . setEnv ( testutil . envWithNewPath ( workspace . uri . fsPath ) )
86+
87+ await testutil . createExecutableFile ( fakeSshPath , '' )
88+ }
89+
90+ const ssh = await findSshPath ( false )
91+ assert . ok ( ssh )
92+ const result = await tryRun ( ssh , [ ] )
93+ assert . ok ( result )
7994 } )
8095
81- it ( 'caches result from previous runs' , async function ( ) {
96+ it ( 'caches result from previous runs (CI + Local Non-Windows)' , async function ( ) {
97+ // In CI, we can assume Windows machines will have ssh.
98+ if ( ! isCI ( ) ) {
99+ return
100+ }
101+ // On local non-windows, we can overwrite path and create our own executable to find.
82102 const workspace = await testutil . createTestWorkspaceFolder ( )
83- const fakeSshPath = path . join ( workspace . uri . fsPath , ` ssh` )
84- await testutil . createExecutableFile ( fakeSshPath , '' )
103+ // We move the ssh to a temp directory temporarily to test if cache works.
104+ const tempLocation = path . join ( workspace . uri . fsPath , 'temp-ssh ' )
85105
86- testutil . setEnv ( testutil . envWithNewPath ( workspace . uri . fsPath ) )
87- const firstResult = await findSshPath ( true )
106+ if ( ! isWin ( ) ) {
107+ const fakeSshPath = path . join ( workspace . uri . fsPath , `ssh` )
108+
109+ testutil . setEnv ( testutil . envWithNewPath ( workspace . uri . fsPath ) )
110+
111+ await testutil . createExecutableFile ( fakeSshPath , '' )
112+ }
113+
114+ const ssh1 = await findSshPath ( true )
115+
116+ await fs . rename ( ssh1 ! , tempLocation )
88117
89- await fs . delete ( fakeSshPath )
118+ const ssh2 = await findSshPath ( true )
90119
91- const secondResult = await findSshPath ( true )
120+ assert . strictEqual ( ssh1 , ssh2 )
92121
93- assert . strictEqual ( firstResult , secondResult )
94- assert . ok ( secondResult )
122+ await fs . rename ( tempLocation , ssh1 ! )
95123 } )
96124 } )
97125} )
0 commit comments