Skip to content

Commit 9a2f490

Browse files
committed
make some tests runnable in ModuleDependencyHandler.tests.ps1 and check for DSC installation
1 parent 2758de2 commit 9a2f490

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

Tests/Engine/ModuleDependencyHandler.tests.ps1

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,21 @@ $directory = Split-Path -Parent $MyInvocation.MyCommand.Path
33
Describe "Resolve DSC Resource Dependency" {
44
BeforeAll {
55
$skipTest = $false
6+
$skipUnitTest = $false # Test that do not require DSC to be installed
67
if ($IsMacOS -or $testingLibararyUsage -or ($PSversionTable.PSVersion -lt [Version]'5.0.0'))
78
{
89
$skipTest = $true
10+
# $skipUnitTest = $true
911
return
1012
}
13+
if ($IsLinux)
14+
{
15+
$dscIsInstalled = Test-Path /etc/opt/omi/conf/dsc/configuration
16+
if (-not $dscIsInstalled)
17+
{
18+
$skipTest = $true
19+
}
20+
}
1121
$SavedPSModulePath = $env:PSModulePath
1222
$violationFileName = 'MissingDSCResource.ps1'
1323
$violationFilePath = Join-Path $directory $violationFileName
@@ -32,12 +42,12 @@ Describe "Resolve DSC Resource Dependency" {
3242

3343
Context "Module handler class" {
3444
BeforeAll {
35-
if ( $skipTest ) { return }
45+
if ( $skipTest -and $skipUnitTest ) { return }
3646
$moduleHandlerType = [Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.ModuleDependencyHandler]
3747
$oldEnvVars = Get-Item Env:\* | Sort-Object -Property Key
3848
$oldPSModulePath = $env:PSModulePath
3949
}
40-
It "Sets defaults correctly" -skip:$skipTest {
50+
It "Sets defaults correctly" -skip:$skipUnitTest {
4151
$rsp = [runspacefactory]::CreateRunspace()
4252
$rsp.Open()
4353
$depHandler = $moduleHandlerType::new($rsp)
@@ -64,15 +74,15 @@ Describe "Resolve DSC Resource Dependency" {
6474
$rsp.Dispose()
6575
}
6676

67-
It "Keeps the environment variables unchanged" -skip:$skipTest {
77+
It "Keeps the environment variables unchanged" -skip:$skipUnitTest {
6878
Test-EnvironmentVariables($oldEnvVars)
6979
}
7080

71-
It "Throws if runspace is null" -skip:$skipTest {
81+
It "Throws if runspace is null" -skip:$skipUnitTest {
7282
{$moduleHandlerType::new($null)} | Should -Throw
7383
}
7484

75-
It "Throws if runspace is not opened" -skip:$skipTest {
85+
It "Throws if runspace is not opened" -skip:$skipUnitTest {
7686
$rsp = [runspacefactory]::CreateRunspace()
7787
{$moduleHandlerType::new($rsp)} | Should -Throw
7888
$rsp.Dispose()

0 commit comments

Comments
 (0)