Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove-DbaLinkedServer: Add option to drop logins along with the linked server #7952

Merged
merged 2 commits into from Nov 18, 2021
Merged

Remove-DbaLinkedServer: Add option to drop logins along with the linked server #7952

merged 2 commits into from Nov 18, 2021

Conversation

lancasteradam
Copy link
Contributor

Type of Change

  • Bug fix (non-breaking change, fixes # )
  • New feature (non-breaking change, adds functionality, fixes Remove-DbaLinkedServer: Add option to drop logins along with the linked server #7951 )
  • Breaking change (effects multiple commands or functionality, fixes # )
  • Ran manual Pester test and has passed (.\tests\manual.pester.ps1)
  • Adding code coverage to existing functionality
  • Pester test is included
  • If new file reference added for test, has is been added to github.com/sqlcollaborative/appveyor-lab ?
  • [] Unit test is included
  • Documentation
  • Build system

Purpose

Add a -Force param so that the logins for a linked server can be dropped at the same time as the linked server.

Approach

Minor change to use a new param.

Commands to test

See the new pester test.

$lsToDrop.Drop($true)
} else {
$lsToDrop.Drop()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you not just do this as $lsToDrop.Drop([boolean]$Force)? The method can accept a boolean value so if the user does not provide -Force that should equate to doing Drop($false).

Though I do not have an lab to test this on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good, updated the code

$linkedServerName1 = "LS1_$random"
$linkedServerName2 = "LS2_$random"
$linkedServerName3 = "LS3_$random"
$linkedServerName4 = "LS4_$random"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use dbatoolscli as a prefix for these objects. Majority of our test should be using this when we create objects on the instance incase a user wants to run our tests in their own environment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated this as well

$warn | Should -BeNullOrEmpty
$results = Get-DbaLinkedServer -SqlInstance $instance2 -LinkedServer "LS2_$random"
$results = Get-DbaLinkedServer -SqlInstance $instance2 -LinkedServer $linkedServerName2
$results | Should -BeNullOrEmpty
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a bit excessive to make so many calls in one It block. Is there anything wrong with just having it test the below line. Not sure why we need to perform this test twice either (piping the command or the object via a variable is the same thing).

Get-DbaLinkedServer -SqlInstance $instance2 -LinkedServer $linkedServerName2 | Remove-DbaLinkedServer -WarningVariable warn -Confirm:$false

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal is to test both of the input object types. I split this into two separate tests.


It "Removes a linked server that requires the -Force param" {
Get-DbaLinkedServer -SqlInstance $instance2 -LinkedServer $linkedServerName4 | Remove-DbaLinkedServer -Confirm:$false -WarningVariable warnings
$warnings | Should -BeLike "*There are still remote logins or linked logins for the server*"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed, or put it a unique it block for testing the warning message. If this fails it will appear in the results that the use of -Force is broken.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this into its own test.

@potatoqualitee
Copy link
Member

pawesome! 🐾 thank you both so much

@potatoqualitee potatoqualitee merged commit d2ec2d1 into dataplat:development Nov 18, 2021
@garyhampson
Copy link

Thanks @lancasteradam!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove-DbaLinkedServer: Add option to drop logins along with the linked server
4 participants