@@ -7,16 +7,15 @@ import assert from 'assert'
77import * as vscode from 'vscode'
88import * as os from 'os'
99import * as path from 'path'
10-
1110import * as testutil from '../../testUtil'
12- import { findTypescriptCompiler , getVscodeCliPath } from '../../../shared/utilities/pathFind'
1311import { fs } from '../../../shared'
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 ( ) {
17- const iswin = process . platform === 'win32'
1817 const workspace = vscode . workspace . workspaceFolders ! [ 0 ]
19- const tscNodemodules = path . join ( workspace . uri . fsPath , `foo/bar/node_modules/.bin/tsc${ iswin ? '.cmd' : '' } ` )
18+ const tscNodemodules = path . join ( workspace . uri . fsPath , `foo/bar/node_modules/.bin/tsc${ isWin ( ) ? '.cmd' : '' } ` )
2019 await fs . delete ( tscNodemodules , { force : true } )
2120
2221 // The test workspace normally doesn't have node_modules so this will
@@ -42,4 +41,90 @@ describe('pathFind', function () {
4241 const regex = / b i n [ \\ \/ ] ( c o d e | c o d e - i n s i d e r s ) $ /
4342 assert . ok ( regex . test ( vscPath ) , `expected regex ${ regex } to match: "${ vscPath } "` )
4443 } )
44+
45+ describe ( 'findSshPath' , function ( ) {
46+ let previousPath : string | undefined
47+
48+ beforeEach ( function ( ) {
49+ previousPath = process . env . PATH
50+ } )
51+
52+ afterEach ( function ( ) {
53+ process . env . PATH = previousPath
54+ } )
55+
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+ }
61+ const workspace = await testutil . createTestWorkspaceFolder ( )
62+ const fakeSshPath = path . join ( workspace . uri . fsPath , `ssh` )
63+
64+ process . env . PATH = workspace . uri . fsPath
65+ const firstResult = await findSshPath ( false )
66+
67+ await testutil . createExecutableFile ( fakeSshPath , '' )
68+
69+ const secondResult = await findSshPath ( false )
70+
71+ assert . notStrictEqual ( firstResult , secondResult )
72+ assert . strictEqual ( secondResult , 'ssh' )
73+ } )
74+
75+ it ( 'only returns valid executable ssh path (Non-Windows)' , async function ( ) {
76+ if ( isWin ( ) ) {
77+ return
78+ }
79+ // On non-windows, we can overwrite path and create our own executable to find.
80+ const workspace = await testutil . createTestWorkspaceFolder ( )
81+ const fakeSshPath = path . join ( workspace . uri . fsPath , `ssh` )
82+
83+ process . env . PATH = workspace . uri . fsPath
84+
85+ await testutil . createExecutableFile ( fakeSshPath , '' )
86+
87+ const ssh = await findSshPath ( false )
88+ assert . ok ( ssh )
89+ const result = await tryRun ( ssh , [ ] , 'yes' )
90+ assert . ok ( result )
91+ } )
92+
93+ it ( 'caches result from previous runs (Non-Windows)' , async function ( ) {
94+ if ( isWin ( ) ) {
95+ return
96+ }
97+ // On non-windows, we can overwrite path and create our own executable to find.
98+ const workspace = await testutil . createTestWorkspaceFolder ( )
99+ // We move the ssh to a temp directory temporarily to test if cache works.
100+ const fakeSshPath = path . join ( workspace . uri . fsPath , `ssh` )
101+
102+ process . env . PATH = workspace . uri . fsPath
103+
104+ await testutil . createExecutableFile ( fakeSshPath , '' )
105+
106+ const ssh1 = ( await findSshPath ( true ) ) !
107+
108+ await fs . delete ( fakeSshPath )
109+
110+ const ssh2 = await findSshPath ( true )
111+
112+ assert . strictEqual ( ssh1 , ssh2 )
113+ } )
114+
115+ it ( 'finds valid executable path (Windows CI)' , async function ( ) {
116+ // Don't want to be messing with System32 on peoples local machines.
117+ if ( ! isWin ( ) || ! isCI ( ) ) {
118+ return
119+ }
120+ const expectedPathInCI = 'C:/Windows/System32/OpenSSH/ssh.exe'
121+
122+ if ( ! ( await fs . exists ( expectedPathInCI ) ) ) {
123+ await testutil . createExecutableFile ( expectedPathInCI , '' )
124+ }
125+ const ssh = ( await findSshPath ( true ) ) !
126+ const result = await tryRun ( ssh , [ '-G' , 'x' ] , 'noresult' )
127+ assert . ok ( result )
128+ } )
129+ } )
45130} )
0 commit comments