Skip to content

Commit faa88c8

Browse files
authored
add sql server 2017 unit tests in github ci (#237)
1 parent 1ba72a6 commit faa88c8

File tree

8 files changed

+33
-33
lines changed

8 files changed

+33
-33
lines changed

.github/actions/mssql-sample-db/main.ps1

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ if ($Env:RUNNER_OS -ne "Windows") {
1010
Write-Error "This action only supported on Windows runners." -ErrorAction "Stop"
1111
}
1212

13-
14-
1513
if ($Database -eq "WideWorldImporters") {
1614
$BackupPath = Join-Path -Path $Env:RUNNER_TEMP -ChildPath "$Database.bak"
1715
$Uri = "https://github.com/Microsoft/sql-server-samples/releases/download/wide-world-importers-v1.0/WideWorldImporters-Full.bak"
@@ -24,5 +22,5 @@ Write-Output "-----"
2422
Write-Output "Downloading '$Database' to '$BackupPath' ..."
2523
Invoke-WebRequest -Uri $Uri -OutFile $BackupPath
2624
Write-Output "Restoring '$Database' ..."
27-
$null = Restore-DbaDatabase -SqlInstance $SqlInstance -DatabaseName $Database -Path $BackupPath -WithReplace -EnableException
28-
Get-DbaDatabase -SqlInstance $SqlInstance -Database $Database | Select-Object -Property Name, Status, SizeMB, SqlInstance
25+
Restore-SqlDatabase -ServerInstance $SqlInstance -Database $Database -BackupFile $BackupPath -AutoRelocateFile -Verbose
26+
#Get-DbaDatabase -SqlInstance $SqlInstance -Database $Database | Select-Object -Property Name, Status, SizeMB, SqlInstance

.github/workflows/artifacts.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
name: Generate Installer Script
2+
name: Generate Scripts
33
on:
44
workflow_dispatch:
55
push:

.github/workflows/sqlserver-unit.yml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,30 @@ jobs:
3535
integration:
3636
runs-on: ${{ matrix.os }}
3737
name: sqlserver-${{ matrix.sql_server }} x ${{ matrix.os }}
38+
defaults:
39+
run:
40+
shell: pwsh
3841
strategy:
3942
fail-fast: false
4043
matrix:
4144
os:
4245
- windows-latest
4346
sql_server:
4447
- 2019
48+
- 2017
4549

4650
steps:
4751
- name: Check out code
4852
uses: actions/[email protected]
4953
with:
5054
path: ""
5155
ref: ${{ github.head_ref }}
56+
57+
# - name: Install and cache PowerShell modules
58+
# uses: potatoqualitee/[email protected]
59+
# with:
60+
# modules-to-cache: dbatools
61+
# shell: powershell
5262

5363
- name: Install SQL Server
5464
continue-on-error: true
@@ -57,6 +67,7 @@ jobs:
5767
with:
5868
install: sqlengine
5969
sa-password: L0wlydb4
70+
version: ${{ matrix.sql_server }}
6071

6172
- name: Retry SQL Server install
6273
if: steps.mssqlsuite.outcome == 'failure'
@@ -65,24 +76,18 @@ jobs:
6576
install: sqlengine
6677
sa-password: L0wlydb4
6778

68-
- name: Install and cache PowerShell modules
69-
uses: potatoqualitee/[email protected]
70-
with:
71-
modules-to-cache: dbatools
72-
shell: powershell
73-
7479
- name: Install tSQLt
7580
uses: lowlydba/tsqlt-installer@v1
7681
with:
7782
sql-instance: ${{ env.SQLINSTANCE }}
7883
database: ${{ env.DATABASE }}
7984
version: "latest"
8085
create: true
81-
86+
8287
- name: Install multitool
8388
run: |
8489
foreach ($script in (Get-ChildItem -Path "." -Filter "sp_*.sql").Name) {
85-
Invoke-DbaQuery -SqlInstance $Env:SQLINSTANCE -Database $Env:DATABASE -File $script -EnableException
90+
Invoke-Sqlcmd -ServerInstance $Env:SQLINSTANCE -Database $Env:DATABASE -InputFile $script
8691
}
8792
8893
- name: Run Pester tests with SQLCover
@@ -103,7 +108,7 @@ jobs:
103108
run: |
104109
Write-Output "Generating '$Env:SAMPLE_DATABASE' markdown sample."
105110
$Query = "EXEC sp_doc @DatabaseName = '$Env:SAMPLE_DATABASE';"
106-
Invoke-DbaQuery -SqlInstance $Env:SQLINSTANCE -Database $Env:DATABASE -Query $Query -As SingleValue -EnableException | Out-File "$($Env:SAMPLE_DATABASE)-$($Env:SQL_VERSION).md"
111+
Invoke-SqlCmd -ServerInstance $Env:SQLINSTANCE -Database $Env:DATABASE -Query $Query -As DataRows | Select-Object -ExpandProperty 'value' | Out-File "$($Env:SAMPLE_DATABASE)-$($Env:SQL_VERSION).md"
107112
108113
- name: Upload sp_doc sample artifact
109114
uses: actions/upload-artifact@v3

appveyor/run_pester_tests.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ $FailedTests = 0
2525
Get-ChildItem -Path ".\" -Filter "sp_*.sql" | Get-Content | Out-File $Env:INSTALLER_FILE -Encoding ascii
2626
Invoke-DbaQuery -SqlInstance $SqlInstance -Database $Database -File $Env:INSTALLER_FILE
2727

28+
# Install and loadl SqlServer module to prevent SQLPS loading
29+
Install-Module SqlServer -Force -AllowClobber
30+
Import-Module SqlServer
31+
2832
# Run Tests
2933
ForEach ($file in $TestFiles) {
3034
Add-AppveyorTest -Name $file.BaseName -Framework NUnit -Filename $file.FullName -Outcome Running

tests/sp_doc.Tests.ps1

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,18 @@ Describe "sp_doc" {
1515
$queryTimeout = 300
1616

1717
$Hash = @{
18-
SqlInstance = $env:SQLINSTANCE
18+
ServerInstance = $env:SQLINSTANCE
1919
Database = $env:DATABASE
2020
Verbose = $true
21-
EnableException = $true
2221
}
2322

2423
# Install tests
2524
ForEach ($File in Get-ChildItem -Path $testPath -Filter $testInstallScript) {
26-
Invoke-DbaQuery @Hash -File $File.FullName
25+
Invoke-SqlCmd @Hash -InputFile $File.FullName
2726
}
2827
}
2928
It "All tests" {
30-
{ Invoke-DbaQuery @Hash -Query $runTestQuery -QueryTimeout $queryTimeout } | Should -Not -Throw -Because "tSQLt unit tests must pass"
29+
{ Invoke-SqlCmd @Hash -Query $runTestQuery -QueryTimeout $queryTimeout } | Should -Not -Throw -Because "tSQLt unit tests must pass"
3130
}
3231
}
3332
}

tests/sp_estindex.Tests.ps1

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,19 @@ Describe "sp_estindex" {
1414
$runTestQuery = "EXEC tSQLt.Run '[$storedProc]'"
1515
$queryTimeout = 300
1616

17-
# Create connection
1817
$Hash = @{
19-
SqlInstance = $env:SQLINSTANCE
18+
ServerInstance = $env:SQLINSTANCE
2019
Database = $env:DATABASE
2120
Verbose = $true
22-
EnableException = $true
2321
}
2422

2523
# Install tests
2624
ForEach ($File in Get-ChildItem -Path $testPath -Filter $testInstallScript) {
27-
Invoke-DbaQuery @Hash -File $File.FullName
25+
Invoke-SqlCmd @Hash -InputFile $File.FullName
2826
}
2927
}
3028
It "All tests" {
31-
{ Invoke-DbaQuery @Hash -Query $runTestQuery -QueryTimeout $queryTimeout } | Should -Not -Throw -Because "tSQLt unit tests must pass"
29+
{ Invoke-SqlCmd @Hash -Query $runTestQuery -QueryTimeout $queryTimeout } | Should -Not -Throw -Because "tSQLt unit tests must pass"
3230
}
3331
}
3432
}

