Tests/Integration/UpdateServicesClientDSC.Integration.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
$DSCModuleName   = 'UpdateServicesClientDSC'
$DSCResourceName = 'UpdateServicesClientDSC'

Import-Module "$((Get-Item -LiteralPath "$($PSScriptRoot)").Parent.Parent.FullName)\Misc\KVWindowsUpdate.psm1"

$configfile = Join-Path -Path $PSScriptRoot -ChildPath "$($DSCResourceName).config.ps1"
. $configfile

$workingFolder = "$env:temp\$DSCModuleName\$DSCResourceName"

try {
    Describe "$($DSCResourceName)_Integration" -Tag IntegrationTest {
        It 'Should compile without throwing' {
            {
                Invoke-Expression -Command "$($DSCResourceName)_config -OutputPath `$workingFolder"
                Start-DscConfiguration -Path $workingFolder -ComputerName localhost -Wait -Verbose -Force
            } | Should not throw
        }

        It 'Should be able to call Get-DscConfiguration without throwing' {
            { Get-DscConfiguration -Verbose -ErrorAction Stop } | Should not throw
        }

        It 'Should have set the resource and all the params should match' {
            $config = Get-DscConfiguration | Where-Object { $_.ConfigurationName -eq "$($DSCResourceName)_config" }
            $config.Ensure                 | Should Be $UpdateServicesClientDSC.Ensure
            $config.AutomaticUpdateEnabled | Should Be $UpdateServicesClientDSC.AutomaticUpdateEnabled
            $config.AutomaticUpdateOption  | Should Be $UpdateServicesClientDSC.AutomaticUpdateOption
            $config.UpdateServer           | Should Be $UpdateServicesClientDSC.UpdateServer
            $config.UpdateTargetGroup      | Should Be $UpdateServicesClientDSC.UpdateTargetGroup
        }
    }
}
finally
{
    Stop-DscConfiguration -Force
    Remove-DscConfigurationDocument -Stage Current
    Remove-DscConfigurationDocument -Stage Pending
    Remove-DscConfigurationDocument -Stage Previous
    Remove-AutomaticUpdate 
    Remove-UpdateOption
    Remove-UpdateServer
    Remove-UpdateTargetGroup
}