This repository has been archived by the owner on Dec 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtests.ps1
59 lines (55 loc) · 2.13 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
param(
$Config,
[System.Management.Automation.PSCredential]$GuestCredential
)
#
# Tests running on the local machine, e. g. try to ping the test vm
#
task Ping {
$progressPreference = 'SilentlyContinue';
Test-Connection $Config.testIp -Quiet 6> $null
assert (Test-Connection $Config.testIp -Quiet 6> $null) "Unable to ping the server."
}
task Port80 {
if ( $(Get-PSVersion).Major -ge 6 ) {
# Test-NetConnection is not available on core non Windows, older versions of Windows do not contain test net-connection so implemented an additional fall back with .Net.Sockets.
assert (
Test-Connection $Config.testIp -TCPPort 80
) "Unable to connect to port 80 of the server."
}
else {
if (Get-Command -Name Test-NetConnection -ErrorAction SilentlyContinue) {
assert (
Test-NetConnection $Config.testIp -Port 80
) "Unable to connect to port 80 of the server."
} else {
assert (
$(try {$socket = New-Object Net.Sockets.TcpClient($Config.testIp, 80);if ($socket.Connected) {$true};$socket.Close()} catch {})
) "Unable to connect to port 80 of the server."
}
}
}
#
# Tests running inside the test vm, e. g. check if a service is running. VMware-tools are used to achieve this.
#
task NTDS {
$splat = @{
ScriptText = 'if ( Get-Service "NTDS" -ErrorAction SilentlyContinue ) { Write-Output "running" } else { Write-Output "not running" }'
ScriptType = 'PowerShell'
VM = $Config.mountName
GuestCredential = $GuestCredential
}
$output = Invoke-VMScript @splat -ErrorAction Stop
equals "$($output.Trim())" "running"
}
task MSSQLSERVER {
$splat = @{
ScriptText = 'if ( Get-Service "MSSQLSERVER" -ErrorAction SilentlyContinue ) { Write-Output "running" } else { Write-Output "not running" }'
ScriptType = 'PowerShell'
VM = $Config.mountName
GuestCredential = $GuestCredential
}
$output = Invoke-VMScript @splat -ErrorAction Stop
equals "$($output.Trim())" "running"
}
task .