-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsafeguard-cmdlet-testing.ps1
More file actions
83 lines (69 loc) · 3.67 KB
/
safeguard-cmdlet-testing.ps1
File metadata and controls
83 lines (69 loc) · 3.67 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Gather any parameters into a single array
param([Parameter(Mandatory=$false, ValueFromRemainingArguments=$true)][string[]] $allParameters)
Write-Host "###############################################################################"
Write-Host "# Safeguard-ps Cmdlet Test Harness #"
Write-Host "###############################################################################"
Write-Host
$SCRIPT_PATH = (Split-Path $myInvocation.MyCommand.Path)
$BASE_NAME = [System.IO.Path]::GetFileNameWithoutExtension($myInvocation.MyCommand.Name)
# global data and functions are in separate files for maintainability
# harness-globals loads all other harness-* files
. "$SCRIPT_PATH\harness-globals.ps1"
if ( -not $GLOBALS.initializeEnvironment($DATA.Tests)) {
exit
}
pause
$knownVMTypes = @('vmware','hyperv')
try {
if ($GLOBALS.createLog) {
$GLOBALS.startTranscribing()
}
$fullRunInfo = $GLOBALS.testBlockHeader("All Test Blocks")
$GLOBALS.sgConnect()
$GLOBALS.goodResult(@{ minVerbosity = 1; cmd = "Connect-Safeguard"; message = "Success"; })
$GLOBALS.writeCallHeader("Get-SafeguardVersion")
$sgVersion = Get-SafeguardVersion
$GLOBALS.goodResult(@{ minVerbosity = 1; cmd = "Get-SafeguardVersion"; message = "Success"; })
$GLOBALS.formatTable(@{ output = $sgVersion; })
$isVm = $knownVMTypes -contains $sgVersion.BuildPlatform
$isLTS = $sgVersion.Minor -eq "0"
$GLOBALS.writeCallHeader("Appliance Info")
$GLOBALS.infoResult(@{ minVerbosity = 1; cmd = "isVm"; message = $isVm; })
$GLOBALS.infoResult(@{ minVerbosity = 1; cmd = "isLTS"; message = $isLTS; })
if ($GLOBALS.testBranch -match "^other:") {
if ($DATA.Tests.Patch.runTest -eq "Y" -or $DATA.Tests.Cluster.runTest -eq "Y") {
$DATA.Tests.Patch.runTest = "N"
$DATA.Tests.Cluster.runTest = "N"
$GLOBALS.infoResult(@{ minVerbosity = 1; cmd = "Test Branch Check"; message = "Skipping patch and cluster testing on 'Other' test branch"; })
}
} elseif ($isLTS -and $GLOBALS.testBranch -eq "Feature" -and $DATA.Tests.Patch.runTest -eq "Y") {
$GLOBALS.infoResult(@{ minVerbosity = 1; cmd = "Test Branch Check"; message = "This is an LTS appliance. Do you want to patch it to a Feature build?"; })
if ("Y" -ne (Read-Host "Enter Y to continue with patch tests on $($DATA.appliance)")) {
$DATA.Tests.Patch.runTest = "N"
$GLOBALS.infoResult(@{ minVerbosity = 1; cmd = "Patch Testing"; message = "Skipping patch testing from LTS to Feature"; })
}
} elseif (($isLTS -and $GLOBALS.testBranch -ne "LTS") -or (-not $isLTS -and $GLOBALS.testBranch -ne "Feature")) {
$GLOBALS.badResult(@{ minVerbosity = 0; cmd = "Test Branch Mismatch"; message = "This is a $(iif $isLTS "LTS" "Feature") appliance and TestBranch is set to $GLOBALS.testBranch"; })
exit
}
$GLOBALS.writeCallHeader("Test-SafeguardVersion - minimum 6.0")
Test-SafeguardVersion -MinVersion 6.0
$GLOBALS.goodResult(@{ minVerbosity = 1; cmd = "Test-SafeguardVersion"; message = "Success"; })
foreach ($t in ($DATA.Tests.GetEnumerator() | Where-Object {$_.Value.runTest -eq "Y"} | Sort {$_.Value.Seq})) {
. "$($t.Value.fileName)"
}
}
catch {
Write-Host $_.Exception
Write-Host $_.ScriptStackTrace
}
finally {
Disconnect-Safeguard
$GLOBALS.testBlockHeader($fullRunInfo, $true)
if ($GLOBALS.resultCounts.Bad -gt 0) {
$GLOBALS.writeHostColor($GLOBALS.COLORS.bad, "===== Collected Errors =====")
$GLOBALS.writeHostColor($GLOBALS.COLORS.bad, $GLOBALS.collectedErrors)
}
Write-Host ""
if ($GLOBALS.createLog) { Stop-Transcript }
}