tests/sp_helpme.Tests.ps1

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,19 @@ Describe "sp_helpme" {
1414
$runTestQuery = "EXEC tSQLt.Run '[$storedProc]'"
1515
$queryTimeout = 300
1616

17-
# Create connection
1817
$Hash = @{
19-
SqlInstance = $env:SQLINSTANCE
18+
ServerInstance = $env:SQLINSTANCE
2019
Database = $env:DATABASE
2120
Verbose = $true
22-
EnableException = $true
2321
}
2422

2523
# Install tests
2624
ForEach ($File in Get-ChildItem -Path $testPath -Filter $testInstallScript) {
27-
Invoke-DbaQuery @Hash -File $File.FullName
25+
Invoke-SqlCmd @Hash -InputFile $File.FullName
2826
}
2927
}
3028
It "All tests" {
31-
{ Invoke-DbaQuery @Hash -Query $runTestQuery -QueryTimeout $queryTimeout } | Should -Not -Throw -Because "tSQLt unit tests must pass"
29+
{ Invoke-SqlCmd @Hash -Query $runTestQuery -QueryTimeout $queryTimeout } | Should -Not -Throw -Because "tSQLt unit tests must pass"
3230
}
3331
}
3432
}

tests/sp_sizeoptimiser.Tests.ps1

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,19 @@ Describe "sp_sizeoptimiser" {
1414
$runTestQuery = "EXEC tSQLt.Run '[$storedProc]'"
1515
$queryTimeout = 300
1616

17-
# Create connection
1817
$Hash = @{
19-
SqlInstance = $env:SQLINSTANCE
18+
ServerInstance = $env:SQLINSTANCE
2019
Database = $env:DATABASE
2120
Verbose = $true
22-
EnableException = $true
2321
}
2422

2523
# Install tests
2624
ForEach ($File in Get-ChildItem -Path $testPath -Filter $testInstallScript) {
27-
Invoke-DbaQuery @Hash -File $File.FullName
25+
Invoke-SqlCmd @Hash -InputFile $File.FullName
2826
}
2927
}
3028
It "All tests" {
31-
{ Invoke-DbaQuery @Hash -Query $runTestQuery -QueryTimeout $queryTimeout } | Should -Not -Throw -Because "tSQLt unit tests must pass"
29+
{ Invoke-SqlCmd @Hash -Query $runTestQuery -QueryTimeout $queryTimeout } | Should -Not -Throw -Because "tSQLt unit tests must pass"
3230
}
3331
}
3432
}

0 commit comments

Comments
 (0)