-
-
Notifications
You must be signed in to change notification settings - Fork 812
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c61359
commit 69b7dc3
Showing
24 changed files
with
1,117 additions
and
530 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,46 @@ | ||
$commandname = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") | ||
Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan | ||
#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} | ||
param($ModuleName = "dbatools") | ||
$global:TestConfig = Get-TestConfig | ||
|
||
Describe "$CommandName Unit Tests" -Tags "UnitTests" { | ||
Context "Validate parameters" { | ||
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')} | ||
[object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'EnableException' | ||
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters | ||
It "Should only contain our specific parameters" { | ||
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object {$_}) -DifferenceObject $params).Count ) | Should Be 0 | ||
Describe "Add-DbaDbMirrorMonitor" -Tag "UnitTests" { | ||
Context "Parameter validation" { | ||
BeforeAll { | ||
$command = Get-Command Add-DbaDbMirrorMonitor | ||
$expectedParameters = $TestConfig.CommonParameters | ||
|
||
$expectedParameters += @( | ||
"SqlInstance", | ||
"SqlCredential", | ||
"EnableException" | ||
) | ||
} | ||
|
||
It "Has parameter: <_>" -ForEach $expectedParameters { | ||
$command | Should -HaveParameter $PSItem | ||
} | ||
|
||
It "Should have exactly the number of expected parameters" { | ||
$actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } | ||
Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty | ||
} | ||
} | ||
} | ||
|
||
Describe "$commandname Integration Tests" -Tag "IntegrationTests" { | ||
Describe "Add-DbaDbMirrorMonitor" -Tag "IntegrationTests" { | ||
BeforeAll { | ||
$null = Remove-DbaDbMirrorMonitor -SqlInstance $TestConfig.instance2 -WarningAction SilentlyContinue | ||
} | ||
AfterAll { | ||
$null = Remove-DbaDbMirrorMonitor -SqlInstance $TestConfig.instance2 -WarningAction SilentlyContinue | ||
} | ||
|
||
It "adds the mirror monitor" { | ||
$results = Add-DbaDbMirrorMonitor -SqlInstance $TestConfig.instance2 -WarningAction SilentlyContinue | ||
$results.MonitorStatus | Should -Be 'Added' | ||
Context "When adding mirror monitor" { | ||
BeforeAll { | ||
$results = Add-DbaDbMirrorMonitor -SqlInstance $TestConfig.instance2 -WarningAction SilentlyContinue | ||
} | ||
|
||
It "Adds the mirror monitor" { | ||
$results.MonitorStatus | Should -Be 'Added' | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,62 @@ | ||
$CommandName = $MyInvocation.MyCommand.Name.Replace(".Tests.ps1", "") | ||
Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan | ||
#Requires -Module @{ ModuleName="Pester"; ModuleVersion="5.0"} | ||
param($ModuleName = "dbatools") | ||
$global:TestConfig = Get-TestConfig | ||
|
||
Describe "$CommandName Unit Tests" -Tag 'UnitTests' { | ||
Context "Validate parameters" { | ||
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')} | ||
[object[]]$knownParameters = 'ComputerName', 'Credential', 'CollectorSet', 'Collector', 'Counter', 'InputObject', 'EnableException' | ||
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters | ||
It "Should only contain our specific parameters" { | ||
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object {$_}) -DifferenceObject $params).Count ) | Should Be 0 | ||
Describe "Add-DbaPfDataCollectorCounter" -Tag "UnitTests" { | ||
Context "Parameter validation" { | ||
BeforeAll { | ||
$command = Get-Command Add-DbaPfDataCollectorCounter | ||
$expectedParameters = $TestConfig.CommonParameters | ||
|
||
$expectedParameters += @( | ||
"ComputerName", | ||
"Credential", | ||
"CollectorSet", | ||
"Collector", | ||
"Counter", | ||
"InputObject", | ||
"EnableException" | ||
) | ||
} | ||
|
||
It "Has parameter: <_>" -ForEach $expectedParameters { | ||
$command | Should -HaveParameter $PSItem | ||
} | ||
|
||
It "Should have exactly the number of expected parameters" { | ||
$actualParameters = $command.Parameters.Keys | Where-Object { $PSItem -notin "WhatIf", "Confirm" } | ||
Compare-Object -ReferenceObject $expectedParameters -DifferenceObject $actualParameters | Should -BeNullOrEmpty | ||
} | ||
} | ||
} | ||
|
||
Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { | ||
BeforeEach { | ||
Describe "Add-DbaPfDataCollectorCounter" -Tag "IntegrationTests" { | ||
BeforeAll { | ||
$null = Get-DbaPfDataCollectorSetTemplate -Template 'Long Running Queries' | Import-DbaPfDataCollectorSetTemplate | | ||
Get-DbaPfDataCollector | Get-DbaPfDataCollectorCounter -Counter '\LogicalDisk(*)\Avg. Disk Queue Length' | Remove-DbaPfDataCollectorCounter -Confirm:$false | ||
} | ||
|
||
AfterAll { | ||
$null = Get-DbaPfDataCollectorSet -CollectorSet 'Long Running Queries' | Remove-DbaPfDataCollectorSet -Confirm:$false | ||
} | ||
Context "Verifying command returns all the required results" { | ||
It "returns the correct values" { | ||
$results = Get-DbaPfDataCollectorSet -CollectorSet 'Long Running Queries' | Get-DbaPfDataCollector | Add-DbaPfDataCollectorCounter -Counter '\LogicalDisk(*)\Avg. Disk Queue Length' | ||
$results.DataCollectorSet | Should Be 'Long Running Queries' | ||
$results.Name | Should Be '\LogicalDisk(*)\Avg. Disk Queue Length' | ||
|
||
Context "When adding a counter to a data collector" { | ||
BeforeAll { | ||
$splatAddCounter = @{ | ||
CollectorSet = 'Long Running Queries' | ||
Counter = '\LogicalDisk(*)\Avg. Disk Queue Length' | ||
} | ||
$results = Get-DbaPfDataCollectorSet @splatAddCounter | | ||
Get-DbaPfDataCollector | | ||
Add-DbaPfDataCollectorCounter @splatAddCounter | ||
} | ||
|
||
It "Returns the correct DataCollectorSet" { | ||
$results.DataCollectorSet | Should -Be 'Long Running Queries' | ||
} | ||
|
||
It "Returns the correct counter name" { | ||
$results.Name | Should -Be '\LogicalDisk(*)\Avg. Disk Queue Length' | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.