@@ -8,6 +8,7 @@ const mockFileSystem = {
8
8
readFile : vi . fn ( ) ,
9
9
mkdir : vi . fn ( ) ,
10
10
writeFile : vi . fn ( ) ,
11
+ rename : vi . fn ( ) ,
11
12
}
12
13
13
14
afterEach ( ( ) => {
@@ -38,7 +39,12 @@ Host coder-vscode--*
38
39
# --- END CODER VSCODE ---`
39
40
40
41
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 )
42
48
} )
43
49
44
50
it ( "creates a new file and adds the config" , async ( ) => {
@@ -65,7 +71,12 @@ Host coder-vscode.dev.coder.com--*
65
71
# --- END CODER VSCODE dev.coder.com ---`
66
72
67
73
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 )
69
80
} )
70
81
71
82
it ( "adds a new coder config in an existent SSH configuration" , async ( ) => {
@@ -100,10 +111,11 @@ Host coder-vscode.dev.coder.com--*
100
111
UserKnownHostsFile /dev/null
101
112
# --- END CODER VSCODE dev.coder.com ---`
102
113
103
- expect ( mockFileSystem . writeFile ) . toBeCalledWith ( sshFilePath , expectedOutput , {
114
+ expect ( mockFileSystem . writeFile ) . toBeCalledWith ( expect . stringContaining ( sshFilePath ) , expectedOutput , {
104
115
encoding : "utf-8" ,
105
116
mode : 384 ,
106
117
} )
118
+ expect ( mockFileSystem . rename ) . toBeCalledWith ( expect . stringContaining ( sshFilePath + "." ) , sshFilePath )
107
119
} )
108
120
109
121
it ( "updates an existent coder config" , async ( ) => {
@@ -164,10 +176,11 @@ Host coder-vscode.dev-updated.coder.com--*
164
176
Host *
165
177
SetEnv TEST=1`
166
178
167
- expect ( mockFileSystem . writeFile ) . toBeCalledWith ( sshFilePath , expectedOutput , {
179
+ expect ( mockFileSystem . writeFile ) . toBeCalledWith ( expect . stringContaining ( sshFilePath ) , expectedOutput , {
168
180
encoding : "utf-8" ,
169
181
mode : 384 ,
170
182
} )
183
+ expect ( mockFileSystem . rename ) . toBeCalledWith ( expect . stringContaining ( sshFilePath + "." ) , sshFilePath )
171
184
} )
172
185
173
186
it ( "does not remove deployment-unaware SSH config and adds the new one" , async ( ) => {
@@ -209,10 +222,11 @@ Host coder-vscode.dev.coder.com--*
209
222
UserKnownHostsFile /dev/null
210
223
# --- END CODER VSCODE dev.coder.com ---`
211
224
212
- expect ( mockFileSystem . writeFile ) . toBeCalledWith ( sshFilePath , expectedOutput , {
225
+ expect ( mockFileSystem . writeFile ) . toBeCalledWith ( expect . stringContaining ( sshFilePath ) , expectedOutput , {
213
226
encoding : "utf-8" ,
214
227
mode : 384 ,
215
228
} )
229
+ expect ( mockFileSystem . rename ) . toBeCalledWith ( expect . stringContaining ( sshFilePath + "." ) , sshFilePath )
216
230
} )
217
231
218
232
it ( "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--*
243
257
UserKnownHostsFile /dev/null
244
258
# --- END CODER VSCODE dev.coder.com ---`
245
259
246
- expect ( mockFileSystem . writeFile ) . toBeCalledWith ( sshFilePath , expectedOutput , {
260
+ expect ( mockFileSystem . writeFile ) . toBeCalledWith ( expect . stringContaining ( sshFilePath ) , expectedOutput , {
247
261
encoding : "utf-8" ,
248
262
mode : 384 ,
249
263
} )
264
+ expect ( mockFileSystem . rename ) . toBeCalledWith ( expect . stringContaining ( sshFilePath + "." ) , sshFilePath )
250
265
} )
251
266
252
267
it ( "throws an error if there is a mismatched start and end block count" , async ( ) => {
@@ -426,10 +441,11 @@ Host afterconfig
426
441
LogLevel : "ERROR" ,
427
442
} )
428
443
429
- expect ( mockFileSystem . writeFile ) . toBeCalledWith ( sshFilePath , expectedOutput , {
444
+ expect ( mockFileSystem . writeFile ) . toBeCalledWith ( expect . stringContaining ( sshFilePath ) , expectedOutput , {
430
445
encoding : "utf-8" ,
431
446
mode : 384 ,
432
447
} )
448
+ expect ( mockFileSystem . rename ) . toBeCalledWith ( expect . stringContaining ( sshFilePath + "." ) , sshFilePath )
433
449
} )
434
450
435
451
it ( "override values" , async ( ) => {
@@ -470,5 +486,10 @@ Host coder-vscode.dev.coder.com--*
470
486
# --- END CODER VSCODE dev.coder.com ---`
471
487
472
488
expect ( mockFileSystem . readFile ) . toBeCalledWith ( sshFilePath , expect . anything ( ) )
473
- expect ( mockFileSystem . writeFile ) . toBeCalledWith ( sshFilePath , expectedOutput , expect . anything ( ) )
489
+ expect ( mockFileSystem . writeFile ) . toBeCalledWith (
490
+ expect . stringContaining ( sshFilePath ) ,
491
+ expectedOutput ,
492
+ expect . anything ( ) ,
493
+ )
494
+ expect ( mockFileSystem . rename ) . toBeCalledWith ( expect . stringContaining ( sshFilePath + "." ) , sshFilePath )
474
495
} )
0 commit comments