Skip to content

Commit d6121be

Browse files
committed
Add Automated Testing
Use GitHub Actions to provide automated testing for first responder kit stored procedures. #3418
1 parent a438f04 commit d6121be

12 files changed

+225
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: First Responder Kit Integration Tests
2+
3+
on:
4+
push:
5+
workflow_dispatch:
6+
7+
jobs:
8+
build:
9+
name: Build
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Install SqlServer Module
17+
shell: pwsh
18+
run: |
19+
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
20+
Install-Module SqlServer
21+
22+
- name: Install SQL Server
23+
uses: potatoqualitee/[email protected]
24+
with:
25+
install: sqlengine
26+
version: 2017
27+
collation: SQL_Latin1_General_CP1_CS_AS
28+
29+
- name: Check SQL Install
30+
run: |
31+
sqlcmd -S localhost -U sa -P dbatools.I0 -d tempdb -Q "SELECT @@version as Version;" -I -b -t 60
32+
sqlcmd -S localhost -U sa -P dbatools.I0 -d tempdb -Q "SELECT SERVERPROPERTY('Collation') AS Collation;" -I -b -t 60
33+
34+
- name: Deploy FRK
35+
run: |
36+
sqlcmd -S localhost -U sa -P dbatools.I0 -d master -i "sp_BlitzCache.sql" -I -b -t 60
37+
sqlcmd -S localhost -U sa -P dbatools.I0 -d master -i "sp_BlitzWho.sql" -I -b -t 60
38+
sqlcmd -S localhost -U sa -P dbatools.I0 -d master -i "sp_Blitz.sql" -I -b -t 60
39+
sqlcmd -S localhost -U sa -P dbatools.I0 -d master -i "sp_BlitzFirst.sql" -I -b -t 60
40+
sqlcmd -S localhost -U sa -P dbatools.I0 -d master -i "sp_BlitzAnalysis.sql" -I -b -t 60
41+
sqlcmd -S localhost -U sa -P dbatools.I0 -d master -i "sp_BlitzBackups.sql" -I -b -t 60
42+
sqlcmd -S localhost -U sa -P dbatools.I0 -d master -i "sp_BlitzIndex.sql" -I -b -t 60
43+
sqlcmd -S localhost -U sa -P dbatools.I0 -d master -i "sp_BlitzInMemoryOLTP.sql" -I -b -t 60
44+
sqlcmd -S localhost -U sa -P dbatools.I0 -d master -i "sp_BlitzLock.sql" -I -b -t 60
45+
sqlcmd -S localhost -U sa -P dbatools.I0 -d master -i "sp_BlitzQueryStore.sql" -I -b -t 60
46+
sqlcmd -S localhost -U sa -P dbatools.I0 -d master -Q "SELECT * FROM sys.procedures WHERE name LIKE 'sp_Blitz%';" -I -b -t 60
47+
48+
- name: Run Pester Tests
49+
shell: pwsh
50+
run: |
51+
cd tests
52+
./run-tests.ps1

tests/run-tests.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Assign default values if script-scoped variables are not set
2+
$ServerInstance = if ($null -ne $script:ServerInstance) { $script:ServerInstance } else { "localhost" }
3+
$UserName = if ($null -ne $script:UserName) { $script:UserName } else { "sa" }
4+
$Password = if ($null -ne $script:Password) { $script:Password } else { "dbatools.I0" }
5+
$TrustServerCertificate = if ($null -ne $script:TrustServerCertificate) { $script:TrustServerCertificate } else { $true }
6+
7+
$PSDefaultParameterValues = @{
8+
"*:ServerInstance" = $ServerInstance
9+
"*:UserName" = $UserName
10+
"*:Password" = $Password
11+
"*:TrustServerCertificate" = $TrustServerCertificate
12+
}
13+
14+
Invoke-Pester -PassThru

