Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/integration-tests-s3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ jobs:
sudo update-ca-certificates
echo "MinIO certificate added to system trust store"

- name: Install Pester 6
run: |
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Install-Module -Name Pester -RequiredVersion 6.0.0 -Force -Scope CurrentUser -SkipPublisherCheck

- name: Install AWS.Tools.S3 for S3 enumeration tests
run: |
Write-Host "Installing AWS.Tools.Installer..."
Expand Down
8 changes: 4 additions & 4 deletions private/testing/Invoke-ManualPester.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ function Invoke-ManualPester {
$invokeFormatterVersion = (Get-Command Invoke-Formatter -ErrorAction SilentlyContinue).Version
$HasScriptAnalyzer = $null -ne $invokeFormatterVersion
$MinimumPesterVersion = [Version] '4.0.0.0' # Because this is when -Show was introduced
$MaximumPesterVersion = [Version] '6.0.0.0' # Because we have either pester4 or pester5 tests
$MaximumPesterVersion = [Version] '7.0.0.0' # Because we have either pester4 or pester5+ tests
$PesterVersion = (Get-Command Invoke-Pester -ErrorAction SilentlyContinue).Version
$HasPester = $null -ne $PesterVersion
$ScriptAnalyzerCorrectVersion = '1.18.2'
Expand Down Expand Up @@ -204,8 +204,8 @@ function Invoke-ManualPester {
Write-Warning " or go to https://github.com/pester/Pester"
}
if ($PesterVersion -gt $MaximumPesterVersion) {
Write-Warning "Please get Pester to the 5.* release"
Write-Warning " Install-Module -Name Pester -MaximumVersion '5.7.1' -Force -SkipPublisherCheck"
Write-Warning "Please get Pester to the 6.0.0 release"
Write-Warning " Install-Module -Name Pester -RequiredVersion '6.0.0' -Force -SkipPublisherCheck"
Write-Warning " or go to https://github.com/pester/Pester"
}

Expand Down Expand Up @@ -308,7 +308,7 @@ function Invoke-ManualPester {
if ($pesterVersionToUse -eq '5') {
Write-DetailedMessage "Running Pester 5 tests $($f.Name)"
Remove-Module -Name Pester -ErrorAction SilentlyContinue
Import-Module Pester -MinimumVersion 5.7.1 -ErrorAction Stop
Import-Module Pester -RequiredVersion 6.0.0 -ErrorAction Stop
$pester5Config = New-PesterConfiguration
$pester5Config.Run.Path = $f.FullName
if ($PassThru) {
Expand Down
2 changes: 2 additions & 0 deletions tests/Compare-DbaDbSchema.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ Describe $CommandName -Tag UnitTests {
$EnableException
)
}
Mock New-Object { & (Get-Command -Name 'New-Object' -CommandType Cmdlet) @PesterBoundParameters }
Mock New-Object {
New-MockCompareDbSchemaStartInfo
} -ParameterFilter {
Expand Down Expand Up @@ -178,6 +179,7 @@ Describe $CommandName -Tag UnitTests {
$script:capturedVerboseMessages += $Message
}
}
Mock New-Object { & (Get-Command -Name 'New-Object' -CommandType Cmdlet) @PesterBoundParameters }
Mock New-Object {
New-MockCompareDbSchemaStartInfo
} -ParameterFilter {
Expand Down
3 changes: 3 additions & 0 deletions tests/Connect-DbaInstance.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ Describe $CommandName -Tag UnitTests {
}

Mock Add-ConnectionHashValue { } -ModuleName dbatools
Mock New-Object { & (Get-Command -Name 'New-Object' -CommandType Cmdlet) @PesterBoundParameters } -ModuleName dbatools
Mock New-Object {
[PSCustomObject]@{ }
} -ModuleName dbatools -ParameterFilter {
Expand Down Expand Up @@ -168,6 +169,7 @@ Describe $CommandName -Tag UnitTests {
}

Mock Add-ConnectionHashValue { } -ModuleName dbatools
Mock New-Object { & (Get-Command -Name 'New-Object' -CommandType Cmdlet) @PesterBoundParameters } -ModuleName dbatools
Mock New-Object {
[PSCustomObject]@{
ConnectionString = "Data Source=sqltoken;Integrated Security=True"
Expand Down Expand Up @@ -224,6 +226,7 @@ Describe $CommandName -Tag UnitTests {
}

Mock Add-ConnectionHashValue { } -ModuleName dbatools
Mock New-Object { & (Get-Command -Name 'New-Object' -CommandType Cmdlet) @PesterBoundParameters } -ModuleName dbatools
Mock New-Object {
$script:lastServerConnection = [PSCustomObject]@{
ConnectionString = $ArgumentList[0].ConnectionString
Expand Down
4 changes: 2 additions & 2 deletions tests/Export-DbaCredential.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ Describe $CommandName -Tag UnitTests {
It "Should not force decryption errors to throw by default" {
$null = Export-DbaCredential -SqlInstance "sql1" -Passthru

Assert-MockCalled -CommandName Get-DecryptedObject -Exactly 1 -Scope It -ModuleName dbatools -ParameterFilter {
Should -Invoke -CommandName Get-DecryptedObject -Exactly 1 -Scope It -ModuleName dbatools -ParameterFilter {
-not $EnableException
}
}

It "Should request terminating decryption errors when EnableException is specified" {
$null = Export-DbaCredential -SqlInstance "sql1" -Passthru -EnableException

Assert-MockCalled -CommandName Get-DecryptedObject -Exactly 1 -Scope It -ModuleName dbatools -ParameterFilter {
Should -Invoke -CommandName Get-DecryptedObject -Exactly 1 -Scope It -ModuleName dbatools -ParameterFilter {
$EnableException
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Export-DbaLinkedServer.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ Describe $CommandName -Tag UnitTests {
It "Should not force decryption errors to throw by default" {
$null = Export-DbaLinkedServer -SqlInstance "sql1" -Passthru

Assert-MockCalled -CommandName Get-DecryptedObject -Exactly 1 -Scope It -ModuleName dbatools -ParameterFilter {
Should -Invoke -CommandName Get-DecryptedObject -Exactly 1 -Scope It -ModuleName dbatools -ParameterFilter {
-not $EnableException
}
}

It "Should request terminating decryption errors when EnableException is specified" {
$null = Export-DbaLinkedServer -SqlInstance "sql1" -Passthru -EnableException

Assert-MockCalled -CommandName Get-DecryptedObject -Exactly 1 -Scope It -ModuleName dbatools -ParameterFilter {
Should -Invoke -CommandName Get-DecryptedObject -Exactly 1 -Scope It -ModuleName dbatools -ParameterFilter {
$EnableException
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/Find-DbaInstance.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Describe $CommandName -Tag UnitTests {
}
function Write-Message {
}
Mock New-Object { & (Get-Command -Name 'New-Object' -CommandType Cmdlet) @PesterBoundParameters }
Mock New-Object {
New-MockFindDbaInstanceUdpClient -ResponseBytes $script:browserResponseBytes
} -ParameterFilter {
Expand Down
16 changes: 8 additions & 8 deletions tests/Get-DbaDatabase.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,18 @@ Describe $CommandName -Tag UnitTests -Skip {
'CommandName' = 'Stop-Function'
'Times' = 1
'Exactly' = $true
'Module' = 'dbatools'
'ModuleName' = 'dbatools'
}
Assert-MockCalled @assertMockParams
Should -Invoke @assertMockParams
}
It "Validates that Test-FunctionInterrupt Mock has been called" {
$assertMockParams = @{
'CommandName' = 'Test-FunctionInterrupt'
'Times' = 1
'Exactly' = $true
'Module' = 'dbatools'
'ModuleName' = 'dbatools'
}
Assert-MockCalled @assertMockParams
Should -Invoke @assertMockParams
}
}
Context "Output" {
Expand Down Expand Up @@ -237,18 +237,18 @@ Describe $CommandName -Tag UnitTests -Skip {
'CommandName' = 'Connect-DbaInstance'
'Times' = 2
'Exactly' = $true
'Module' = 'dbatools'
'ModuleName' = 'dbatools'
}
Assert-MockCalled @assertMockParams
Should -Invoke @assertMockParams
}
It "Validates that Invoke-QueryDBlastUsed Mock has been called" {
$assertMockParams = @{
'CommandName' = 'Invoke-QueryDBlastUsed'
'Times' = 2
'Exactly' = $true
'Module' = 'dbatools'
'ModuleName' = 'dbatools'
}
Assert-MockCalled @assertMockParams
Should -Invoke @assertMockParams
}
}
}
2 changes: 1 addition & 1 deletion tests/Get-DbaLastBackup.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Describe $CommandName -Tag UnitTests {
$results = @(Get-DbaLastBackup -SqlInstance "sql1" -Database "agdb" -ExcludeReplica)

$results | Should -BeNullOrEmpty
Assert-MockCalled -CommandName Get-DbaDbBackupHistory -Exactly 0 -Scope It -ModuleName dbatools
Should -Invoke -CommandName Get-DbaDbBackupHistory -Exactly 0 -Scope It -ModuleName dbatools
}
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/Get-DbaNetworkEncryption.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ Describe $CommandName -Tag UnitTests {
$Message
)
}
Mock New-Object { & (Get-Command -Name 'New-Object' -CommandType Cmdlet) @PesterBoundParameters }
Mock New-Object {
New-MockNetworkEncryptionUdpClient
} -ParameterFilter {
Expand Down
4 changes: 2 additions & 2 deletions tests/Get-DbaService.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ Describe $CommandName -Tag UnitTests {

$results | Should -HaveCount 1
$results.ServiceType | Should -Be "PowerBI"
Assert-MockCalled Get-DbaReportingService -Times 1 -Exactly -Scope It
Assert-MockCalled Get-DbaCmObject -Times 0 -Exactly -Scope It -ParameterFilter { $Namespace -eq "root\Microsoft\SQLServer" }
Should -Invoke Get-DbaReportingService -Times 1 -Exactly -Scope It
Should -Invoke Get-DbaCmObject -Times 0 -Exactly -Scope It -ParameterFilter { $Namespace -eq "root\Microsoft\SQLServer" }
}
}
}
Expand Down
56 changes: 34 additions & 22 deletions tests/Install-DbaInstance.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ Describe $CommandName -Tag IntegrationTests {
Mock -CommandName Set-DbaTcpPort -ModuleName dbatools -MockWith { }
Mock -CommandName Restart-DbaService -ModuleName dbatools -MockWith { }
Mock -CommandName Get-DbaCmObject -ModuleName dbatools -MockWith { [PSCustomObject]@{ NumberOfLogicalProcessors = 24 } } -ParameterFilter { $ClassName -eq "Win32_processor" }
# Resolve the (local) host without touching the network. Resolve-DbaNetworkName
# internally calls Get-DbaCmObject -ClassName win32_ComputerSystem, which is not
# covered by the Win32_processor mock above; under Pester 6 an unmatched
# parameter-filtered mock throws instead of falling through to the real command,
# so we mock the whole resolver to keep the tests offline and deterministic
# (matches Update-DbaInstance.Tests.ps1).
Mock -CommandName Resolve-DbaNetworkName -ModuleName dbatools -MockWith {
[PSCustomObject]@{
ComputerName = $env:COMPUTERNAME
FullComputerName = $env:COMPUTERNAME
}
}
# mock searching for setup, proper file should always it find
Mock -CommandName Find-SqlInstanceSetup -MockWith {
Get-ChildItem $Path -Filter "dummy.exe" -ErrorAction Stop | Select-Object -ExpandProperty FullName -First 1
Expand Down Expand Up @@ -104,9 +116,9 @@ Describe $CommandName -Tag IntegrationTests {
) | Set-Content -Path TestDrive:\Configuration.ini -Force

$result = Install-DbaInstance -Version $version -Path TestDrive: -EnableException -Feature All
Assert-MockCalled -CommandName Invoke-Program -Exactly 1 -Scope It -ModuleName dbatools
Assert-MockCalled -CommandName Find-SqlInstanceSetup -Exactly 1 -Scope It -ModuleName dbatools
Assert-MockCalled -CommandName Test-PendingReboot -Exactly 3 -Scope It -ModuleName dbatools
Should -Invoke -CommandName Invoke-Program -Exactly 1 -Scope It -ModuleName dbatools
Should -Invoke -CommandName Find-SqlInstanceSetup -Exactly 1 -Scope It -ModuleName dbatools
Should -Invoke -CommandName Test-PendingReboot -Exactly 3 -Scope It -ModuleName dbatools

$result | Should -Not -BeNullOrEmpty
$result.ComputerName | Should -BeLike $env:COMPUTERNAME*
Expand Down Expand Up @@ -148,16 +160,16 @@ Describe $CommandName -Tag IntegrationTests {
AdminAccount = "local\foo", "local\bar"
}
$result = Install-DbaInstance @splatInstall -EnableException
Assert-MockCalled -CommandName Invoke-Program -Exactly 1 -Scope It -ModuleName dbatools
Assert-MockCalled -CommandName Find-SqlInstanceSetup -Exactly 1 -Scope It -ModuleName dbatools
Assert-MockCalled -CommandName Test-PendingReboot -Exactly 3 -Scope It -ModuleName dbatools
Should -Invoke -CommandName Invoke-Program -Exactly 1 -Scope It -ModuleName dbatools
Should -Invoke -CommandName Find-SqlInstanceSetup -Exactly 1 -Scope It -ModuleName dbatools
Should -Invoke -CommandName Test-PendingReboot -Exactly 3 -Scope It -ModuleName dbatools
if ($version -in "2008", "2008R2", "2012", "2014") {
Assert-MockCalled -CommandName Set-DbaPrivilege -Exactly 1 -Scope It -ModuleName dbatools
Should -Invoke -CommandName Set-DbaPrivilege -Exactly 1 -Scope It -ModuleName dbatools
} else {
# SQLSVCINSTANTFILEINIT is used for version 2016 and later
Assert-MockCalled -CommandName Set-DbaPrivilege -Exactly 0 -Scope It -ModuleName dbatools
Should -Invoke -CommandName Set-DbaPrivilege -Exactly 0 -Scope It -ModuleName dbatools
}
Assert-MockCalled -CommandName Set-DbaTcpPort -Exactly 1 -Scope It -ModuleName dbatools
Should -Invoke -CommandName Set-DbaTcpPort -Exactly 1 -Scope It -ModuleName dbatools

$result | Should -Not -BeNullOrEmpty
$result.ComputerName | Should -BeLike $env:COMPUTERNAME*
Expand Down Expand Up @@ -204,9 +216,9 @@ Describe $CommandName -Tag IntegrationTests {
ConfigurationFile = "TestDrive:\Configuration.ini"
}
$result = Install-DbaInstance @splatConfig -EnableException
Assert-MockCalled -CommandName Invoke-Program -Exactly 1 -Scope It -ModuleName dbatools
Assert-MockCalled -CommandName Find-SqlInstanceSetup -Exactly 1 -Scope It -ModuleName dbatools
Assert-MockCalled -CommandName Test-PendingReboot -Exactly 3 -Scope It -ModuleName dbatools
Should -Invoke -CommandName Invoke-Program -Exactly 1 -Scope It -ModuleName dbatools
Should -Invoke -CommandName Find-SqlInstanceSetup -Exactly 1 -Scope It -ModuleName dbatools
Should -Invoke -CommandName Test-PendingReboot -Exactly 3 -Scope It -ModuleName dbatools

$result | Should -Not -BeNullOrEmpty
$result.ComputerName | Should -BeLike $env:COMPUTERNAME*
Expand Down Expand Up @@ -237,9 +249,9 @@ Describe $CommandName -Tag IntegrationTests {
) {
param($version, $canonicVersion, $mainNode)
$result = Install-DbaInstance -Version $version -Path TestDrive: -EnableException -UpdateSourcePath TestDrive:
Assert-MockCalled -CommandName Invoke-Program -Exactly 1 -Scope It -ModuleName dbatools
Assert-MockCalled -CommandName Find-SqlInstanceSetup -Exactly 1 -Scope It -ModuleName dbatools
Assert-MockCalled -CommandName Test-PendingReboot -Exactly 3 -Scope It -ModuleName dbatools
Should -Invoke -CommandName Invoke-Program -Exactly 1 -Scope It -ModuleName dbatools
Should -Invoke -CommandName Find-SqlInstanceSetup -Exactly 1 -Scope It -ModuleName dbatools
Should -Invoke -CommandName Test-PendingReboot -Exactly 3 -Scope It -ModuleName dbatools

$result | Should -Not -BeNullOrEmpty
$result.ComputerName | Should -BeLike $env:COMPUTERNAME*
Expand Down Expand Up @@ -273,10 +285,10 @@ Describe $CommandName -Tag IntegrationTests {
Restart = $true
}
$result = Install-DbaInstance @splatRestart -EnableException
Assert-MockCalled -CommandName Invoke-Program -Exactly 1 -Scope It -ModuleName dbatools
Assert-MockCalled -CommandName Find-SqlInstanceSetup -Exactly 1 -Scope It -ModuleName dbatools
Assert-MockCalled -CommandName Test-PendingReboot -Exactly 3 -Scope It -ModuleName dbatools
Assert-MockCalled -CommandName Restart-Computer -Exactly 1 -Scope It -ModuleName dbatools
Should -Invoke -CommandName Invoke-Program -Exactly 1 -Scope It -ModuleName dbatools
Should -Invoke -CommandName Find-SqlInstanceSetup -Exactly 1 -Scope It -ModuleName dbatools
Should -Invoke -CommandName Test-PendingReboot -Exactly 3 -Scope It -ModuleName dbatools
Should -Invoke -CommandName Restart-Computer -Exactly 1 -Scope It -ModuleName dbatools

$result | Should -Not -BeNullOrEmpty
$result.ComputerName | Should -BeLike $env:COMPUTERNAME*
Expand Down Expand Up @@ -313,9 +325,9 @@ Describe $CommandName -Tag IntegrationTests {
Feature = "Tools"
}
$result = Install-DbaInstance @splatTools -EnableException
Assert-MockCalled -CommandName Invoke-Program -Exactly 1 -Scope It -ModuleName dbatools
Assert-MockCalled -CommandName Find-SqlInstanceSetup -Exactly 1 -Scope It -ModuleName dbatools
Assert-MockCalled -CommandName Test-PendingReboot -Exactly 3 -Scope It -ModuleName dbatools
Should -Invoke -CommandName Invoke-Program -Exactly 1 -Scope It -ModuleName dbatools
Should -Invoke -CommandName Find-SqlInstanceSetup -Exactly 1 -Scope It -ModuleName dbatools
Should -Invoke -CommandName Test-PendingReboot -Exactly 3 -Scope It -ModuleName dbatools

$result | Should -Not -BeNullOrEmpty
$result.Version | Should -Be $canonicVersion
Expand Down
Loading