-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Tests for New-WinEvent #4384
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
Tests for New-WinEvent #4384
Conversation
|
|
||
| Context "New-WinEvent tests" { | ||
|
|
||
| It 'Simple New-WinEvent' -Skip:(-not $IsWindows) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may want to use $PSDefaultParameterValues to set the value of skip.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, I saw that approach; but don't really like it; I think having skip conditions explicitly on each test makes it easier to investigate test failures.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The recommendation according to the testing guidelines is to use PSDefaultParameterValues. Please see: https://github.com/PowerShell/PowerShell/blob/master/docs/testing-guidelines/WritingPesterTests.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
| It 'Simple New-WinEvent' -Skip:(-not $IsWindows) { | ||
| New-WinEvent -ProviderName Microsoft-Windows-PowerShell -Id 40962 -Version 1 # simple event without any payload | ||
| $filter = @{ ProviderName = 'Microsoft-Windows-PowerShell'; Id = 40962} | ||
| (Get-WinEvent -filterHashtable $filter).Count -gt 0 | Should be $true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be,
(Get-WinEvent -filterHashtable $filter).Count | Should BeGreaterThan 0There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
| } | ||
|
|
||
| It 'No provider found error' -Skip:(-not $IsWindows) { | ||
| { New-WinEvent -ProviderName NonExistingProvider -Id 0 } | ShouldBeErrorID 'System.ArgumentException,Microsoft.PowerShell.Commands.NewWinEventCommand' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo. Please change "ShouldBeErrorID" -> "ShouldBeErrorId".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
|
|
||
| It 'PayloadMismatch error' -Skip:(-not $IsWindows) { | ||
| $logPath = join-path $TestDrive 'testlog1.txt' | ||
| New-WinEvent -ProviderName Microsoft-Windows-PowerShell -Id 32868 *> $logPath # this will print the warning with expected event template to the file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move the comment on separate line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved.
| } | ||
|
|
||
| It 'Simple New-WinEvent' { | ||
| New-WinEvent -ProviderName Microsoft-Windows-PowerShell -Id 40962 -Version 1 # simple event without any payload |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the comment to a separate line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated.
SteveL-MSFT
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which issue does this address if any?
| } | ||
|
|
||
| It 'Simple New-WinEvent' { | ||
| New-WinEvent -ProviderName Microsoft-Windows-PowerShell -Id 40962 -Version 1 # simple event without any payload |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use something like
$PSProviderId = 40962There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
|
This goes toward #4156 |
|
Based on the code coverage, you're missing some tests:
The Reader code should probably be a different PR |
|
@SteveL-MSFT All of the things that you've mentioned is ETW code and will go into separate PR. |
|
@iSazonov Can you have a look again? |
| } | ||
|
|
||
| It 'Simple New-WinEvent' { | ||
| # simple event without any payload |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we can remove the comment. And maybe move to the test name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anmenaga can you address this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
|
With one minor comment LGTM. |
Some tests for New-WinEvent that bring code coverage of the class to 80%.