Skip to content

Commit 6860ee6

Browse files
authored
first pester5 test (do Invoke-DbaQuery) (#9525)
1 parent c0feb7a commit 6860ee6

File tree

3 files changed

+29
-21
lines changed

3 files changed

+29
-21
lines changed

tests/Invoke-DbaQuery.Tests.ps1

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
1-
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "")
2-
Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
3-
$global:TestConfig = Get-TestConfig
1+
#HaveParameter - yeah, I know.
2+
3+
BeforeAll {
4+
$CommandName = (Get-Item $PSCommandPath).Name.Replace(".Tests.ps1", "")
5+
Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan
6+
$global:TestConfig = Get-TestConfig
7+
}
8+
49

510
Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
611
Context "Validate parameters" {
7-
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object { $_ -notin ('whatif', 'confirm') }
8-
[object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'Database', 'Query', 'QueryTimeout', 'File', 'SqlObject', 'As', 'SqlParameter', 'AppendServerInstance', 'MessagesToOutput', 'InputObject', 'ReadOnly', 'EnableException', 'CommandType', 'NoExec'
9-
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
12+
BeforeAll {
13+
$command = Get-Command Invoke-DbaQuery
14+
}
1015
It "Should only contain our specific parameters" {
11-
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object { $_ }) -DifferenceObject $params).Count ) | Should Be 0
16+
[object[]]$params = $command.Parameters.Keys | Where-Object { $_ -notin ('whatif', 'confirm') }
17+
[object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'Database', 'Query', 'QueryTimeout', 'File', 'SqlObject', 'As', 'SqlParameter', 'AppendServerInstance', 'MessagesToOutput', 'InputObject', 'ReadOnly', 'EnableException', 'CommandType', 'NoExec'
18+
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
19+
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object { $_ }) -DifferenceObject $params).Count ) | Should -Be 0
1220
}
1321
}
1422
Context "Validate alias" {
@@ -65,7 +73,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" {
6573
}
6674
It "stops when piped databases and -Database" {
6775
$dbs = Get-DbaDatabase -SqlInstance $TestConfig.instance2, $TestConfig.instance3
68-
{ $dbs | Invoke-DbaQuery -Query "Select 'hello' as TestColumn, DB_NAME() as dbname" -Database tempdb -EnableException } | Should Throw "You can't"
76+
{ $dbs | Invoke-DbaQuery -Query "Select 'hello' as TestColumn, DB_NAME() as dbname" -Database tempdb -EnableException } | Should -Throw "You can't*"
6977
}
7078
It "supports reading files" {
7179
$testPath = "TestDrive:\dbasqlquerytest.txt"
@@ -108,7 +116,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" {
108116
$null = Invoke-DbaQuery -SqlInstance $TestConfig.instance3 -Database tempdb -SqlObject $smoobj
109117
$check = "SELECT name FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[CommandLog]') AND type in (N'U')"
110118
$results = Invoke-DbaQuery -SqlInstance $TestConfig.instance3 -Database tempdb -Query $check
111-
$results.Name | Should Be 'CommandLog'
119+
$results.Name | Should -Be 'CommandLog'
112120
$null = Invoke-DbaQuery -SqlInstance $TestConfig.instance2, $TestConfig.instance3 -Database tempdb -Query $cleanup
113121
}
114122
<#
@@ -187,7 +195,7 @@ SELECT @@servername as dbname
187195
}
188196
It "Executes stored procedures with parameters" {
189197
$results = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database tempdb -Query "dbatoolsci_procedure_example" -SqlParameters @{p1 = 1 } -CommandType StoredProcedure
190-
$results.TestColumn | Should Be 1
198+
$results.TestColumn | Should -Be 1
191199
}
192200
It "Executes script file with a relative path (see #6184)" {
193201
Set-Content -Path ".\hellorelative.sql" -Value "Select 'hello' as TestColumn, DB_NAME() as dbname"
@@ -324,7 +332,7 @@ SELECT 2
324332
$result = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database tempdb -Query $q -NoExec
325333
$result | Should -BeNullOrEmpty
326334

327-
{ Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database tempdb -Query "SELEC p FROM c" -NoExec -EnableException } | Should -Throw "Incorrect syntax near 'selec'"
335+
{ Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Database tempdb -Query "SELEC p FROM c" -NoExec -EnableException } | Should -Throw "Incorrect syntax near 'SELEC'."
328336
}
329337

330338
It "supports dropping temp objects (#8472)" {
@@ -345,7 +353,4 @@ SELECT 2
345353
$results = Invoke-DbaQuery -SqlInstance $TestConfig.instance2 -Query "select cast(null as hierarchyid)"
346354
$results.Column1 | Should -Be "NULL"
347355
}
348-
349-
350356
}
351-

