Skip to content

Commit 5b3bb00

Browse files
committed
Enhance Remove-SqlDscLogin tests to ensure login existence for WhatIf scenario and handle non-existent login case
1 parent c4c328c commit 5b3bb00

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

tests/Integration/Commands/Remove-SqlDscLogin.Integration.Tests.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ Describe 'Remove-SqlDscLogin' -Tag @('Integration_SQL2016', 'Integration_SQL2017
7474
}
7575

7676
It 'Should handle WhatIf parameter correctly' {
77+
# Ensure the login exists for this scenario (don't rely on other Its)
78+
$null = $script:serverObject | New-SqlDscLogin -Name $script:testLoginName -SqlLogin -SecurePassword $script:testLoginPassword -Force
79+
7780
# Use WhatIf - login should not be removed
7881
$script:serverObject | Remove-SqlDscLogin -Name $script:testLoginName -WhatIf
7982

@@ -83,6 +86,12 @@ Describe 'Remove-SqlDscLogin' -Tag @('Integration_SQL2016', 'Integration_SQL2017
8386
}
8487

8588
It 'Should throw an error when the login does not exist' {
89+
# Ensure the login does not exist for this scenario (don't rely on other Its)
90+
if (Test-SqlDscIsLogin -ServerObject $script:serverObject -Name $script:testLoginName)
91+
{
92+
$script:serverObject | Remove-SqlDscLogin -Name $script:testLoginName -Force
93+
}
94+
8695
# Try to remove a non-existent login
8796
{
8897
$script:serverObject | Remove-SqlDscLogin -Name $script:testLoginName -Force -ErrorAction 'Stop'

0 commit comments

Comments
 (0)