diff --git a/tests/Backup-DbaDatabase.Tests.ps1 b/tests/Backup-DbaDatabase.Tests.ps1 index 26889a9db6..997f4cf0fc 100644 --- a/tests/Backup-DbaDatabase.Tests.ps1 +++ b/tests/Backup-DbaDatabase.Tests.ps1 @@ -50,7 +50,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "No database found to backup should raise warning and null output" { - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -BackupDirectory $DestBackupDir -Database AliceDoesntDBHereAnyMore -WarningVariable warnvar + $results = Backup-DbaDatabase -SqlInstance $script:instance1 -BackupDirectory $DestBackupDir -Database AliceDoesntDBHereAnyMore -WarningVariable warnvar 3> $null It "Should not return object" { $results | Should -Be $null } @@ -116,10 +116,9 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $warnvar | Should -BeLike "*$MissingPath*" } # $MissingPathTrailing has a trailing slash but we normalize the path before doing the actual backup - $results = Backup-DbaDatabase -SqlInstance $script:instance1 -Database master -BackupDirectory $MissingPathTrailing -WarningVariable warnvar -BuildPath + $results = Backup-DbaDatabase -SqlInstance $script:instance1 -Database master -BackupDirectory $MissingPathTrailing -BuildPath It "Should have backed up to $MissingPath" { $results.BackupFolder | Should -Be "$MissingPath" - $results.Path | Should -Not -BeLike '*\\*' } } @@ -246,9 +245,9 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } Context "Test Backup-DbaDatabase can take pipe input" { - $results = Get-DbaDatabase -SqlInstance $script:instance1 -Database master | Backup-DbaDatabase -confirm:$false -WarningVariable warnvar + $results = Get-DbaDatabase -SqlInstance $script:instance1 -Database master | Backup-DbaDatabase -confirm:$false -WarningVariable warnvar 3> $null It "Should not warn" { - '' -eq $warnvar | Should -Be $True + $warnvar | Should -BeNullOrEmpty } It "Should Complete Successfully" { $results.BackupComplete | Should -Be $true diff --git a/tests/Backup-DbaDbCertificate.Tests.ps1 b/tests/Backup-DbaDbCertificate.Tests.ps1 index 85e62dd1cf..445de01875 100644 --- a/tests/Backup-DbaDbCertificate.Tests.ps1 +++ b/tests/Backup-DbaDbCertificate.Tests.ps1 @@ -43,7 +43,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { It "warns the caller if the cert cannot be found" { $invalidDBCertName = "dbatoolscli_invalidCertName" $invalidDBCertName2 = "dbatoolscli_invalidCertName2" - $results = Backup-DbaDbCertificate -SqlInstance $script:instance1 -Certificate $invalidDBCertName, $invalidDBCertName2, $cert2.Name -Database $db1Name -EncryptionPassword $pw -DecryptionPassword $pw -WarningVariable warnVariable + $results = Backup-DbaDbCertificate -SqlInstance $script:instance1 -Certificate $invalidDBCertName, $invalidDBCertName2, $cert2.Name -Database $db1Name -EncryptionPassword $pw -DecryptionPassword $pw -WarningVariable warnVariable 3> $null $null = Get-ChildItem -Path $results.Path -ErrorAction Ignore | Remove-Item -Confirm:$false -ErrorAction Ignore #$results.Certificate | Should -Be $cert2.Name $warnVariable | Should -BeLike "*Database certificate(s) * not found*" diff --git a/tests/ConvertTo-DbaDataTable.Tests.ps1 b/tests/ConvertTo-DbaDataTable.Tests.ps1 index 9c396c2a38..4d1fb2a3a3 100644 --- a/tests/ConvertTo-DbaDataTable.Tests.ps1 +++ b/tests/ConvertTo-DbaDataTable.Tests.ps1 @@ -267,8 +267,8 @@ Describe "Testing input parameters" { } It "Suppresses warning messages when Silent is used" { - $null = ConvertTo-DbaDataTable -InputObject (returnnull) -IgnoreNull -EnableException -WarningVariable warn -WarningAction SilentlyContinue - $warn.message -eq $null | Should -Be $true + $null = ConvertTo-DbaDataTable -InputObject (returnnull) -IgnoreNull -EnableException -WarningVariable warn -WarningAction SilentlyContinue 3> $null + $warn | Should -BeNullOrEmpty } } diff --git a/tests/Copy-DbaAgentAlert.Tests.ps1 b/tests/Copy-DbaAgentAlert.Tests.ps1 index bea925fb23..b4361ae41f 100644 --- a/tests/Copy-DbaAgentAlert.Tests.ps1 +++ b/tests/Copy-DbaAgentAlert.Tests.ps1 @@ -63,7 +63,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } It "Skips alerts where destination is missing the operator" { - $results = Copy-DbaAgentAlert -Source $script:instance2 -Destination $script:instance3 -Alert $alert2 -WarningVariable warningInfo -WarningAction SilentlyContinue + $results = Copy-DbaAgentAlert -Source $script:instance2 -Destination $script:instance3 -Alert $alert2 -WarningAction SilentlyContinue $results.Status -eq 'Skipped', 'Skipped' } diff --git a/tests/Copy-DbaBackupDevice.Tests.ps1 b/tests/Copy-DbaBackupDevice.Tests.ps1 index 786e9f8ae7..eac4f6ad8a 100644 --- a/tests/Copy-DbaBackupDevice.Tests.ps1 +++ b/tests/Copy-DbaBackupDevice.Tests.ps1 @@ -34,10 +34,10 @@ if (-not $env:appveyor) { } } - $results = Copy-DbaBackupDevice -Source $script:instance1 -Destination $script:instance2 -WarningVariable warn -WarningAction SilentlyContinue + $results = Copy-DbaBackupDevice -Source $script:instance1 -Destination $script:instance2 -WarningVariable warn -WarningAction SilentlyContinue 3> $null if ($warn) { It "warns if it has a problem moving (issue for local to local)" { - $warn -match "backup device to destination" | Should Be $true + $warn | Should -Match "backup device to destination" } } else { It "should report success" { diff --git a/tests/Copy-DbaCredential.Tests.ps1 b/tests/Copy-DbaCredential.Tests.ps1 index d99f72da41..4cdaaa52a0 100644 --- a/tests/Copy-DbaCredential.Tests.ps1 +++ b/tests/Copy-DbaCredential.Tests.ps1 @@ -128,7 +128,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { It -Skip:(-not $cryptoProvider) "check warning message if crypto provider is not configured/enabled on destination" { Remove-DbaCredential -SqlInstance $instance3 -Credential dbatoolsci_thor_crypto -Confirm:$false $instance3.Query("ALTER CRYPTOGRAPHIC PROVIDER $cryptoProvider DISABLE") - $results = Copy-DbaCredential -Source $instance2 -Destination $instance3 -Name dbatoolsci_thor_crypto -WarningVariable warnings + $results = Copy-DbaCredential -Source $instance2 -Destination $instance3 -Name dbatoolsci_thor_crypto $instance3.Query("ALTER CRYPTOGRAPHIC PROVIDER $cryptoProvider ENABLE") $results.Status | Should Be Failed $results.Notes | Should -Match "The cryptographic provider $cryptoProvider needs to be configured and enabled on" diff --git a/tests/Copy-DbaDatabase.Tests.ps1 b/tests/Copy-DbaDatabase.Tests.ps1 index 32254a67cd..3a071e937a 100644 --- a/tests/Copy-DbaDatabase.Tests.ps1 +++ b/tests/Copy-DbaDatabase.Tests.ps1 @@ -182,9 +182,8 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } It "Should warn if trying to rename and prefix" { - $results = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb -BackupRestore -SharedPath $NetworkPath -NewName $newname -prefix pre -WarningVariable warnvar + $null = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb -BackupRestore -SharedPath $NetworkPath -NewName $newname -prefix pre -WarningVariable warnvar 3> $null $warnvar | Should -BeLike "*NewName and Prefix are exclusive options, cannot specify both" - } It "Should prefix databasename and files" { @@ -219,9 +218,8 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { $null = Restore-DbaDatabase -SqlInstance $script:instance2 -path $script:appveyorlabrepo\RestoreTimeClean2016 -useDestinationDefaultDirectories It "Should warn and exit if newname and >1 db specified" { - $prefix = "copy$(Get-Random)" - $results = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb, RestoreTimeClean -DetachAttach -Reattach -NewName warn -WarningVariable warnvar - $Warnvar | Should -BeLike "*Cannot use NewName when copying multiple databases" + $null = Copy-DbaDatabase -Source $script:instance2 -Destination $script:instance3 -Database $backuprestoredb, RestoreTimeClean -DetachAttach -Reattach -NewName warn -WarningVariable warnvar 3> $null + $warnvar | Should -BeLike "*Cannot use NewName when copying multiple databases" } } diff --git a/tests/Copy-DbaDbTableData.Tests.ps1 b/tests/Copy-DbaDbTableData.Tests.ps1 index 712b6e949d..d864cfb16f 100644 --- a/tests/Copy-DbaDbTableData.Tests.ps1 +++ b/tests/Copy-DbaDbTableData.Tests.ps1 @@ -112,7 +112,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } It "Should warn if the destinaton table doesn't exist" { - $result = Copy-DbaDbTableData -SqlInstance $script:instance1 -Database tempdb -Table dbatoolsci_example -DestinationTable dbatoolsci_doesntexist -WarningVariable tablewarning + $result = Copy-DbaDbTableData -SqlInstance $script:instance1 -Database tempdb -Table dbatoolsci_example -DestinationTable dbatoolsci_doesntexist -WarningVariable tablewarning 3> $null $result | Should -Be $null $tablewarning | Should -Match Auto } @@ -123,7 +123,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } It "Should warn if the source database doesn't exist" { - $result = Copy-DbaDbTableData -SqlInstance $script:instance2 -Database tempdb_invalid -Table dbatoolsci_example -DestinationTable dbatoolsci_doesntexist -WarningVariable tablewarning + $result = Copy-DbaDbTableData -SqlInstance $script:instance2 -Database tempdb_invalid -Table dbatoolsci_example -DestinationTable dbatoolsci_doesntexist -WarningVariable tablewarning 3> $null $result | Should -Be $null $tablewarning | Should -Match "cannot open database" } diff --git a/tests/Copy-DbaDbViewData.Tests.ps1 b/tests/Copy-DbaDbViewData.Tests.ps1 index a5b2b7c559..9e4e641814 100644 --- a/tests/Copy-DbaDbViewData.Tests.ps1 +++ b/tests/Copy-DbaDbViewData.Tests.ps1 @@ -114,13 +114,13 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } It "Should warn and return nothing if Source and Destination are same" { - $result = Copy-DbaDbViewData -SqlInstance $script:instance1 -Database tempdb -View dbatoolsci_view_example -Truncate -WarningVariable tablewarning + $result = Copy-DbaDbViewData -SqlInstance $script:instance1 -Database tempdb -View dbatoolsci_view_example -Truncate -WarningVariable tablewarning 3> $null $result | Should -Be $null $tablewarning | Should -match "Cannot copy dbatoolsci_view_example into itself" } It "Should warn if the destination table doesn't exist" { - $result = Copy-DbaDbViewData -SqlInstance $script:instance1 -Database tempdb -View tempdb.dbo.dbatoolsci_view_example -DestinationTable dbatoolsci_view_does_not_exist -WarningVariable tablewarning + $result = Copy-DbaDbViewData -SqlInstance $script:instance1 -Database tempdb -View tempdb.dbo.dbatoolsci_view_example -DestinationTable dbatoolsci_view_does_not_exist -WarningVariable tablewarning 3> $null $result | Should -Be $null $tablewarning | Should -match Auto } @@ -131,7 +131,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } It "Should warn if the source database doesn't exist" { - $result = Copy-DbaDbViewData -SqlInstance $script:instance2 -Database tempdb_invalid -View dbatoolsci_view_example -DestinationTable dbatoolsci_doesntexist -WarningVariable tablewarning + $result = Copy-DbaDbViewData -SqlInstance $script:instance2 -Database tempdb_invalid -View dbatoolsci_view_example -DestinationTable dbatoolsci_doesntexist -WarningVariable tablewarning 3> $null $result | Should -Be $null $tablewarning | Should -match "Failure" } diff --git a/tests/Copy-DbaInstanceTrigger.Tests.ps1 b/tests/Copy-DbaInstanceTrigger.Tests.ps1 index 56635d1530..91e5839e7f 100644 --- a/tests/Copy-DbaInstanceTrigger.Tests.ps1 +++ b/tests/Copy-DbaInstanceTrigger.Tests.ps1 @@ -35,7 +35,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } } - $results = Copy-DbaInstanceTrigger -Source $script:instance1 -Destination $script:instance2 -WarningVariable warn -WarningAction SilentlyContinue # -ServerTrigger $triggername + $results = Copy-DbaInstanceTrigger -Source $script:instance1 -Destination $script:instance2 -WarningAction SilentlyContinue It "should report success" { $results.Status | Should Be "Successful" diff --git a/tests/Copy-DbaRegServer.Tests.ps1 b/tests/Copy-DbaRegServer.Tests.ps1 index de8c143846..e8df0c654a 100644 --- a/tests/Copy-DbaRegServer.Tests.ps1 +++ b/tests/Copy-DbaRegServer.Tests.ps1 @@ -44,7 +44,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { $groupstore.Drop() } - $results = Copy-DbaRegServer -Source $script:instance2 -Destination $script:instance1 -WarningVariable warn -WarningAction SilentlyContinue -CMSGroup $group + $results = Copy-DbaRegServer -Source $script:instance2 -Destination $script:instance1 -WarningAction SilentlyContinue -CMSGroup $group It "should report success" { $results.Status | Should Be "Successful", "Successful" diff --git a/tests/Disable-DbaDbEncryption.Tests.ps1 b/tests/Disable-DbaDbEncryption.Tests.ps1 index 2224844541..79af457ac8 100644 --- a/tests/Disable-DbaDbEncryption.Tests.ps1 +++ b/tests/Disable-DbaDbEncryption.Tests.ps1 @@ -51,7 +51,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It "should disable encryption on a database with piping" { # Give it time to finish encrypting or it'll error Start-Sleep 10 - $results = $db | Disable-DbaDbEncryption -NoEncryptionKeyDrop -WarningVariable warn + $results = $db | Disable-DbaDbEncryption -NoEncryptionKeyDrop -WarningVariable warn 3> $null $warn | Should -Be $null $results.EncryptionEnabled | Should -Be $false } @@ -59,7 +59,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $null = $db | Enable-DbaDbEncryption -EncryptorName $mastercert.Name -Force # Give it time to finish encrypting or it'll error Start-Sleep 10 - $results = Disable-DbaDbEncryption -SqlInstance $script:instance2 -Database $db.Name -WarningVariable warn + $results = Disable-DbaDbEncryption -SqlInstance $script:instance2 -Database $db.Name -WarningVariable warn 3> $null $warn | Should -Be $null $results.EncryptionEnabled | Should -Be $false } diff --git a/tests/Disable-DbaFilestream.Tests.ps1 b/tests/Disable-DbaFilestream.Tests.ps1 index 478b68b005..826b132f1d 100644 --- a/tests/Disable-DbaFilestream.Tests.ps1 +++ b/tests/Disable-DbaFilestream.Tests.ps1 @@ -24,7 +24,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { Context "Changing FileStream Level" { $NewLevel = ($OriginalFileStream.FileStreamStateId + 1) % 3 #Move it on one, but keep it less than 4 with modulo division - $results = Set-DbaFilestream -SqlInstance $script:instance1 -FileStreamLevel $NewLevel -Force -WarningVariable warnvar -WarningAction silentlyContinue -ErrorVariable errvar -Erroraction silentlyContinue + $results = Set-DbaFilestream -SqlInstance $script:instance1 -FileStreamLevel $NewLevel -Force -WarningAction silentlyContinue -ErrorVariable errvar -Erroraction silentlyContinue It "Should have changed the FileStream Level" { $results.InstanceAccessLevel | Should be $NewLevel } diff --git a/tests/Dismount-DbaDatabase.Tests.ps1 b/tests/Dismount-DbaDatabase.Tests.ps1 index 383c9e9714..8c17a1f281 100644 --- a/tests/Dismount-DbaDatabase.Tests.ps1 +++ b/tests/Dismount-DbaDatabase.Tests.ps1 @@ -84,7 +84,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { } It "Skips detachment if database is snapshotted" { - $result = Dismount-DbaDatabase -SqlInstance $script:instance3 -Database $db2 -Force -WarningAction SilentlyContinue -WarningVariable warn + $result = Dismount-DbaDatabase -SqlInstance $script:instance3 -Database $db2 -Force -WarningAction SilentlyContinue -WarningVariable warn 3> $null $result | Should Be $null $warn -match "snapshot" | Should Be $true $result = Get-DbaDatabase -SqlInstance $script:instance3 -Database $db2 diff --git a/tests/Get-DbaBackupInformation.Tests.ps1 b/tests/Get-DbaBackupInformation.Tests.ps1 index d77c402ed2..6e1ba343d5 100644 --- a/tests/Get-DbaBackupInformation.Tests.ps1 +++ b/tests/Get-DbaBackupInformation.Tests.ps1 @@ -130,9 +130,9 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It "Should be 0 log backups" { ($resultsSanLog | Where-Object {$_.Type -eq 'Transaction Log'}).count | Should be 0 } - $ResultsSanLog = Get-DbaBackupInformation -SqlInstance $script:instance1 -Path $DestBackupDirOla -IgnoreLogBackup -WarningVariable warnvar -WarningAction SilentlyContinue + $ResultsSanLog = Get-DbaBackupInformation -SqlInstance $script:instance1 -Path $DestBackupDirOla -IgnoreLogBackup -WarningVariable warnvar -WarningAction SilentlyContinue 3> $null It "Should Warn if IgnoreLogBackup without MaintenanceSolution" { - ($WarnVar -match "IgnoreLogBackup can only by used with MaintenanceSolution. Will not be used") | Should Be $True + $warnVar | Should -Match "IgnoreLogBackup can only by used with MaintenanceSolution. Will not be used" } It "Should ignore IgnoreLogBackup and return 3 backups" { $resultsSanLog.count | Should Be 3 diff --git a/tests/Get-DbaDbAsymmetricKey.Tests.ps1 b/tests/Get-DbaDbAsymmetricKey.Tests.ps1 index 4c02b78905..fdbca45985 100644 --- a/tests/Get-DbaDbAsymmetricKey.Tests.ps1 +++ b/tests/Get-DbaDbAsymmetricKey.Tests.ps1 @@ -24,7 +24,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $tPassword = ConvertTo-SecureString "ThisIsThePassword1" -AsPlainText -Force New-DbaDbMasterKey -SqlInstance $script:instance2 -Database $database -SecurePassword $tPassword -confirm:$false New-DbaDbUser -SqlInstance $script:instance2 -Database $database -UserName $dbuser - $key = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Database $database -Name $keyname -Owner keyowner -Algorithm $algorithm -WarningVariable warnvar + $null = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Database $database -Name $keyname -Owner keyowner -Algorithm $algorithm -WarningVariable warnvar $results = Get-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database It "Should Create new key in $database called $keyname" { $warnvar | Should -BeNullOrEmpty @@ -42,7 +42,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $pipeResults | Should -HaveCount 1 } - $key2 = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Database $database -Name $keyname2 -Owner keyowner -Algorithm $algorithm -WarningVariable warnvar + $null = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Database $database -Name $keyname2 -Owner keyowner -Algorithm $algorithm -WarningVariable warnvar $multiResults = Get-DbaDatabase -SqlInstance $script:instance2 -Database $database | Get-DbaDbAsymmetricKey It "Should return 2 keys" { $multiResults | Should -HaveCount 2 diff --git a/tests/Get-DbaDbBackupHistory.Tests.ps1 b/tests/Get-DbaDbBackupHistory.Tests.ps1 index 2545a4ec5d..497bcc6e68 100644 --- a/tests/Get-DbaDbBackupHistory.Tests.ps1 +++ b/tests/Get-DbaDbBackupHistory.Tests.ps1 @@ -172,7 +172,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { } It "Invalid type for -Since" { - $results = Get-DbaDbBackupHistory -SqlInstance $script:instance1 -Database $dbname -Since "-" -WarningVariable warning + $results = Get-DbaDbBackupHistory -SqlInstance $script:instance1 -Database $dbname -Since "-" -WarningVariable warning 3> $null $results | Should -BeNullOrEmpty $warning | Should -BeLike "*-Since must be either a DateTime or TimeSpan object*" } diff --git a/tests/Get-DbaDbCompatibility.Tests.ps1 b/tests/Get-DbaDbCompatibility.Tests.ps1 index fc2b37b404..237d02b07b 100644 --- a/tests/Get-DbaDbCompatibility.Tests.ps1 +++ b/tests/Get-DbaDbCompatibility.Tests.ps1 @@ -14,14 +14,18 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { } Describe "$commandname Integration Tests" -Tags "IntegrationTests" { + BeforeAll { + $server = Connect-DbaInstance -SqlInstance $script:instance1 + $compatibilityLevel = $server.Databases['master'].CompatibilityLevel + } Context "Gets compatibility for multiple databases" { $results = Get-DbaDbCompatibility -SqlInstance $script:instance1 It "Gets results" { $results | Should Not Be $null } Foreach ($row in $results) { - It "Should return Compatiblity level of Version100 for $($row.database)" { - $row.Compatibility | Should Be "Version100" + It "Should return correct compatibility level for $($row.database)" { + $row.Compatibility | Should Be $compatibilityLevel $row.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $script:instance1 -Database $row.Database).Id } } @@ -32,8 +36,8 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { It "Gets results" { $results | Should Not Be $null } - It "Should return Compatiblity level of Version100 for $($results.database)" { - $results.Compatibility | Should Be "Version100" + It "Should return correct compatibility level for $($results.database)" { + $results.Compatibility | Should Be $compatibilityLevel $results.DatabaseId | Should -Be (Get-DbaDatabase -SqlInstance $script:instance1 -Database master).Id } } diff --git a/tests/Get-DbaDbDetachedFileInfo.Tests.ps1 b/tests/Get-DbaDbDetachedFileInfo.Tests.ps1 index 04febf3026..a079fc59a7 100644 --- a/tests/Get-DbaDbDetachedFileInfo.Tests.ps1 +++ b/tests/Get-DbaDbDetachedFileInfo.Tests.ps1 @@ -16,6 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { BeforeAll { $server = Connect-DbaInstance -SqlInstance $script:instance2 + $versionName = $server.GetSqlServerVersionName() $random = Get-Random $dbname = "dbatoolsci_detatch_$random" $server.Query("CREATE DATABASE $dbname") @@ -38,8 +39,8 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It "Should be created database" { $results.name | Should Be $dbname } - It "Should be 2016" { - $results.version | Should Be 'SQL Server 2016' + It "Should be the correct version" { + $results.version | Should Be $versionName } It "Should have Data files" { $results.DataFiles | Should Not Be $null diff --git a/tests/Get-DbaDbRestoreHistory.Tests.ps1 b/tests/Get-DbaDbRestoreHistory.Tests.ps1 index c8555399bf..5e845e80a2 100644 --- a/tests/Get-DbaDbRestoreHistory.Tests.ps1 +++ b/tests/Get-DbaDbRestoreHistory.Tests.ps1 @@ -16,10 +16,6 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { BeforeAll { - $DestBackupDir = 'C:\Temp\backups' - if (-Not(Test-Path $DestBackupDir)) { - New-Item -Type Container -Path $DestBackupDir - } $random = Get-Random $dbname1 = "dbatoolsci_restorehistory1_$random" $dbname2 = "dbatoolsci_restorehistory2_$random" diff --git a/tests/Get-DbaDbSharePoint.Tests.ps1 b/tests/Get-DbaDbSharePoint.Tests.ps1 index 6209b6ed2a..f81ae30229 100644 --- a/tests/Get-DbaDbSharePoint.Tests.ps1 +++ b/tests/Get-DbaDbSharePoint.Tests.ps1 @@ -15,21 +15,39 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tag "IntegrationTests" { BeforeAll { + $skip = $false $spdb = 'SharePoint_Admin_7c0c491d0e6f43858f75afa5399d49ab', 'WSS_Logging', 'SecureStoreService_20e1764876504335a6d8dd0b1937f4bf', 'DefaultWebApplicationDB', 'SharePoint_Config_4c524cb90be44c6f906290fe3e34f2e0', 'DefaultPowerPivotServiceApplicationDB-5b638361-c6fc-4ad9-b8ba-d05e63e48ac6', 'SharePoint_Config_4c524cb90be44c6f906290fe3e34f2e0' - Get-DbaProcess -SqlInstance $script:instance3 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue + Get-DbaProcess -SqlInstance $script:instance2 -Program 'dbatools PowerShell module - dbatools.io' | Stop-DbaProcess -WarningAction SilentlyContinue $server = Connect-DbaInstance -SqlInstance $script:instance2 foreach ($db in $spdb) { try { $null = $server.Query("Create Database [$db]") } catch { continue } } + # Andreas Jordan: We should try to get a backup working again or even better just a sql script to set this up. # This takes a long time but I cannot figure out why every backup of this db is malformed $bacpac = "$script:appveyorlabrepo\bacpac\sharepoint_config.bacpac" - $sqlpackage = (Get-Command sqlpackage -ErrorAction Ignore).Source - if (-not $sqlpackage) { - $sqlpackage = Join-DbaPath -Path (Split-Path -Path (Get-Module dbatools*library).Path) -ChildPath lib, sqlpackage, windows, sqlpackage.exe + if (Test-Path -Path $bacpac) { + $sqlpackage = (Get-Command sqlpackage -ErrorAction Ignore).Source + if (-not $sqlpackage) { + $libraryPath = Get-DbatoolsLibraryPath + if ($libraryPath -match 'desktop$') { + $sqlpackage = Join-DbaPath -Path (Get-DbatoolsLibraryPath) -ChildPath lib, sqlpackage.exe + } elseif ($isWindows) { + $sqlpackage = Join-DbaPath -Path (Get-DbatoolsLibraryPath) -ChildPath lib, win, sqlpackage.exe + } else { + # Not implemented + } + } + # On PowerShell 5.1 on Windows Server 2022, the following line throws: + # sqlpackage.exe : *** An unexpected failure occurred: Could not load type 'Microsoft.Data.Tools.Schema.Common.Telemetry.SqlPackageSource' from assembly 'Microsoft.Data.Tools.Utilities, Version=162.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. + # On PowerShell 7.4.2 on Windows Server 2022, the following line throws: + # Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified. + . $sqlpackage /Action:Import /tsn:$script:instance2 /tdn:Sharepoint_Config /sf:$bacpac /p:Storage=File + } else { + Write-Warning -Message "No bacpac found in path [$bacpac], skipping tests." + $skip = $true } - . $sqlpackage /Action:Import /tsn:$script:instance2 /tdn:Sharepoint_Config /sf:$bacpac /p:Storage=File } AfterAll { Remove-DbaDatabase -SqlInstance $script:instance2 -Database $spdb -Confirm:$false @@ -37,7 +55,7 @@ Describe "$commandname Integration Tests" -Tag "IntegrationTests" { Context "Command gets SharePoint Databases" { $results = Get-DbaDbSharePoint -SqlInstance $script:instance2 foreach ($db in $spdb) { - It "returns $db from in the SharePoint database list" { + It -Skip:$skip "returns $db from in the SharePoint database list" { $db | Should -BeIn $results.Name } } diff --git a/tests/Get-DbaDbSpace.Tests.ps1 b/tests/Get-DbaDbSpace.Tests.ps1 index 691b8a0df6..54a7ea280b 100644 --- a/tests/Get-DbaDbSpace.Tests.ps1 +++ b/tests/Get-DbaDbSpace.Tests.ps1 @@ -4,11 +4,11 @@ Write-Host -Object "Running $PSCommandPath" -ForegroundColor Cyan Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Context "Validate parameters" { - [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object {$_ -notin ('whatif', 'confirm')} + [object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object { $_ -notin ('whatif', 'confirm') } [object[]]$knownParameters = 'SqlInstance', 'SqlCredential', 'Database', 'ExcludeDatabase', 'IncludeSystemDBs', '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 + (@(Compare-Object -ReferenceObject ($knownParameters | Where-Object { $_ }) -DifferenceObject $params).Count ) | Should Be 0 } } } @@ -24,38 +24,40 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } #Skipping these tests as internals of Get-DbaDbSpace seems to be unreliable in CI Context "Gets DbSpace" { - $results = Get-DbaDbSpace -SqlInstance $script:instance2 | Where-Object {$_.Database -eq "$dbname"} - It -skip "Gets results" { - $results | Should Not Be $null + $results = Get-DbaDbSpace -SqlInstance $script:instance2 | Where-Object { $_.Database -eq "$dbname" } + It "Gets results" { + $results | Should -Not -BeNullOrEmpty } foreach ($row in $results) { - It -skip "Should retreive space for $dbname" { - $row.Database | Should Be $dbname + It "Should retreive space for $dbname" { + $row.Database | Should -Be $dbname + $row.UsedSpace | Should -Not -BeNullOrEmpty } - It -skip "Should have a physical path for $dbname" { - $row.physicalname | Should Not Be $null + It "Should have a physical path for $dbname" { + $row.physicalname | Should -Not -BeNullOrEmpty } } } #Skipping these tests as internals of Get-DbaDbSpace seems to be unreliable in CI Context "Gets DbSpace when using -Database" { $results = Get-DbaDbSpace -SqlInstance $script:instance2 -Database $dbname - It -skip "Gets results" { + It "Gets results" { $results | Should Not Be $null } Foreach ($row in $results) { - It -skip "Should retreive space for $dbname" { - $row.Database | Should Be $dbname + It "Should retreive space for $dbname" { + $row.Database | Should -Be $dbname + $row.UsedSpace | Should -Not -BeNullOrEmpty } - It -skip "Should have a physical path for $dbname" { - $row.physicalname | Should Not Be $null + It "Should have a physical path for $dbname" { + $row.physicalname | Should -Not -BeNullOrEmpty } } } Context "Gets no DbSpace for specific database when using -ExcludeDatabase" { $results = Get-DbaDbSpace -SqlInstance $script:instance2 -ExcludeDatabase $dbname It "Gets no results" { - $results.database | Should Not Contain $dbname + $results.database | Should -Not -Contain $dbname } } } \ No newline at end of file diff --git a/tests/Get-DbaLinkedServerLogin.Tests.ps1 b/tests/Get-DbaLinkedServerLogin.Tests.ps1 index 57967ad706..772e2e411a 100644 --- a/tests/Get-DbaLinkedServerLogin.Tests.ps1 +++ b/tests/Get-DbaLinkedServerLogin.Tests.ps1 @@ -66,7 +66,7 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "ensure command works" { It "Check the validation for a linked server" { - $results = Get-DbaLinkedServerLogin -SqlInstance $instance2 -LocalLogin $localLogin1Name -WarningVariable warnings + $results = Get-DbaLinkedServerLogin -SqlInstance $instance2 -LocalLogin $localLogin1Name -WarningVariable warnings 3> $null $warnings | Should -BeLike "*LinkedServer is required*" $results | Should -BeNullOrEmpty } diff --git a/tests/Get-DbaPrivilege.Tests.ps1 b/tests/Get-DbaPrivilege.Tests.ps1 index 33cb27aab7..86edc86304 100644 --- a/tests/Get-DbaPrivilege.Tests.ps1 +++ b/tests/Get-DbaPrivilege.Tests.ps1 @@ -16,7 +16,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' { Describe "$commandname Integration Tests" -Tags "IntegrationTests" { Context "Gets Instance Privilege" { - $results = Get-DbaPrivilege -ComputerName $env:ComputerName -WarningVariable warn + $results = Get-DbaPrivilege -ComputerName $env:ComputerName -WarningVariable warn 3> $null It "Gets results" { $results | Should Not Be $null } diff --git a/tests/Get-DbaUserPermission.Tests.ps1 b/tests/Get-DbaUserPermission.Tests.ps1 index fb4ff78b84..d538a993a4 100644 --- a/tests/Get-DbaUserPermission.Tests.ps1 +++ b/tests/Get-DbaUserPermission.Tests.ps1 @@ -53,7 +53,7 @@ exec sp_addrolemember 'userrole','bob'; $null = New-DbaDatabase -SqlInstance $script:instance1 -Name $dbName -Collation $dbCollation - $results = Get-DbaUserPermission -SqlInstance $script:instance1 -Database $dbName -WarningVariable warnvar + $results = Get-DbaUserPermission -SqlInstance $script:instance1 -Database $dbName -WarningVariable warnvar 3> $null It "Should not warn about collation conflict" { $warnvar | Should -Be $null } diff --git a/tests/Move-DbaDbFile.Tests.ps1 b/tests/Move-DbaDbFile.Tests.ps1 index 2f3f6c6153..ecbad4f15c 100644 --- a/tests/Move-DbaDbFile.Tests.ps1 +++ b/tests/Move-DbaDbFile.Tests.ps1 @@ -34,6 +34,9 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" { } AfterAll { $null = Remove-DbaDatabase -SqlInstance $script:instance2 -Database "dbatoolsci_MoveDbFile", "dbatoolsci_MoveDbFile_2DataFiles" -Confirm:$false + Get-Item -Path "$physicalPathFolder\moveFile" | Remove-Item -Recurse + Get-Item -Path "$physicalPathFolder\New" | Remove-Item -Recurse + Get-Item -Path "$physicalPathFolder\dbatoolsci_MoveDbFile.mdf" | Remove-Item } Context "Should output current database structure" { diff --git a/tests/New-DbaDbAsymmetricKey.Tests.ps1 b/tests/New-DbaDbAsymmetricKey.Tests.ps1 index 10fab88e90..6aef3095eb 100644 --- a/tests/New-DbaDbAsymmetricKey.Tests.ps1 +++ b/tests/New-DbaDbAsymmetricKey.Tests.ps1 @@ -36,7 +36,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { Context "Handles pre-existing key" { $keyname = 'test1' - $key = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database master -WarningVariable warnvar + $key = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database master -WarningVariable warnvar 3> $null $null = Remove-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database master -confirm:$false It "Should Warn that they key $keyname already exists" { $Warnvar | Should -BeLike '*already exists in master on*' @@ -98,14 +98,20 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $null = Remove-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database -confirm:$false } - Context "Create new key in $database Loaded from a keyfile" { + Context "Create new key loaded from a keyfile" { + $skip = $false $keyname = 'filekey' $dbuser = 'keyowner' $database = 'enctest' $path = "$($script:appveyorlabrepo)\keytests\keypair.snk" - $key = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Database $database -Name $keyname -Owner keyowner -WarningVariable warnvar -KeySourceType File -KeySource $path - $results = Get-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database - It "Should Create new key in master called $keyname" { + if (Test-Path -Path $path) { + $key = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Database $database -Name $keyname -Owner keyowner -WarningVariable warnvar -KeySourceType File -KeySource $path + $results = Get-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database + } else { + Write-Warning -Message "No keypair found in path [$path], skipping tests." + $skip = $true + } + It -Skip:$skip "Should Create new key in master called $keyname" { $warnvar | Should -BeNullOrEmpty $results.database | Should -Be $database $results.name | Should -Be $keyname @@ -119,7 +125,7 @@ Describe "$CommandName Integration Tests" -Tag "IntegrationTests" { $dbuser = 'keyowner' $database = 'enctest' $path = "$($script:appveyorlabrepo)\keytests\keypair.bad" - $key = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Database $database -Name $keyname -Owner keyowner -WarningVariable warnvar -KeySourceType File -KeySource $path + $key = New-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Database $database -Name $keyname -Owner keyowner -WarningVariable warnvar -KeySourceType File -KeySource $path 3> $null $results = Get-DbaDbAsymmetricKey -SqlInstance $script:instance2 -Name $keyname -Database $database It "Should not Create new key in $database called $keyname" { $warnvar | Should -Not -BeNullOrEmpty diff --git a/tests/New-DbaDbEncryptionKey.Tests.ps1 b/tests/New-DbaDbEncryptionKey.Tests.ps1 index 65e0f6aabd..7ed3aed5af 100644 --- a/tests/New-DbaDbEncryptionKey.Tests.ps1 +++ b/tests/New-DbaDbEncryptionKey.Tests.ps1 @@ -95,10 +95,14 @@ Describe "$CommandName Integration Tests for Async" -Tags "IntegrationTests" { } } + # TODO: I think I need some background on this. Was the intention to create the key or not to creeate the key? + # Currently $warn is: + # [09:49:20][New-DbaDbEncryptionKey] Failed to create encryption key in random-1299050584 on localhost\sql2016 | Cannot decrypt or encrypt using the specified asymmetric key, either because it has no private key or because the password provided for the private key is incorrect. + # Will leave it skipped for now. Context "Command does not work but warns" { # this works on docker, not sure what's up It -Skip "should warn that it cant create an encryption key" { - $null = $db | New-DbaDbEncryptionKey -Force -Type AsymmetricKey -EncryptorName $masterasym.Name -WarningVariable warn + ($null = $db | New-DbaDbEncryptionKey -Force -Type AsymmetricKey -EncryptorName $masterasym.Name -WarningVariable warn) *> $null $warn | Should -Match "n order to encrypt the database encryption key with an as" } } diff --git a/tests/New-DbaDbMailAccount.Tests.ps1 b/tests/New-DbaDbMailAccount.Tests.ps1 index 9710fc9e7e..5645633922 100644 --- a/tests/New-DbaDbMailAccount.Tests.ps1 +++ b/tests/New-DbaDbMailAccount.Tests.ps1 @@ -42,6 +42,8 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { EmailAddress = $email_address DisplayName = $display_name ReplyToAddress = $replyto_address + # MailServer is not set, because we don't want to configure the mail server on the instance. + # MailServer = $mailserver_name } $results = New-DbaDbMailAccount @splat @@ -54,12 +56,14 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It "Should have Description of 'Mail account for email alerts' " { $results.Description | Should Be 'Mail account for email alerts' } - It "Should have EmailAddress of 'dbatoolssci@dbatools.net' " { - $results.EmailAddress | Should Be 'dbatoolssci@dbatools.net' + # TODO: If we set the variables then we should use them, don't we? + It "Should have EmailAddress of '$email_address' " { + $results.EmailAddress | Should Be $email_address } It "Should have ReplyToAddress of 'no-reply@dbatools.net' " { $results.ReplyToAddress | Should Be 'no-reply@dbatools.net' } + # Skipped, because we have not set the MailServer, because we don't want to configure the mail server on the instance. It -Skip "Should have MailServer of '[smtp.dbatools.io]' " { $results.MailServers | Should Be '[smtp.dbatools.io]' } @@ -81,6 +85,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { It "Should have ReplyToAddress of 'no-reply@dbatools.net' " { $results.ReplyToAddress | Should Be 'no-reply@dbatools.net' } + # Skipped, because we have not set the MailServer, because we don't want to configure the mail server on the instance. It -Skip "Should have MailServer of '[smtp.dbatools.io]' " { $results.MailServers | Should Be '[smtp.dbatools.io]' } diff --git a/tests/Remove-DbaDbUser.Tests.ps1 b/tests/Remove-DbaDbUser.Tests.ps1 index 687c812cd6..b1ca3d55d6 100644 --- a/tests/Remove-DbaDbUser.Tests.ps1 +++ b/tests/Remove-DbaDbUser.Tests.ps1 @@ -19,7 +19,7 @@ Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { $server = Connect-DbaInstance -SqlInstance $script:instance1 $db = Get-DbaDatabase $server -Database tempdb $securePassword = ConvertTo-SecureString "password" -AsPlainText -Force - $loginTest = New-DbaLogin $server -Login dbatoolsci_remove_dba_db_user -Password $securePassword + $loginTest = New-DbaLogin $server -Login dbatoolsci_remove_dba_db_user -Password $securePassword -Force } BeforeEach { $user = New-Object Microsoft.SqlServer.Management.SMO.User($db, $loginTest.Name) diff --git a/tests/Test-DbaDbLogShipStatus.Tests.ps1 b/tests/Test-DbaDbLogShipStatus.Tests.ps1 index e65a6ea329..759be691e6 100644 --- a/tests/Test-DbaDbLogShipStatus.Tests.ps1 +++ b/tests/Test-DbaDbLogShipStatus.Tests.ps1 @@ -14,7 +14,15 @@ Describe "$CommandName Unit Tests" -Tags "UnitTests" { } Describe "$CommandName Integration Tests" -Tags "IntegrationTests" { - It "warns if SQL instance edition is not supported" { + BeforeAll { + $server = Connect-DbaInstance -SqlInstance $script:instance1 + $skip = $false + if ($server.Edition -notmatch 'Express') { + $skip = $true + } + } + + It -Skip:$skip "warns if SQL instance edition is not supported" { $null = Test-DbaDbLogShipStatus -SqlInstance $script:instance1 -WarningAction SilentlyContinue -WarningVariable editionwarn $editionwarn -match "Express" | Should Be $true }