tests/sp_Blitz.tests.ps1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Describe "sp_Blitz Tests" {
2+
3+
It "sp_Blitz Check" {
4+
$results = Invoke-SqlCmd -Query "EXEC dbo.sp_Blitz" -OutputAs DataSet
5+
$results.Tables.Count | Should -Be 1
6+
$results.Tables[0].Columns.Count | Should -Be 9
7+
$results.Tables[0].Rows.Count | Should -BeGreaterThan 0
8+
}
9+
10+
}

tests/sp_BlitzAnalysis.tests.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Describe "sp_BlitzAnalysis Tests" {
2+
3+
It "sp_BlitzAnalysis Check" {
4+
5+
# Run sp_BlitzFirst to populate the tables used by sp_BlitzAnalysis
6+
Invoke-SqlCmd -Query "EXEC dbo.sp_BlitzFirst @OutputDatabaseName = 'tempdb', @OutputSchemaName = N'dbo', @OutputTableName = N'BlitzFirst', @OutputTableNameFileStats = N'BlitzFirst_FileStats',@OutputTableNamePerfmonStats = N'BlitzFirst_PerfmonStats',
7+
@OutputTableNameWaitStats = N'BlitzFirst_WaitStats',
8+
@OutputTableNameBlitzCache = N'BlitzCache',
9+
@OutputTableNameBlitzWho= N'BlitzWho'"
10+
11+
$results = Invoke-SqlCmd -Query "EXEC dbo.sp_BlitzAnalysis @OutputDatabaseName = 'tempdb'" -OutputAs DataSet
12+
$results.Tables.Count | Should -BeGreaterThan 6
13+
}
14+
15+
}

tests/sp_BlitzBackups.tests.ps1

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Describe "sp_BlitzBackups Tests" {
2+
3+
It "sp_BlitzBackups Check" {
4+
# Give sp_BlitzBackups something to capture by performing a dummy backup of model DB
5+
# Test to be run in GitHub action but backing up model to NUL should be safe on most systems
6+
Invoke-SqlCmd -Query "BACKUP DATABASE model TO DISK='NUL'"
7+
$results = Invoke-SqlCmd -Query "EXEC dbo.sp_BlitzBackups" -OutputAs DataSet
8+
$results.Tables.Count | Should -Be 3
9+
10+
$results.Tables[0].Columns.Count | Should -Be 39
11+
$results.Tables[0].Rows.Count | Should -BeGreaterThan 0
12+
13+
$results.Tables[1].Columns.Count | Should -Be 32
14+
$results.Tables[1].Rows.Count | Should -BeGreaterThan 0
15+
16+
$results.Tables[2].Columns.Count | Should -Be 5
17+
$results.Tables[2].Rows.Count | Should -BeGreaterThan 0
18+
}
19+
20+
}

tests/sp_BlitzCache.tests.ps1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Describe "sp_BlitzCache Tests" {
2+
3+
It "sp_BlitzCache Check" {
4+
# Note: Added 'SELECT 1 AS A' as an empty first resultset causes issues returning the full DataSet
5+
$results = Invoke-SqlCmd -Query "SELECT 1 AS A;EXEC dbo.sp_BlitzCache" -OutputAs DataSet
6+
# Adjust table count to get the actual tables returned from sp_BlitzCache (So reporting isn't confusing)
7+
$tableCount = $results.Tables.Count -1
8+
$tableCount | Should -Be 2
9+
$results.Tables[1].Columns.Count | Should -Be 43
10+
$results.Tables[2].Columns.Count | Should -Be 6
11+
$results.Tables[2].Rows.Count | Should -BeGreaterThan 0
12+
}
13+
}

