internal/tests/DSCPullServer.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
Describe "[$($Lab.Name)] DSCPullServer" -Tag DSCPullServer {
    Context "Role deployment successful" {
        It "[DSCPullServer] Should return the correct amount of machines" {
            (Get-LabVM -Role DSCPullServer).Count | Should -Be $(Get-Lab).Machines.Where( { $_.Roles.Name -contains 'DSCPullServer' }).Count
        }

        foreach ($vm in (Get-LabVM -Role DSCPullServer))
        {
            It "[$vm] should have all required Pull Server features installed" -TestCases @{
                vm = $vm
            } {            
                (Get-LabWindowsFeature -ComputerName $vm -FeatureName DSC-Service -NoDisplay).Installed | Should -Not -Contain $false
            }

            It "[$vm] Pull Server DSC config should exist" -TestCases @{vm = $vm} {
                $config = Get-DscConfiguration -CimSession (New-LabCimSession -ComputerName $vm) -ErrorAction SilentlyContinue
                $config.ConfigurationName | Sort-Object -Unique | Should -Be 'SetupDscPullServer'
            }

            It "[$vm] Pull Server DSC config should be converged" -TestCases @{vm = $vm} {
                Test-DscConfiguration -CimSession (New-LabCimSession -ComputerName $vm) -ErrorAction SilentlyContinue | Should -Be $true
            }

            It "[$vm] Endpoint should be accessible" -TestCases @{vm = $vm} {
                    Invoke-LabCommand -ComputerName $vm -ScriptBlock {
                        if ([Net.ServicePointManager]::SecurityProtocol -notmatch 'Tls12')
                        {
                            Write-Verbose -Message 'Adding support for TLS 1.2'
                            [Net.ServicePointManager]::SecurityProtocol += [Net.SecurityProtocolType]::Tls12
                        }
                        $uri = (Get-DscConfiguration -ErrorAction SilentlyContinue | Where-Object -Property CimClassName -eq 'DSC_xDscWebService').DscServerUrl                
                        Invoke-RestMethod -Method Get -Uri $uri -UseBasicParsing -ErrorAction SilentlyContinue
                    } -PassThru -NoDisplay | Should -Not -BeNullOrEmpty
            }
        }
    }
}