Skip to content

Commit 03f1438

Browse files
lowlydbaAppveyor
andauthored
Local test setup (#108)
- Add capabilities for local dev test script - Remove appveyor as source of truth - Share as much as possible between appveyor & local test script - Remove unneeded sql auth variables Co-authored-by: Appveyor <[email protected]>
1 parent df672e6 commit 03f1438

13 files changed

+131
-73
lines changed

appveyor/appveyor.yml

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@ environment:
99
secure: 'E5I+i+CQyj9EHusDrPSQKHRXmzmpTujYAoFxlvJjvSRSEQHHzqTBIFR1VuPbwLMi'
1010

1111
APPVEYOR_RDP_PASSWORD: Np^VNSzJI5#OmRdUNqro2T9UVkCdZ
12-
MSSQL_LOGIN: sa
13-
MSSQL_PASS: Password12!
14-
TSQLTSETCLR: tests\tSQLt\SetClrEnabled.sql
15-
TSQLTCREATEDB: tests\tSQLt\CreateDatabase.sql
16-
TSQLTINSTALL: tests\tSQLt\tSQLt.class.sql
17-
TSQLTBUILDPATH: tests\build
18-
TSQLTTESTPATH: tests\run
1912
TARGET_DB: tSQLt
2013
COV_REPORT: appveyor\sqlcover\Coverage.opencoverxml
2114

@@ -47,30 +40,28 @@ environment:
4740
LINT_CONFIG: appveyor\tsqllint\.tsqllintrc_110
4841

4942
clone_script:
50-
- git config --global credential.helper store
51-
- ps: Add-Content "$HOME\.git-credentials" "https://$($env:access_token):[email protected]`n" -NoNewLine
52-
- git config --global user.email "[email protected]"
53-
- git config --global user.name "Appveyor"
54-
- git config --global core.safecrlf false
55-
- git clone -q --single-branch --branch=%APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH% https://github.com/LowlyDBA/ExpressSQL.git %APPVEYOR_BUILD_FOLDER%
56-
- cd %APPVEYOR_BUILD_FOLDER%
43+
- git config --global credential.helper store
44+
- ps: Add-Content "$HOME\.git-credentials" "https://$($env:access_token):[email protected]`n" -NoNewLine
45+
- git config --global user.email "[email protected]"
46+
- git config --global user.name "Appveyor"
47+
- git config --global core.safecrlf false
48+
- git clone -q --single-branch --branch=%APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH% https://github.com/LowlyDBA/ExpressSQL.git %APPVEYOR_BUILD_FOLDER%
49+
- cd %APPVEYOR_BUILD_FOLDER%
5750

5851
install:
59-
- ps: Install-Module SqlServer -Force -AllowClobber
60-
- npm install tsqllint -g
61-
- ps: .\appveyor\start_sqlserver.ps1
62-
- ps: .\appveyor\install_tsqlt.ps1
52+
- ps: .\appveyor\install_dependencies.ps1
53+
- ps: .\appveyor\start_sqlserver.ps1
54+
- ps: .\appveyor\install_tsqlt.ps1
6355

6456
build_script:
65-
- ps: .\appveyor\make_combined_script.ps1
66-
- ps: .\appveyor\install_expsql.ps1
67-
- ps: .\appveyor\build_tsqlt_tests.ps1
68-
- echo Running TSQLLint tests
69-
- npx tsqllint -c %LINT_CONFIG% *.sql
57+
- ps: .\appveyor\make_combined_script.ps1
58+
- ps: .\appveyor\install_expsql.ps1
59+
- ps: .\appveyor\build_tsqlt_tests.ps1
7060

7161
# Non-covered test run
7262
test_script:
73-
- ps: .\appveyor\run_tsqlt_tests.ps1
63+
- ps: .\appveyor\run_tsqllint.ps1
64+
- ps: .\appveyor\run_tsqlt_tests.ps1
7465

7566
# Only run code cov & push changes on latest build env
7667
for:
@@ -81,8 +72,7 @@ for:
8172

8273
# Setup codecov, SQL Cover
8374
before_test:
84-
- ps: Install-Package GOEddie.SQLCover -Force | Out-Null
85-
- ps: choco install codecov --no-progress --limit-output | Out-Null
75+
- ps: .\appveyor\install_coverage_dependencies.ps1
8676

8777
# Run tests with SQL Cover analysis
8878
test_script:

appveyor/build_tsqlt_tests.ps1

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
Write-Host "Building tSQLt Tests"
1+
param(
2+
[Parameter()]
3+
$SqlInstance = $env:DB_INSTANCE,
4+
$Database = $env:TARGET_DB,
5+
$TestPath = "tests\build",
6+
$Color = "Green"
7+
)
28

3-
ForEach ($filename in Get-Childitem -Path $env:TSQLTBUILDPATH -Filter "*.sql") {
4-
Invoke-SqlCmd -ServerInstance $env:DB_INSTANCE -Database $env:TARGET_DB -InputFile $filename.fullname -Username $env:MSSQL_LOGIN -Password $env:MSSQL_PASS
9+
Write-Host "Building tSQLt Tests..." -ForegroundColor $Color
10+
11+
ForEach ($filename in Get-Childitem -Path $TestPath -Filter "*.sql") {
12+
Invoke-SqlCmd -ServerInstance $SqlInstance -Database $Database -InputFile $filename.fullname
513
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Install code coverage tool
2+
Install-Package GOEddie.SQLCover -Force | Out-Null
3+
4+
# Install codecov.io uploader
5+
choco install codecov --no-progress --limit-output | Out-Null

appveyor/install_dependencies.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
param(
2+
[Parameter()]
3+
$Color = "Green"
4+
)
5+
6+
Write-Host "Installing dependencies..." -ForegroundColor $Color
7+
8+
# TSQLLinter
9+
npm install tsqllint -g
10+
11+
# SQLServer Module
12+
if (!(Get-Module -ListAvailable -Name SqlServer)) {
13+
Install-Module SqlServer -Force -AllowClobber
14+
}

appveyor/install_expsql.ps1

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1-
Write-Host "Installing ExpressSQL Scripts"
1+
param(
2+
[Parameter()]
3+
$SqlInstance = $env:DB_INSTANCE,
4+
$Database = $env:TARGET_DB,
5+
$Color = "Green"
6+
)
27

3-
Invoke-SqlCmd -ServerInstance $env:DB_INSTANCE -Database $env:TARGET_DB -InputFile "install_expsql.sql" -Username $env:MSSQL_LOGIN -Password $env:MSSQL_PASS
8+
Write-Host "Installing ExpressSQL scripts..." -ForegroundColor $Color
9+
10+
Invoke-SqlCmd -ServerInstance $SqlInstance -Database $Database -InputFile "install_expsql.sql"

appveyor/install_tsqlt.ps1

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
Write-Host "Installing tSQLt"
1+
param(
2+
[Parameter()]
3+
$SqlInstance = $env:DB_INSTANCE,
4+
$Database = $env:TARGET_DB,
5+
$CLRScript = "tests\tSQLt\SetClrEnabled.sql",
6+
$CreateDBScript = "tests\tSQLt\CreateDatabase.sql",
7+
$tSQLtInstallScript = "tests\tSQLt\tSQLt.class.sql",
8+
$Color = "Green"
9+
)
10+
$Master = "master"
211

3-
$CLRScript = Join-Path $env:APPVEYOR_BUILD_FOLDER $env:TSQLTSETCLR
4-
$CreateDBScript = Join-Path $env:APPVEYOR_BUILD_FOLDER $env:TSQLTCREATEDB
5-
$tSQLtInstallScript = Join-Path $env:APPVEYOR_BUILD_FOLDER $env:TSQLTINSTALL
12+
Write-Host "Installing tSQLt..." -ForegroundColor $Color
613

7-
Invoke-SqlCmd -ServerInstance $env:DB_INSTANCE -Database "master" -InputFile $clrscript -Username $env:MSSQL_LOGIN -Password $env:MSSQL_PASS | Out-Null
8-
Invoke-SqlCmd -ServerInstance $env:DB_INSTANCE -Database "master" -InputFile $CreateDBScript -Username $env:MSSQL_LOGIN -Password $env:MSSQL_PASS | Out-Null
9-
Invoke-SqlCmd -ServerInstance $env:DB_INSTANCE -Database $env:TARGET_DB -InputFile $tSQLtInstallScript -Username $env:MSSQL_LOGIN -Password $env:MSSQL_PASS
14+
Invoke-SqlCmd -ServerInstance $SqlInstance -Database $Master -InputFile $clrscript | Out-Null
15+
Invoke-SqlCmd -ServerInstance $SqlInstance -Database $Master -InputFile $CreateDBScript | Out-Null
16+
Invoke-SqlCmd -ServerInstance $SqlInstance -Database $Database -InputFile $tSQLtInstallScript

appveyor/run_tsqllint.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
param(
2+
[Parameter()]
3+
$Config = $env:LINT_CONFIG,
4+
$Color = "Green"
5+
)
6+
7+
Write-Host "Running TSQLLint with config $Config..." -ForegroundColor $Color
8+
tsqllint -c $Config *.sql

appveyor/run_tsqlt_tests.ps1

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
param(
22
[Parameter()]
3-
$FilePath = $env:TSQLTTESTPATH,
3+
$FilePath = "tests\run",
44
$SqlInstance = $env:DB_INSTANCE,
55
$Database = $env:TARGET_DB,
6-
$SqlUser = $env:MSSQL_LOGIN,
7-
$SqlPass = $env:MSSQL_PASS,
8-
$SQLAuth = $true
6+
$Color = "Green"
97
)
108

11-
Write-Host "Run tSQLt Tests"
9+
Write-Host "Running tSQLt Tests..." -ForegroundColor $Color
1210

1311
ForEach ($filename in Get-Childitem -Path $FilePath -Filter "*.sql") {
14-
If ($SQLAuth) {
15-
Invoke-SqlCmd -ServerInstance $SqlInstance -Database $Database -InputFile $filename.fullname -Username $SqlUser -Password $SqlPass -Verbose | Out-Null
16-
}
17-
Else {
18-
Invoke-SqlCmd -ServerInstance $SqlInstance -Database $Database -InputFile $filename.fullname -Verbose | Out-Null
19-
}
12+
Invoke-SqlCmd -ServerInstance $SqlInstance -Database $Database -InputFile $filename.fullname -Verbose | Out-Null
2013
}

appveyor/sqlcover/Run_SQLCover.ps1

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ param(
77
$Database = $env:TARGET_DB,
88
$TrustedConnection = "yes",
99
$ConnString = "server=$SqlInstance;initial catalog=$Database;Trusted_Connection=$TrustedConnection",
10-
$ReportDest = $PSSCriptRoot,
11-
$TestPath = $env:TSQLTTESTPATH
10+
$CoverageXMLPath = $env:COV_REPORT,
11+
$Color = "Green"
1212
)
1313

1414
# Setup files
@@ -21,20 +21,22 @@ $SQLCoverDllFullPath = Join-Path $SQLCoverPath "SQLCover.dll"
2121
Add-Type -Path $SQLCoverDllFullPath
2222

2323
# Start covering
24+
Write-Host "Starting SQLCover..." -ForegroundColor $Color
2425
$SQLCover = new-object SQLCover.CodeCoverage($ConnString, $Database)
2526
$IsCoverStarted = $SQLCover.Start()
2627

2728
If ($IsCoverStarted) {
2829
# Run Tests
29-
. .\appveyor\run_tsqlt_tests.ps1 -FilePath $TestPath -SqlInstance $SqlInstance -Database $Database -SQLAuth $false
30+
. .\appveyor\run_tsqlt_tests.ps1 -SqlInstance $SqlInstance -Database $Database
3031

3132
# Stop covering
33+
Write-Host "Stopping SQLCover..." -ForegroundColor $Color
3234
$coverageResults = $SQLCover.Stop()
3335

3436
# Export results
37+
Write-Host "Generating code coverage report..." -ForegroundColor $Color
3538
If (!($LocalTest)) {
36-
$xmlPath = Join-Path -Path $ReportDest -ChildPath "Coverage.opencoverxml"
37-
$coverageResults.OpenCoverXml() | Out-File $xmlPath -Encoding utf8
39+
$coverageResults.OpenCoverXml() | Out-File $CoverageXMLPath -Encoding utf8
3840
$coverageResults.SaveSourceFiles($ReportDest)
3941
}
4042
Else { # Don't save any files and bring up html report for review

install_expsql.sql

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)