tests/sp_BlitzFirst.tests.ps1

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
Describe "sp_BlitzFirst Tests" {
2+
3+
It "sp_BlitzFirst Check" {
4+
# Give sp_BlitzFirst something to capture
5+
Start-Job -ScriptBlock {
6+
Invoke-SqlCmd -Query "WAITFOR DELAY '00:00:15'" -ServerInstance $using:ServerInstance -Username $using:UserName -Password $using:Password -TrustServerCertificate:$using:TrustServerCertificate
7+
}
8+
Start-Sleep -Milliseconds 1000
9+
$results = Invoke-SqlCmd -Query "EXEC dbo.sp_BlitzFirst" -OutputAs DataSet
10+
$results.Tables.Count | Should -Be 1
11+
$results.Tables[0].Columns.Count | Should -Be 8
12+
$results.Tables[0].Rows.Count | Should -BeGreaterThan 0
13+
14+
$results = Invoke-SqlCmd -Query "EXEC dbo.sp_BlitzFirst @ExpertMode=1" -OutputAs DataSet
15+
$results.Tables.Count | Should -Be 7
16+
17+
$results.Tables[0].Columns.Count | Should -Be 21
18+
$results.Tables[0].Rows.Count | Should -BeGreaterThan 0
19+
20+
$results.Tables[1].Columns.Count | Should -Be 40
21+
$results.Tables[1].Rows.Count | Should -BeGreaterThan 0
22+
23+
$results.Tables[2].Columns.Count | Should -Be 13
24+
$results.Tables[2].Rows.Count | Should -BeGreaterThan 0
25+
26+
$results.Tables[3].Columns.Count | Should -Be 11
27+
$results.Tables[3].Rows.Count | Should -BeGreaterThan 0
28+
29+
$results.Tables[4].Columns.Count | Should -Be 10
30+
$results.Tables[4].Rows.Count | Should -BeGreaterThan 0
31+
32+
$results.Tables[5].Columns.Count | Should -Be 4
33+
$results.Tables[5].Rows.Count | Should -BeGreaterThan 0
34+
35+
$results.Tables[6].Columns.Count | Should -Be 21
36+
$results.Tables[6].Rows.Count | Should -BeGreaterThan 0
37+
38+
}
39+
40+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Describe "sp_BlitzInMemoryOLTP Tests" {
2+
3+
It "sp_BlitzInMemoryOLTP Check" {
4+
# Create InMemory OLTP Database
5+
Invoke-SqlCmd -Query "CREATE DATABASE sp_BlitzInMemoryOLTPTest;ALTER DATABASE sp_BlitzInMemoryOLTPTest SET MEMORY_OPTIMIZED_ELEVATE_TO_SNAPSHOT = ON;ALTER DATABASE sp_BlitzInMemoryOLTPTest ADD FILEGROUP sp_BlitzInMemoryOLTPTest CONTAINS MEMORY_OPTIMIZED_DATA;"
6+
# Note: Added 'SELECT 1 AS A' as an empty first resultset causes issues returning the full DataSet
7+
$results = Invoke-SqlCmd -Query "SELECT 1 AS A;EXEC dbo.sp_BlitzInMemoryOLTP" -OutputAs DataSet
8+
# Adjust table count to get the actual tables returned from sp_BlitzInMemoryOLTP (So reporting isn't confusing)
9+
$tableCount = $results.Tables.Count -1
10+
$tableCount | Should -BeGreaterThan 0
11+
}
12+
13+
}

tests/sp_BlitzIndex.tests.ps1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Describe "sp_BlitzIndex Tests" {
2+
3+
It "sp_BlitzIndex Check" {
4+
$results = Invoke-SqlCmd -Query "EXEC dbo.sp_BlitzIndex" -OutputAs DataSet
5+
$results.Tables.Count | Should -Be 1
6+
$results.Tables[0].Columns.Count | Should -Be 12
7+
$results.Tables[0].Rows.Count | Should -BeGreaterThan 0
8+
}
9+
10+
}

tests/sp_BlitzLock.tests.ps1

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Describe "sp_BlitzLock Tests" {
2+
3+
It "sp_BlitzLock Check" {
4+
# Note: Added 'SELECT 1 AS A' as an empty first resultset causes issues returning the full DataSet
5+
$results = Invoke-SqlCmd -Query "SELECT 1 AS A;EXEC dbo.sp_BlitzLock" -OutputAs DataSet
6+
# Adjust table count to get the actual tables returned from sp_BlitzLock (So reporting isn't confusing)
7+
$tableCount = $results.Tables.Count - 1
8+
$tableCount | Should -Be 3
9+
}
10+
11+
}

0 commit comments

Comments
 (0)