@@ -16,24 +16,33 @@ suite("Authenticate", () => {
16
16
17
17
teardown ( ( ) => utils . resetEnv ( ) )
18
18
19
+ const assertDir = ( actual : string , expected : string ) => {
20
+ assert . match ( actual , new RegExp ( expected . replace ( / \\ / g, "\\$&" ) + "$" ) )
21
+ }
22
+
19
23
const assertDirs = ( dir : string ) => {
20
- assert . match ( auth . getConfigDir ( "linux" ) , new RegExp ( path . join ( dir , ".config$" ) ) )
21
- assert . match ( auth . getConfigDir ( "freebsd" ) , new RegExp ( path . join ( dir , ".config$" ) ) )
22
- assert . match ( auth . getConfigDir ( "win32" ) , new RegExp ( path . join ( dir , "AppData/Roaming$" ) ) )
23
- assert . match ( auth . getConfigDir ( "darwin" ) , new RegExp ( path . join ( dir , "Library/Application Support$" ) ) )
24
+ assertDir ( auth . getConfigDir ( "linux" ) , path . join ( dir , ".config" ) )
25
+ assertDir ( auth . getConfigDir ( "freebsd" ) , path . join ( dir , ".config" ) )
26
+ assertDir ( auth . getConfigDir ( "win32" ) , path . join ( dir , "AppData/Roaming" ) )
27
+ assertDir ( auth . getConfigDir ( "darwin" ) , path . join ( dir , "Library/Application Support" ) )
24
28
}
25
29
26
30
test ( "getConfigDir" , async ( ) => {
27
31
// Make sure local config mocks work.
28
32
const tmpDir = await utils . tmpdir ( tmpPath )
29
33
utils . setEnv ( "HOME" , tmpDir )
34
+ utils . setEnv ( "USERPROFILE" , tmpDir )
35
+ utils . setEnv ( "XDG_CONFIG_HOME" , undefined )
36
+ utils . setEnv ( "APPDATA" , undefined )
30
37
assertDirs ( tmpDir )
31
38
32
39
// Make sure the global mock also works. For example the Linux temp config
33
40
// directory looks like: /tmp/coder/tests/config/tmp-Dzfqwl/home/.config
34
41
// This runs after the local mock to make sure environment variables are
35
42
// being restored correctly.
36
43
utils . resetEnv ( )
44
+ utils . setEnv ( "XDG_CONFIG_HOME" , undefined )
45
+ utils . setEnv ( "APPDATA" , undefined )
37
46
assertDirs ( "tests/config/.+/home" )
38
47
} )
39
48
0 commit comments