@@ -2,12 +2,21 @@ $directory = Split-Path -Parent $MyInvocation.MyCommand.Path
2
2
3
3
Describe " Resolve DSC Resource Dependency" {
4
4
BeforeAll {
5
- $skipTest = $false
6
- if ($IsLinux -or $IsMacOS -or $ testingLibararyUsage -or ($PSversionTable.PSVersion -lt [Version ]' 5.0.0' ))
5
+ $skipTest = $false # Test that require DSC to be installed
6
+ if ($testingLibararyUsage -or ($PSversionTable.PSVersion -lt [Version ]' 5.0.0' ))
7
7
{
8
8
$skipTest = $true
9
9
return
10
10
}
11
+ if ($IsLinux -or $IsMacOS )
12
+ {
13
+ $dscIsInstalled = Test-Path / etc/ opt/ omi/ conf/ dsc/ configuration
14
+ if (-not $dscIsInstalled )
15
+ {
16
+ $skipTest = $true
17
+ }
18
+ }
19
+
11
20
$savedPSModulePath = $env: PSModulePath
12
21
$violationFileName = ' MissingDSCResource.ps1'
13
22
$violationFilePath = Join-Path $directory $violationFileName
@@ -24,6 +33,11 @@ Describe "Resolve DSC Resource Dependency" {
24
33
$newEnv [$index ].Value | Should - Be $oldEnv [$index ].Value
25
34
}
26
35
}
36
+
37
+ Function Get-LocalAppDataFolder
38
+ {
39
+ if ($IsLinux -or $IsMacOS ) { $env: HOME } else { $env: LOCALAPPDATA }
40
+ }
27
41
}
28
42
AfterAll {
29
43
if ( $skipTest ) { return }
@@ -32,7 +46,7 @@ Describe "Resolve DSC Resource Dependency" {
32
46
33
47
Context " Module handler class" {
34
48
BeforeAll {
35
- if ( $skipTest ) { return }
49
+ if ($PSversionTable .PSVersion -lt [ Version ] ' 5.0.0 ' ) { return }
36
50
$moduleHandlerType = [Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.ModuleDependencyHandler ]
37
51
$oldEnvVars = Get-Item Env:\* | Sort-Object - Property Key
38
52
$savedPSModulePath = $env: PSModulePath
@@ -41,16 +55,15 @@ Describe "Resolve DSC Resource Dependency" {
41
55
if ( $skipTest ) { return }
42
56
$env: PSModulePath = $savedPSModulePath
43
57
}
44
- It " Sets defaults correctly" - skip: $skipTest {
58
+ It " Sets defaults correctly" - Skip:( $PSversionTable .PSVersion -lt [ Version ] ' 5.0.0 ' ) {
45
59
$rsp = [runspacefactory ]::CreateRunspace()
46
60
$rsp.Open ()
47
61
$depHandler = $moduleHandlerType ::new($rsp )
48
62
49
63
$expectedPath = [System.IO.Path ]::GetTempPath()
50
64
$depHandler.TempPath | Should - Be $expectedPath
51
65
52
- $expectedLocalAppDataPath = $env: LOCALAPPDATA
53
- $depHandler.LocalAppDataPath | Should - Be $expectedLocalAppDataPath
66
+ $depHandler.LocalAppDataPath | Should - Be (Get-LocalAppDataFolder )
54
67
55
68
$expectedModuleRepository = " PSGallery"
56
69
$depHandler.ModuleRepository | Should - Be $expectedModuleRepository
@@ -65,15 +78,15 @@ Describe "Resolve DSC Resource Dependency" {
65
78
$rsp.Dispose ()
66
79
}
67
80
68
- It " Keeps the environment variables unchanged" - skip: $skipTest {
81
+ It " Keeps the environment variables unchanged" - Skip:( $PSversionTable .PSVersion -lt [ Version ] ' 5.0.0 ' ) {
69
82
Test-EnvironmentVariables ($oldEnvVars )
70
83
}
71
84
72
- It " Throws if runspace is null" - skip: $skipTest {
85
+ It " Throws if runspace is null" - Skip:( $PSversionTable .PSVersion -lt [ Version ] ' 5.0.0 ' ) {
73
86
{$moduleHandlerType ::new($null )} | Should - Throw
74
87
}
75
88
76
- It " Throws if runspace is not opened" - skip: $skipTest {
89
+ It " Throws if runspace is not opened" - Skip:( $PSversionTable .PSVersion -lt [ Version ] ' 5.0.0 ' ) {
77
90
$rsp = [runspacefactory ]::CreateRunspace()
78
91
{$moduleHandlerType ::new($rsp )} | Should - Throw
79
92
$rsp.Dispose ()
@@ -176,16 +189,19 @@ Describe "Resolve DSC Resource Dependency" {
176
189
$modulePath = " $ ( Split-Path $directory ) \Rules\DSCResourceModule\DSCResources\$moduleName "
177
190
178
191
# Save the current environment variables
179
- $oldLocalAppDataPath = $ env: LOCALAPPDATA
192
+ $oldLocalAppDataPath = Get-LocalAppDataFolder
180
193
$oldTempPath = $env: TEMP
181
194
$savedPSModulePath = $env: PSModulePath
182
195
183
196
# set the environment variables
184
- $tempPath = Join-Path $oldTempPath ([guid ]::NewGUID()).ToString()
197
+ $tempPath = Join-Path ([ System.IO.Path ]::GetTempPath()) ([guid ]::NewGUID()).ToString()
185
198
$newLocalAppDataPath = Join-Path $tempPath " LocalAppData"
186
199
$newTempPath = Join-Path $tempPath " Temp"
187
- $env: LOCALAPPDATA = $newLocalAppDataPath
188
- $env: TEMP = $newTempPath
200
+ if (-not ($IsLinux -or $IsMacOS ))
201
+ {
202
+ $env: LOCALAPPDATA = $newLocalAppDataPath
203
+ $env: TEMP = $newTempPath
204
+ }
189
205
190
206
# create the temporary directories
191
207
New-Item - Type Directory - Path $newLocalAppDataPath - force
@@ -212,7 +228,6 @@ Describe "Resolve DSC Resource Dependency" {
212
228
}
213
229
214
230
It " has a single parse error" - skip:$skipTest {
215
- # invoke script analyzer
216
231
$dr = Invoke-ScriptAnalyzer - Path $violationFilePath - ErrorVariable analyzerErrors - ErrorAction SilentlyContinue
217
232
$analyzerErrors.Count | Should - Be 0
218
233
$dr |
@@ -221,14 +236,22 @@ Describe "Resolve DSC Resource Dependency" {
221
236
}
222
237
223
238
It " Keeps PSModulePath unchanged before and after invocation" - skip:$skipTest {
224
- $dr = Invoke-ScriptAnalyzer - Path $violationFilePath - ErrorVariable parseErrors - ErrorAction SilentlyContinue
239
+ Invoke-ScriptAnalyzer - Path $violationFilePath - ErrorVariable parseErrors - ErrorAction SilentlyContinue
225
240
$env: PSModulePath | Should - Be $savedPSModulePath
226
241
}
227
242
228
243
if (! $skipTest )
229
244
{
230
- $env: LOCALAPPDATA = $oldLocalAppDataPath
231
- $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
+ }
232
255
Remove-Item - Recurse - Path $tempModulePath - Force
233
256
Remove-Item - Recurse - Path $tempPath - Force
234
257
}
0 commit comments