@@ -33,6 +33,11 @@ Describe "Resolve DSC Resource Dependency" {
33
33
$newEnv [$index ].Value | Should - Be $oldEnv [$index ].Value
34
34
}
35
35
}
36
+
37
+ Function Get-LocalAppDataFolder
38
+ {
39
+ if ($IsLinux -or $IsMacOS ) { $env: HOME } else { $env: LOCALAPPDATA }
40
+ }
36
41
}
37
42
AfterAll {
38
43
if ( $skipTest ) { return }
@@ -58,11 +63,7 @@ Describe "Resolve DSC Resource Dependency" {
58
63
$expectedPath = [System.IO.Path ]::GetTempPath()
59
64
$depHandler.TempPath | Should - Be $expectedPath
60
65
61
- $expectedLocalAppDataPath = $env: LOCALAPPDATA
62
- if ($IsLinux -or $IsMacOS ) {
63
- $expectedLocalAppDataPath = $env: HOME
64
- }
65
- $depHandler.LocalAppDataPath | Should - Be $expectedLocalAppDataPath
66
+ $depHandler.LocalAppDataPath | Should - Be (Get-LocalAppDataFolder )
66
67
67
68
$expectedModuleRepository = " PSGallery"
68
69
$depHandler.ModuleRepository | Should - Be $expectedModuleRepository
@@ -188,16 +189,19 @@ Describe "Resolve DSC Resource Dependency" {
188
189
$modulePath = " $ ( Split-Path $directory ) \Rules\DSCResourceModule\DSCResources\$moduleName "
189
190
190
191
# Save the current environment variables
191
- $oldLocalAppDataPath = $ env: LOCALAPPDATA
192
+ $oldLocalAppDataPath = Get-LocalAppDataFolder
192
193
$oldTempPath = $env: TEMP
193
194
$savedPSModulePath = $env: PSModulePath
194
195
195
196
# set the environment variables
196
- $tempPath = Join-Path $oldTempPath ([guid ]::NewGUID()).ToString()
197
+ $tempPath = Join-Path ([ System.IO.Path ]::GetTempPath()) ([guid ]::NewGUID()).ToString()
197
198
$newLocalAppDataPath = Join-Path $tempPath " LocalAppData"
198
199
$newTempPath = Join-Path $tempPath " Temp"
199
- $env: LOCALAPPDATA = $newLocalAppDataPath
200
- $env: TEMP = $newTempPath
200
+ if (-not ($IsLinux -or $IsMacOS ))
201
+ {
202
+ $env: LOCALAPPDATA = $newLocalAppDataPath
203
+ $env: TEMP = $newTempPath
204
+ }
201
205
202
206
# create the temporary directories
203
207
New-Item - Type Directory - Path $newLocalAppDataPath - force
@@ -224,7 +228,6 @@ Describe "Resolve DSC Resource Dependency" {
224
228
}
225
229
226
230
It " has a single parse error" - skip:$skipTest {
227
- # invoke script analyzer
228
231
$dr = Invoke-ScriptAnalyzer - Path $violationFilePath - ErrorVariable analyzerErrors - ErrorAction SilentlyContinue
229
232
$analyzerErrors.Count | Should - Be 0
230
233
$dr |
@@ -233,14 +236,22 @@ Describe "Resolve DSC Resource Dependency" {
233
236
}
234
237
235
238
It " Keeps PSModulePath unchanged before and after invocation" - skip:$skipTest {
236
- $dr = Invoke-ScriptAnalyzer - Path $violationFilePath - ErrorVariable parseErrors - ErrorAction SilentlyContinue
239
+ Invoke-ScriptAnalyzer - Path $violationFilePath - ErrorVariable parseErrors - ErrorAction SilentlyContinue
237
240
$env: PSModulePath | Should - Be $savedPSModulePath
238
241
}
239
242
240
243
if (! $skipTest )
241
244
{
242
- $env: LOCALAPPDATA = $oldLocalAppDataPath
243
- $env: TEMP = $oldTempPath
245
+ if ($IsLinux -or $IsMacOS )
246
+ {
247
+ $env: HOME = $oldLocalAppDataPath
248
+ # On Linux [System.IO.Path]::GetTempPath() does not use the TEMP env variable unlike on Windows
249
+ }
250
+ else
251
+ {
252
+ $env: LOCALAPPDATA = $oldLocalAppDataPath
253
+ $env: TEMP = $oldTempPath
254
+ }
244
255
Remove-Item - Recurse - Path $tempModulePath - Force
245
256
Remove-Item - Recurse - Path $tempPath - Force
246
257
}
0 commit comments