-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathTest-RscSdk.ps1
145 lines (126 loc) · 4.17 KB
/
Test-RscSdk.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<#
.SYNOPSIS
Run the Rubrik PowerShell SDK tests.
.DESCRIPTION
This script runs the unit and e2e tests for both
the Core and Toolkit components of the RSC SDK.
By default, all tests are run. You can skip some tests
by passing the appropriate switches.
The script will stop on the first error.
.PARAMETER SkipUnitTests
Skip all unit tests (in Core and Toolkit).
.PARAMETER SkipE2ETests
Skip all e2e tests (in Core and Toolkit).
.PARAMETER SkipCoreTests
Skip all Core tests (unit and e2e).
.PARAMETER SkipToolkitTests
Skip all Toolkit tests (unit and e2e).
.EXAMPLE
.\Utils\Test-RscSdk.ps1 -SkipUnitTests
# Run only e2e tests for Core and Toolkit.
.EXAMPLE
.\Utils\Test-RscSdk.ps1 -SkipCoreTests
# Run only Toolkit tests.
# Note: this is what ToolkitDev.ps1's Test-RscToolkit does.
.EXAMPLE
.\Utils\Test-RscSdk.ps1 -SkipE2ETests -SkipCoreTests
# Run only Toolkit unit tests.
#>
[CmdletBinding()] # Enable common parameters like -Verbose
param(
[switch]$SkipUnitTests = $false,
[switch]$SkipE2ETests = $false,
[switch]$SkipCoreTests = $false,
[switch]$SkipToolkitTests = $false,
[switch]$CI = $false
)
# Change to the root of the repository
Set-Location $PSScriptRoot\..
# Stop on error
$ErrorActionPreference = "Stop"
# Uncomment this to enable Write-Debug output
# $DebugPreference = "Continue"
# Set up
if ($CI) {
if ($env:RSC_SERVICE_ACCOUNT_FILE) {
$serviceAccountFile = $env:RSC_SERVICE_ACCOUNT_FILE
# bail out if the file doesn't exist
if (-not (Test-Path $serviceAccountFile)) {
throw "SA Unavailable (File not found: $serviceAccountFile)."
}
# bail out if the file is empty
if ((Get-Content $serviceAccountFile) -eq "") {
throw "SA Unavailable (File is empty: $serviceAccountFile)."
}
Set-Location $PSScriptRoot\..
.\Utils\Import-RscModuleFromLocalOutputDir.ps1
Set-RscServiceAccountFile -InputFilePath $serviceAccountFile -DisablePrompts -KeepOriginalClearTextFile
}
else {
throw "SA Unavailable (Environment variable RSC_SERVICE_ACCOUNT_FILE not set)."
}
}
# Run tests
if ( -not $SkipUnitTests ) {
if ( -not $SkipCoreTests ) {
# Run Core unit tests (Pester)
Set-Location $PSScriptRoot\..
$results = .\Toolkit\Utils\Run-PesterTests.ps1 .\Tests\unit
if ($results.Failed.Count -gt 0) {
Write-Error "Pester Core unit tests failed."
exit 1
}
else {
Write-Output "Pester Core unit tests passed."
}
# Run Core unit tests (C#)
Set-Location $PSScriptRoot\..\RubrikSecurityCloud\RubrikSecurityCloud.Common.Tests\
dotnet test
if ($LASTEXITCODE -ne 0) {
Write-Error "C# unit tests failed."
exit $LASTEXITCODE
}
else {
Write-Output "C# unit tests passed."
}
Set-Location $PSScriptRoot\..
}
if ( -not $SkipToolkitTests ) {
# Run Toolkit unit tests (Pester)
Set-Location $PSScriptRoot\..
$results = .\Toolkit\Utils\Run-PesterTests.ps1 .\Toolkit\Tests\unit
if ($results.Failed.Count -gt 0) {
Write-Error "Pester Toolkit unit tests failed."
exit 1
}
else {
Write-Output "Pester Toolkit unit tests passed."
}
}
}
if ( -not $SkipE2ETests ) {
if ( -not $SkipCoreTests ) {
# Run Core e2e tests (Pester)
Set-Location $PSScriptRoot\..
$results = .\Toolkit\Utils\Run-PesterTests.ps1 .\Tests\e2e
if ($results.Failed.Count -gt 0) {
Write-Error "Pester Core e2e tests failed."
exit 1
}
else {
Write-Output "Pester Core e2e tests passed."
}
}
if ( -not $SkipToolkitTests ) {
# Run Toolkit e2e tests (Pester)
Set-Location $PSScriptRoot\..
$results = .\Toolkit\Utils\Run-PesterTests.ps1 .\Toolkit\Tests\e2e
if ($results.Failed.Count -gt 0) {
Write-Error "Pester Toolkit e2e tests failed."
exit 1
}
else {
Write-Output "Pester Toolkit e2e tests passed."
}
}
}