package Ġclub . ge ek 6 6 . command . executor Ċ Ċ import Ġarrow . core . Either Ċ import Ġarrow . core . N el Ċ import Ġarrow . core . k Ċ import Ġclub . ge ek 6 6 . command . executor . local . Local Request Specific Ċ import Ġclub . ge ek 6 6 . command . executor . ssh . Ssh Connection Info Ċ import Ġclub . ge ek 6 6 . command . executor . ssh . Ssh Credential Ċ import Ġclub . ge ek 6 6 . command . executor . ssh . Ssh Request Specific Ċ import Ġjava . io . File Ċ import Ġjava . nio . file . Files Ċ import Ġjava . nio . file . Path Ċ import Ġkotlin . test . Test Ċ import Ġkotlin . test . assertEquals Ċ import Ġkotlin . test . assertTrue ĊĊ Ċ /** Ċ Ġ* Ġ@ author : Ġorange Ċ Ġ* Ġ@ date : Ġ 2 0 2 0 / 1 1 / 2 0 Ċ Ġ* Ġ@ time : Ġä¸ĭåįĪ 6 : 5 2 Ċ Ġ* Ġ@ copyright : ĠCopyright Ġ 2 0 2 0 Ġby Ġorange Ċ Ġ*/ Ċ class ĠCommand Exec Test Ġ{ ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Local () Ġ{ Ċĉ ĉ // Ġtest Ġecho Ġenv Ċĉ ĉ Command Exec . local . exec Ġ{ Ċĉĉ ĉ Local Request Specific ( Ċĉĉĉ ĉ environments Ġ= Ġmap Of (" NAME " Ġto Ġ" TEST "). k (), Ċĉĉĉ ĉ commands Ġ= ĠN el (" bash ", Ġ"- c ", Ġ" echo Ġ${ '$ '} NAME "), Ċĉĉĉ ĉ work Dir Ġ= Ġ"/ tmp " Ċĉĉ ĉ ) Ċĉ ĉ }. let Ġ{ Ċĉĉ ĉ when Ġ( it ) Ġ{ Ċĉĉĉ ĉ is ĠEither . Right Ġ-> Ġ{ Ċĉĉĉĉ ĉ assertEquals (" TEST \ n ", Ġit . b . response . std Out ) Ċĉĉĉ ĉ } Ċĉĉĉ ĉ else Ġ-> Ġthrow ĠIllegalArgumentException ( it . toString ()) Ċĉĉ ĉ } Ċĉ ĉ } ĊĊĉ ĉ Files . delete IfExists ( Path . of ("/ tmp / 1 2 3 ")) Ċĉ ĉ // Ġtest Ġtouch Ġfile Ċĉ ĉ Command Exec . local . exec Ġ{ Ċĉĉ ĉ Local Request Specific ( Ċĉĉĉ ĉ environments Ġ= Ġempty Map < String , ĠString >(). k (), Ċĉĉĉ ĉ commands Ġ= ĠN el (" touch ", Ġ" 1 2 3 "), Ċĉĉĉ ĉ work Dir Ġ= Ġ"/ tmp " Ċĉĉ ĉ ) Ċĉ ĉ }. let Ġ{ Ċĉĉ ĉ when Ġ( it ) Ġ{ Ċĉĉĉ ĉ is ĠEither . Right Ġ-> ĠassertEquals ( 0 , Ġit . b . response . exit Code ) Ċĉĉĉ ĉ else Ġ-> Ġthrow ĠIllegalArgumentException ( it . toString ()) Ċĉĉ ĉ } Ċĉ ĉ } Ċĉ ĉ assertTrue ( Files . exists ( Path . of ("/ tmp / 1 2 3 "))) Ċ ĉ } ĊĊ ĉ @ Test Ċ ĉ fun Ġtest Ssh () Ġ{ Ċĉ ĉ // Ġonly Ġsupport Ġenvironment Ġthat Ġname Ġstart Ġwith ĠLC ( ssh Ġsecurity Ġconfig ) Ċĉ ĉ // Ġsee Ġhttps :// stackoverflow . com / questions / 9 3 6 6 9 1 4 / setting - environment - variables - on - a - js ch - chan ne lex ec ? rq = 1 ĠPa Å Ń lo ĠE ber mann 's Ġanswer Ċĉ ĉ Command Exec . ssh . exec Ġ{ Ċĉĉ ĉ Ssh Request Specific ( Ċĉĉĉ ĉ environments Ġ= Ġmap Of (" LC _ TEST " Ġto Ġ" Jack "). k (), Ċĉĉĉ ĉ commands Ġ= ĠN el (" echo ", Ġ"${ '$ '} LC _ TEST "), Ċĉĉĉ ĉ connection Info Ġ= ĠSsh Connection Info ( user Ġ= Ġ" orange "), Ċĉĉĉ ĉ credential Ġ= ĠSsh Credential . PrivateKey Credential ( Ċĉĉĉĉ ĉ privateKey Ġ= ĠFile ("/ home / orange /. ssh / id _ rsa "). read Text () Ċĉĉĉ ĉ ) Ċĉĉ ĉ ) Ċĉ ĉ }. let Ġ{ Ċĉĉ ĉ when Ġ( it ) Ġ{ Ċĉĉĉ ĉ is ĠEither . Right Ġ-> Ġ{ Ċĉĉĉĉ ĉ // Ġend Ġwith Ġ\ r \ n Ċĉĉĉĉ ĉ assertEquals (" Jack \ r \ n ", Ġit . b . response . std Out ) Ċĉĉĉ ĉ } ĊĊĉĉĉ ĉ else Ġ-> Ġthrow ĠIllegalArgumentException () Ċĉĉ ĉ } Ċĉ ĉ } Ċ ĉ } Ċ Ċ }