Skip to content

Commit 04d24ca

Browse files
Some test improvements and fixes (#10356)
1 parent 3ed951f commit 04d24ca

23 files changed

Lines changed: 98 additions & 86 deletions

tests/Add-DbaComputerCertificate.Tests.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Describe $CommandName -Tag UnitTests {
6868
SecurePassword = $pfxPassword
6969
Flag = @("UserProtected", "NonExportable")
7070
Confirm = $false
71+
WarningAction = "SilentlyContinue"
7172
ErrorAction = "SilentlyContinue"
7273
}
7374
$null = Add-DbaComputerCertificate @splatAddCertificate

tests/Add-DbaInstanceList.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Describe $CommandName -Tag IntegrationTests {
2626
}
2727

2828
AfterAll {
29-
$null = Remove-DbaInstanceList -SqlInstance $instanceName -Confirm:$false -ErrorAction SilentlyContinue
29+
$null = Remove-DbaInstanceList -SqlInstance $instanceName -ErrorAction SilentlyContinue
3030
}
3131

3232
Context "adds instances to the list" {

tests/Add-DbaServerRoleMember.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Describe $CommandName -Tag IntegrationTests {
5757
Login = $login1, $login2
5858
}
5959
$null = Remove-DbaLogin @splatRemoveLogin
60-
$null = Remove-DbaServerRole -SqlInstance $TestConfig.InstanceSingle -ServerRole $customServerRole -Confirm:$false
60+
$null = Remove-DbaServerRole -SqlInstance $TestConfig.InstanceSingle -ServerRole $customServerRole
6161

6262
$PSDefaultParameterValues.Remove("*-Dba*:EnableException")
6363
}
@@ -105,7 +105,7 @@ Describe $CommandName -Tag IntegrationTests {
105105

106106
It "Adds Login to Roles via piped input from Get-DbaServerRole" {
107107
$serverRole = Get-DbaServerRole -SqlInstance $server -ServerRole $fixedServerRoles[0]
108-
$serverRole | Add-DbaServerRoleMember -Login $login2 -Confirm:$false
108+
$serverRole | Add-DbaServerRoleMember -Login $login2
109109

110110
$roleAfter = Get-DbaServerRole -SqlInstance $server -ServerRole $fixedServerRoles[0]
111111
$roleAfter.EnumMemberNames() | Should -Contain $login2

tests/CLAUDE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ Describe $CommandName -Tag IntegrationTests {
100100
$PSDefaultParameterValues["*-Dba*:EnableException"] = $true
101101
102102
# Cleanup all created objects.
103-
$null = Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $testDbName -Confirm:$false -ErrorAction SilentlyContinue
103+
$null = Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $testDbName -ErrorAction SilentlyContinue
104104
105105
# Remove the backup directory.
106106
Remove-Item -Path $backupPath -Recurse -ErrorAction SilentlyContinue
@@ -354,7 +354,7 @@ Describe $CommandName -Tag IntegrationTests {
354354
# Clean up all resources with error suppression
355355
Remove-Item -Path $backupPath -Recurse -ErrorAction SilentlyContinue
356356
Remove-Item -Path $filesToRemove -ErrorAction SilentlyContinue
357-
Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $databasesToCleanup -Confirm:$false -ErrorAction SilentlyContinue
357+
Remove-DbaDatabase -SqlInstance $TestConfig.instance2 -Database $databasesToCleanup -ErrorAction SilentlyContinue
358358
}
359359
360360
# Test code here

tests/Compare-DbaDbSchema.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ Describe $CommandName -Tag IntegrationTests {
257257
# We want to run all commands in the AfterAll block with EnableException to ensure that the test fails if the cleanup fails.
258258
$PSDefaultParameterValues["*-Dba*:EnableException"] = $true
259259

260-
$null = Remove-DbaDatabase -SqlInstance $TestConfig.InstanceSingle -Database $dbSourceName, $dbTargetName -Confirm:$false
260+
$null = Remove-DbaDatabase -SqlInstance $TestConfig.InstanceSingle -Database $dbSourceName, $dbTargetName
261261

262262
Remove-Item -Path $testFolder -Recurse -ErrorAction SilentlyContinue
263263

tests/Copy-DbaAgentJobStep.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ Describe $CommandName -Tag IntegrationTests {
6969
$PSDefaultParameterValues["*-Dba*:EnableException"] = $true
7070

7171
# Cleanup all created jobs
72-
$null = Remove-DbaAgentJob -SqlInstance $TestConfig.InstanceCopy1 -Job $sourceJobName, $pipelineJobName -Confirm:$false -ErrorAction SilentlyContinue
73-
$null = Remove-DbaAgentJob -SqlInstance $TestConfig.InstanceCopy2 -Job $sourceJobName, $pipelineJobName -Confirm:$false -ErrorAction SilentlyContinue
72+
$null = Remove-DbaAgentJob -SqlInstance $TestConfig.InstanceCopy1 -Job $sourceJobName, $pipelineJobName -ErrorAction SilentlyContinue
73+
$null = Remove-DbaAgentJob -SqlInstance $TestConfig.InstanceCopy2 -Job $sourceJobName, $pipelineJobName -ErrorAction SilentlyContinue
7474
}
7575

7676
Context "Command synchronizes job steps properly" {

tests/Get-DbaExternalProcess.Tests.ps1

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ Describe $CommandName -Tag IntegrationTests {
2525
# We want to run all commands in the BeforeAll block with EnableException to ensure that the test fails if the setup fails.
2626
$PSDefaultParameterValues["*-Dba*:EnableException"] = $true
2727

28-
$computerName = Resolve-DbaComputerName -ComputerName $TestConfig.InstanceSingle -Property ComputerName
28+
$computerName = Resolve-DbaComputerName -ComputerName $TestConfig.InstanceRestart -Property ComputerName
2929

3030
# Setup xp_cmdshell to create external processes for testing
31-
$null = Invoke-DbaQuery -SqlInstance $TestConfig.InstanceSingle -Query "
31+
$null = Invoke-DbaQuery -SqlInstance $TestConfig.InstanceRestart -Query "
3232
-- To allow advanced options to be changed.
3333
EXECUTE sp_configure 'show advanced options', 1;
3434
GO
@@ -47,7 +47,7 @@ Describe $CommandName -Tag IntegrationTests {
4747
Set-Content -Path $sqlFile -Value "xp_cmdshell 'powershell -command ""sleep 5""'"
4848

4949
# Run sql file to start external process
50-
Start-Process -FilePath sqlcmd -ArgumentList "-S $($TestConfig.InstanceSingle) -i $sqlFile" -NoNewWindow -RedirectStandardOutput null
50+
Start-Process -FilePath sqlcmd -ArgumentList "-S $($TestConfig.InstanceRestart) -i $sqlFile" -NoNewWindow -RedirectStandardOutput null
5151

5252
# We want to run all commands outside of the BeforeAll block without EnableException to be able to test for specific warnings.
5353
$PSDefaultParameterValues.Remove("*-Dba*:EnableException")
@@ -58,7 +58,7 @@ Describe $CommandName -Tag IntegrationTests {
5858
$PSDefaultParameterValues["*-Dba*:EnableException"] = $true
5959

6060
# Cleanup: Disable xp_cmdshell for security
61-
$null = Invoke-DbaQuery -SqlInstance $TestConfig.InstanceSingle -Query "
61+
$null = Invoke-DbaQuery -SqlInstance $TestConfig.InstanceRestart -Query "
6262
EXECUTE sp_configure 'xp_cmdshell', 0;
6363
GO
6464
RECONFIGURE;
@@ -68,17 +68,20 @@ Describe $CommandName -Tag IntegrationTests {
6868
RECONFIGURE;
6969
GO"
7070

71-
# remove sql file
71+
# Restart the SQL Service to ensure we can remove the temporary file.
72+
$null = Restart-DbaService -ComputerName $TestConfig.InstanceRestart -Type Engine -Force
7273
Remove-Item -Path $sqlFile
7374

7475
$PSDefaultParameterValues.Remove("*-Dba*:EnableException")
7576
}
7677

7778
Context "Can get an external process" {
7879
It "returns a process" {
79-
Start-Sleep -Seconds 1
80-
$results = Get-DbaExternalProcess -ComputerName $computerName | Where-Object Name -eq "cmd.exe"
81-
Start-Sleep -Seconds 5
80+
1..10 | ForEach-Object {
81+
$results = Get-DbaExternalProcess -ComputerName $computerName
82+
if ($results) { break }
83+
Start-Sleep -Milliseconds 500
84+
}
8285
$results.ComputerName | Should -Be $computerName
8386
$results.Name | Should -Be "cmd.exe"
8487
$results.ProcessId | Should -Not -Be $null

tests/Get-DbaInstanceList.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Describe $CommandName -Tag IntegrationTests {
2222
}
2323

2424
AfterAll {
25-
$null = Remove-DbaInstanceList -SqlInstance $instanceName -Confirm:$false -ErrorAction SilentlyContinue
25+
$null = Remove-DbaInstanceList -SqlInstance $instanceName -ErrorAction SilentlyContinue
2626
}
2727

2828
Context "returns the instance list" {

0 commit comments

Comments
 (0)