Skip to content

Conversation

@KevinMarquette
Copy link
Contributor

PR Summary

Use new Pester syntax: -Parameter for Pester in Modules/Microsoft.PowerShell.LocalAccounts
Resolves part of #6245

PR Checklist

}
catch {
$_.FullyQualifiedErrorId | Should Be $expectedFqeid
{& $sb} | Should -Throw -ErrorId $expectedFqeid
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'm not sure if this is the best way to refactor this with the use of try/finally here to toggle ErrorActionPreference. There is a hand full of instances of this pattern in this file

Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe we could do:

{
    $script:ErrorActionPreference = "Stop" 
    try {
        & $sb
    } finally {
         $script:ErrorActionPreference = $backupEAP 
    }
} Should -Throw -ErrorId $expectedFqeid 

{
# Force failing the test because an unexpected outcome occurred
$false | Should Be $true
$false | Should -BeTrue
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can I remove the if/else and just $result | Should -Not -BeNullOrEmpty instead

Copy link
Collaborator

Choose a reason for hiding this comment

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

No.


$finalCount = (Get-LocalGroup).Count
$initialCount -eq $finalCount + 1 | Should Be true
$initialCount | Should -Be ($finalCount + 1)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this an appropriate refactor to add to this pull request?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes.

@KevinMarquette
Copy link
Contributor Author

@iSazonov I have a few questions on this PR that I called out in the code before someone does a full review.

Overal, there was a lot of left side logic that was piping to | Should be true. Lots of counts, matches and contains that all have Pester support now, so I did those refactor this time.

$result[2] -match "TestGroupGet1" | Should Be true
$result[0] | Should -Be 1
$result[1] | Should -Match "GroupNotFound"
$result[2] | Should -match "TestGroupGet1"
Copy link
Collaborator

@iSazonov iSazonov Mar 26, 2018

Choose a reason for hiding this comment

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

-match -> -MatchExactly

}
catch {
$_.FullyQualifiedErrorId | Should Be $expectedFqeid
{& $sb} | Should -Throw -ErrorId $expectedFqeid
Copy link
Collaborator

Choose a reason for hiding this comment

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

The same pattern as above.

$result[0].Name -match ($OptDomainPrefix + "TestUser1") | Should Be $true
$result[1].Name -match ($OptDomainPrefix + "TestUser2") | Should Be $true
$result[0].Name | Should -Match ($OptDomainPrefix + "TestUser1")
$result[1].Name | Should -Match ($OptDomainPrefix + "TestUser2")
Copy link
Collaborator

@iSazonov iSazonov Mar 26, 2018

Choose a reason for hiding this comment

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

-MatchExactly for strings for all commits.

}
catch {
$_.FullyQualifiedErrorId | Should Be $expectedFqeid
{& $sb} | Should -Throw -ErrorId $expectedFqeid
Copy link
Collaborator

Choose a reason for hiding this comment

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

The same pattern as above

@daxian-dbw
Copy link
Member

@adityapatwardhan Do we even run LocalAccount tests? I think we disabled building the assembly, and thus we shouldn't be running the tests anymore ...

@adityapatwardhan
Copy link
Member

@daxian-dbw Yes, you are correct, we do not run these tests anymore.

@KevinMarquette KevinMarquette changed the title WIP: Use new Pester syntax: -Parameter for Modules/Microsoft.PowerShell.LocalAccounts tests Use new Pester syntax: -Parameter for Modules/Microsoft.PowerShell.LocalAccounts tests Mar 27, 2018
@SteveL-MSFT
Copy link
Member

@KevinMarquette I appreciate you taking the time to clean up these tests, however, to validate the changes are correct, you'll need to run them on Windows PowerShell 5.1 where the LocalAccounts module still exists. These tests all have a return statement early in the script so none of the tests actually run.

@KevinMarquette
Copy link
Contributor Author

I was relying on the CI triggers for the build. I didn't even notice the return statement.

@KevinMarquette KevinMarquette changed the title Use new Pester syntax: -Parameter for Modules/Microsoft.PowerShell.LocalAccounts tests WIP: Use new Pester syntax: -Parameter for Modules/Microsoft.PowerShell.LocalAccounts tests Mar 27, 2018
@stale
Copy link

stale bot commented Apr 26, 2018

This PR has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed if no further activity occurs within 10 days.
Thank you for your contributions.
Community members are welcome to grab these works.

@stale stale bot added the Stale label Apr 26, 2018
@iSazonov
Copy link
Collaborator

Up.

@stale stale bot removed the Stale label Apr 26, 2018
}
catch {
$_.FullyQualifiedErrorId | Should Be "ParameterArgumentValidationError,Microsoft.PowerShell.Commands.NewLocalGroupCommand"
{$shouldBeNull = New-LocalGroup -Name $name -Description $desc} |
Copy link
Member

Choose a reason for hiding this comment

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

NIT: whitespace after opening brace and before closing brace

@stale
Copy link

stale bot commented May 26, 2018

This PR has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed if no further activity occurs within 10 days.
Thank you for your contributions.
Community members are welcome to grab these works.

@stale stale bot added the Stale label May 26, 2018
@stale
Copy link

stale bot commented Jun 5, 2018

This PR has be automatically close because it is stale. If you wish to continue working on the PR, please first update the PR, then reopen it.
Thanks again for your contribution.
Community members are welcome to grab these works.

@stale stale bot closed this Jun 5, 2018
@xtqqczze xtqqczze mentioned this pull request Jan 10, 2020
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants