Tests/Integration/MSFT_xWindowsFeatureSet.Tests.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
$TestEnvironment = Initialize-TestEnvironment `
    -DSCModuleName 'xPSDesiredStateConfiguration' `
    -DSCResourceName 'MSFT_xWindowsFeatureSet' `
    -TestType Integration

Describe "xWindowsFeatureSet Integration Tests" {
    It "Prepare to install a set of Windows features with their sub features" {
        $configurationName = "PrepareInstallWithSubFeatures"
        $configurationPath = Join-Path -Path (Get-Location) -ChildPath $configurationName
        $logPath = Join-Path -Path (Get-Location) -ChildPath "TestLogs"
        $featureNames = @("Test1", "SubTest3")

        try
        {
            Configuration $configurationName
            {
                Import-DscResource -ModuleName xPSDesiredStateConfiguration

                xWindowsFeatureSet WindowsFeatureSet1
                {
                    Name = $featureNames
                    Ensure = "Present"
                    IncludeAllSubFeature = $true
                    LogPath = $logPath
                }
            }

            # Ensure that the configuration compiles correctly
            { & $configurationName -OutputPath $configurationPath } | Should Not Throw

            # This call will not actually work since we are not on a server and these are not real features
            { Start-DscConfiguration -Path $configurationPath -ErrorAction SilentlyContinue } | Should Not Throw
        }
        finally
        {
            if (Test-Path -Path $logPath)
            {
                Remove-Item -Path $logPath -Recurse -Force
            }

            if (Test-Path -Path $configurationPath)
            {
                Remove-Item -Path $configurationPath -Recurse -Force
            }
        }
    }
}