tests/appveyor.pester.ps1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,9 @@ if (-not $Finalize) {
277277
$outcome = "Passed"
278278
if ($PesterRun.FailedCount -gt 0) {
279279
$trialno += 1
280-
Update-AppveyorTest -Name $appvTestName -Framework NUnit -FileName $f.FullName -Outcome "Failed" -Duration $PesterRun.Time.TotalMilliseconds
280+
Update-AppveyorTest -Name $appvTestName -Framework NUnit -FileName $f.FullName -Outcome "Failed" -Duration $PesterRun.Duration.TotalMilliseconds
281281
} else {
282-
Update-AppveyorTest -Name $appvTestName -Framework NUnit -FileName $f.FullName -Outcome "Passed" -Duration $PesterRun.Time.TotalMilliseconds
282+
Update-AppveyorTest -Name $appvTestName -Framework NUnit -FileName $f.FullName -Outcome "Passed" -Duration $PesterRun.Duration.TotalMilliseconds
283283
break
284284
}
285285
}
@@ -331,7 +331,8 @@ if (-not $Finalize) {
331331
Get-ChildItem $ModuleBase\dbatools_messages_and_errors.xml.zip | ForEach-Object { Push-AppveyorArtifact $_.FullName -FileName $_.Name }
332332
}
333333
#$totalcount = $results | Select-Object -ExpandProperty TotalCount | Measure-Object -Sum | Select-Object -ExpandProperty Sum
334-
$failedcount = $results | Select-Object -ExpandProperty FailedCount | Measure-Object -Sum | Select-Object -ExpandProperty Sum
334+
$failedcount = 0
335+
$failedcount += $results | Select-Object -ExpandProperty FailedCount | Measure-Object -Sum | Select-Object -ExpandProperty Sum
335336
if ($failedcount -gt 0) {
336337
# pester 4 output
337338
$faileditems = $results | Select-Object -ExpandProperty TestResult | Where-Object { $_.Passed -notlike $True }
@@ -353,6 +354,7 @@ if (-not $Finalize) {
353354

354355

355356
$results5 = @(Get-ChildItem -Path "$ModuleBase\Pester5Results*.xml" | Import-Clixml)
357+
$failedcount += $results | Select-Object -ExpandProperty FailedCount | Measure-Object -Sum | Select-Object -ExpandProperty Sum
356358
# pester 5 output
357359
$faileditems = $results5 | Select-Object -ExpandProperty Tests | Where-Object { $_.Passed -notlike $True }
358360
if ($faileditems) {

tests/appveyor.post.ps1

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ Add-AppveyorTest -Name "appveyor.post" -Framework NUnit -FileName "appveyor.post
22
$sw = [system.diagnostics.stopwatch]::startNew()
33
Write-Host -Object "appveyor.post: Sending coverage data (pester 4)" -ForeGroundColor DarkGreen
44
Push-AppveyorArtifact PesterResultsCoverage.json -FileName "PesterResultsCoverage"
5-
codecov -f PesterResultsCoverage.json --flag "ps,$($env:SCENARIO.ToLowerInvariant())" | Out-Null
5+
codecov -f PesterResultsCoverage.json --flag "pester4_$($env:SCENARIO.ToLowerInvariant())" | Out-Null
66

77
Write-Host -Object "appveyor.post: Sending coverage data (pester 5)" -ForeGroundColor DarkGreen
8-
$ProjectRoot = $env:APPVEYOR_BUILD_FOLDER,
9-
$ModuleBase = $ProjectRoot,
8+
$ProjectRoot = $env:APPVEYOR_BUILD_FOLDER
9+
$ModuleBase = $ProjectRoot
1010
$pester5CoverageFiles = Get-ChildItem -Path "$ModuleBase\Pester5Coverage*.xml"
1111
foreach($coverageFile in $pester5CoverageFiles)
1212
{
13+
Write-Host -Object "appveyor.post: Sending $($coverageFile.FullName)" -ForeGroundColor DarkGreen
1314
Push-AppveyorArtifact $coverageFile.FullName -FileName $coverageFile.Name
14-
codecov -f $coverageFile.FullName --flag "ps,$($env:SCENARIO.ToLowerInvariant())" | Out-Null
15+
codecov -f $coverageFile.FullName --flag "pester5_$($env:SCENARIO.ToLowerInvariant())" | Out-Null
1516
}
1617

1718
$sw.Stop()

0 commit comments

Comments
 (0)