diff --git a/tests/Connect-DbaInstance.Tests.ps1 b/tests/Connect-DbaInstance.Tests.ps1 index e033ee52d8c..0e72fee1cac 100644 --- a/tests/Connect-DbaInstance.Tests.ps1 +++ b/tests/Connect-DbaInstance.Tests.ps1 @@ -526,12 +526,17 @@ Describe $CommandName -Tag IntegrationTests { It "clones when using Backup-DabInstace" { $server = Connect-DbaInstance -SqlInstance $TestConfig.InstanceMulti1 -Database tempdb - $results = Backup-DbaDatabase -SqlInstance $server -Database msdb + # The backups have to go to the shared temp folder. Without a path they land in the default + # backup folder of the instance, which is a path on the SQL Server, so the Remove-Item below + # runs against a path that does not exist on the machine running the tests and silently does + # nothing. The backup was then left behind on every remote instance, and because this file + # runs early in the suite, every later test file reported it as a leftover of its own. + $results = Backup-DbaDatabase -SqlInstance $server -Database msdb -Path $TestConfig.Temp if ($results.FullName) { Remove-Item -Path $results.FullName -ErrorAction SilentlyContinue } - $results = Backup-DbaDatabase -SqlInstance $server -Database msdb -WarningVariable warn + $results = Backup-DbaDatabase -SqlInstance $server -Database msdb -Path $TestConfig.Temp -WarningVariable warn $warn | Should -BeNullOrEmpty if ($results.FullName) { diff --git a/tests/Copy-DbaDatabase.Tests.ps1 b/tests/Copy-DbaDatabase.Tests.ps1 index 0dc9a6fa1a4..70a7b7012ba 100644 --- a/tests/Copy-DbaDatabase.Tests.ps1 +++ b/tests/Copy-DbaDatabase.Tests.ps1 @@ -55,8 +55,9 @@ Describe $CommandName -Tag IntegrationTests { # For all the backups that we want to clean up after the test, we create a directory that we can delete at the end. # Other files can be written there as well, maybe we change the name of that variable later. But for now we focus on backups. - $NetworkPath = $TestConfig.Temp $random = Get-Random + $NetworkPath = Join-Path -Path $TestConfig.Temp -ChildPath "dbatoolsci_copydatabase$random" + $null = New-Item -Path $NetworkPath -ItemType Directory -Force $backuprestoredb = "dbatoolsci_backuprestore$random" $backuprestoredb2 = "dbatoolsci_backuprestoreother$random" $detachattachdb = "dbatoolsci_detachattach$random" @@ -106,6 +107,10 @@ Describe $CommandName -Tag IntegrationTests { } Remove-DbaDatabase @splatRemoveSupport -ErrorAction SilentlyContinue + # The backups taken during the tests stay behind otherwise, and every test file that runs + # afterwards then reports them as leftovers of its own. + Remove-Item -Path $NetworkPath -Recurse -Force -ErrorAction SilentlyContinue + $PSDefaultParameterValues.Remove("*-Dba*:EnableException") } diff --git a/tests/Invoke-DbaDbMirroring.Tests.ps1 b/tests/Invoke-DbaDbMirroring.Tests.ps1 index 56069471bfd..b2ffe700553 100644 --- a/tests/Invoke-DbaDbMirroring.Tests.ps1 +++ b/tests/Invoke-DbaDbMirroring.Tests.ps1 @@ -58,6 +58,10 @@ Describe $CommandName -Tag IntegrationTests { $null = Remove-DbaDatabase -SqlInstance $TestConfig.InstanceCopy1, $TestConfig.InstanceCopy2 -Database $dbName $null = Remove-DbaEndpoint -SqlInstance $TestConfig.InstanceCopy1, $TestConfig.InstanceCopy2 -EndPoint $endpointName + # Seeding the mirror leaves the full backup and the log backup in the shared folder, and every + # test file that runs afterwards then reports them as leftovers of its own. + Get-ChildItem -Path $TestConfig.Temp -Filter "$dbName*" | Remove-Item -Force -ErrorAction SilentlyContinue + $PSDefaultParameterValues.Remove("*-Dba*:EnableException") }