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

        foreach ($vm in (Get-LabVM -Role TfsBuildWorker))
        {
            $role = $vm.Roles | Where-Object Name -eq TfsBuildWorker            
            if ($role.Properties.ContainsKey('Organisation') -and $role.Properties.ContainsKey('PAT'))
            {
                $tfsServer = 'dev.azure.com'
            }
            elseif ($role.Properties.ContainsKey('TfsServer'))
            {
                $tfsServer = Get-LabVM -ComputerName $role.Properties['TfsServer'] -ErrorAction SilentlyContinue
            }

            if (-not $tfsServer)
            {
                $tfsServer = Get-LabVM -Role Tfs2015, Tfs2017, Tfs2018, AzDevOps | Select-Object -First 1
            }

            It "[$vm] Should have build worker installed" -TestCases @{ 
                vm        = $vm
                tfsServer = $tfsServer
            } {
                $test = Test-LabTfsEnvironment -SkipServer -ComputerName $tfsServer -NoDisplay
                $test.BuildWorker[$vm.Name].WorkerDeploymentOk | Should -Not -Be $false
            }
        }
    }
}