@@ -8,6 +8,7 @@ const mockFileSystem = {
88 readFile : vi . fn ( ) ,
99 mkdir : vi . fn ( ) ,
1010 writeFile : vi . fn ( ) ,
11+ rename : vi . fn ( ) ,
1112}
1213
1314afterEach ( ( ) => {
@@ -38,7 +39,12 @@ Host coder-vscode--*
3839# --- END CODER VSCODE ---`
3940
4041 expect ( mockFileSystem . readFile ) . toBeCalledWith ( sshFilePath , expect . anything ( ) )
41- expect ( mockFileSystem . writeFile ) . toBeCalledWith ( sshFilePath , expectedOutput , expect . anything ( ) )
42+ expect ( mockFileSystem . writeFile ) . toBeCalledWith (
43+ expect . stringContaining ( sshFilePath ) ,
44+ expectedOutput ,
45+ expect . anything ( ) ,
46+ )
47+ expect ( mockFileSystem . rename ) . toBeCalledWith ( expect . stringContaining ( sshFilePath + "." ) , sshFilePath )
4248} )
4349
4450it ( "creates a new file and adds the config" , async ( ) => {
@@ -65,7 +71,12 @@ Host coder-vscode.dev.coder.com--*
6571# --- END CODER VSCODE dev.coder.com ---`
6672
6773 expect ( mockFileSystem . readFile ) . toBeCalledWith ( sshFilePath , expect . anything ( ) )
68- expect ( mockFileSystem . writeFile ) . toBeCalledWith ( sshFilePath , expectedOutput , expect . anything ( ) )
74+ expect ( mockFileSystem . writeFile ) . toBeCalledWith (
75+ expect . stringContaining ( sshFilePath ) ,
76+ expectedOutput ,
77+ expect . anything ( ) ,
78+ )
79+ expect ( mockFileSystem . rename ) . toBeCalledWith ( expect . stringContaining ( sshFilePath + "." ) , sshFilePath )
6980} )
7081
7182it ( "adds a new coder config in an existent SSH configuration" , async ( ) => {
@@ -100,10 +111,11 @@ Host coder-vscode.dev.coder.com--*
100111 UserKnownHostsFile /dev/null
101112# --- END CODER VSCODE dev.coder.com ---`
102113
103- expect ( mockFileSystem . writeFile ) . toBeCalledWith ( sshFilePath , expectedOutput , {
114+ expect ( mockFileSystem . writeFile ) . toBeCalledWith ( expect . stringContaining ( sshFilePath ) , expectedOutput , {
104115 encoding : "utf-8" ,
105116 mode : 384 ,
106117 } )
118+ expect ( mockFileSystem . rename ) . toBeCalledWith ( expect . stringContaining ( sshFilePath + "." ) , sshFilePath )
107119} )
108120
109121it ( "updates an existent coder config" , async ( ) => {
@@ -164,10 +176,11 @@ Host coder-vscode.dev-updated.coder.com--*
164176Host *
165177 SetEnv TEST=1`
166178
167- expect ( mockFileSystem . writeFile ) . toBeCalledWith ( sshFilePath , expectedOutput , {
179+ expect ( mockFileSystem . writeFile ) . toBeCalledWith ( expect . stringContaining ( sshFilePath ) , expectedOutput , {
168180 encoding : "utf-8" ,
169181 mode : 384 ,
170182 } )
183+ expect ( mockFileSystem . rename ) . toBeCalledWith ( expect . stringContaining ( sshFilePath + "." ) , sshFilePath )
171184} )
172185
173186it ( "does not remove deployment-unaware SSH config and adds the new one" , async ( ) => {
@@ -209,10 +222,11 @@ Host coder-vscode.dev.coder.com--*
209222 UserKnownHostsFile /dev/null
210223# --- END CODER VSCODE dev.coder.com ---`
211224
212- expect ( mockFileSystem . writeFile ) . toBeCalledWith ( sshFilePath , expectedOutput , {
225+ expect ( mockFileSystem . writeFile ) . toBeCalledWith ( expect . stringContaining ( sshFilePath ) , expectedOutput , {
213226 encoding : "utf-8" ,
214227 mode : 384 ,
215228 } )
229+ expect ( mockFileSystem . rename ) . toBeCalledWith ( expect . stringContaining ( sshFilePath + "." ) , sshFilePath )
216230} )
217231
218232it ( "it does not remove a user-added block that only matches the host of an old coder SSH config" , async ( ) => {
@@ -243,10 +257,11 @@ Host coder-vscode.dev.coder.com--*
243257 UserKnownHostsFile /dev/null
244258# --- END CODER VSCODE dev.coder.com ---`
245259
246- expect ( mockFileSystem . writeFile ) . toBeCalledWith ( sshFilePath , expectedOutput , {
260+ expect ( mockFileSystem . writeFile ) . toBeCalledWith ( expect . stringContaining ( sshFilePath ) , expectedOutput , {
247261 encoding : "utf-8" ,
248262 mode : 384 ,
249263 } )
264+ expect ( mockFileSystem . rename ) . toBeCalledWith ( expect . stringContaining ( sshFilePath + "." ) , sshFilePath )
250265} )
251266
252267it ( "throws an error if there is a mismatched start and end block count" , async ( ) => {
@@ -477,10 +492,11 @@ Host afterconfig
477492 LogLevel : "ERROR" ,
478493 } )
479494
480- expect ( mockFileSystem . writeFile ) . toBeCalledWith ( sshFilePath , expectedOutput , {
495+ expect ( mockFileSystem . writeFile ) . toBeCalledWith ( expect . stringContaining ( sshFilePath ) , expectedOutput , {
481496 encoding : "utf-8" ,
482497 mode : 384 ,
483498 } )
499+ expect ( mockFileSystem . rename ) . toBeCalledWith ( expect . stringContaining ( sshFilePath + "." ) , sshFilePath )
484500} )
485501
486502it ( "override values" , async ( ) => {
@@ -521,5 +537,10 @@ Host coder-vscode.dev.coder.com--*
521537# --- END CODER VSCODE dev.coder.com ---`
522538
523539 expect ( mockFileSystem . readFile ) . toBeCalledWith ( sshFilePath , expect . anything ( ) )
524- expect ( mockFileSystem . writeFile ) . toBeCalledWith ( sshFilePath , expectedOutput , expect . anything ( ) )
540+ expect ( mockFileSystem . writeFile ) . toBeCalledWith (
541+ expect . stringContaining ( sshFilePath ) ,
542+ expectedOutput ,
543+ expect . anything ( ) ,
544+ )
545+ expect ( mockFileSystem . rename ) . toBeCalledWith ( expect . stringContaining ( sshFilePath + "." ) , sshFilePath )
525546} )
0 commit comments