FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Tests for New-WinEvent by anmenaga · Pull Request #4384 · PowerShell/PowerShell · GitHub

Tests for New-WinEvent - #4384

Merged
Aditya Patwardhan (adityapatwardhan) merged 6 commits into
PowerShell:masterfrom
anmenaga:NewWinEventTests
Aug 7, 2017
Merged

Tests for New-WinEvent#4384
Aditya Patwardhan (adityapatwardhan) merged 6 commits into
PowerShell:masterfrom
anmenaga:NewWinEventTests

Conversation

Copy link
Copy Markdown

Some tests for New-WinEvent that bring code coverage of the class to 80%.


Context "New-WinEvent tests" {

It 'Simple New-WinEvent' -Skip:(-not $IsWindows) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

You may want to use $PSDefaultParameterValues to set the value of skip.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Should be,

(Get-WinEvent -filterHashtable $filter).Count | Should BeGreaterThan 0

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Updated.

}

It 'No provider found error' -Skip:(-not $IsWindows) {
{ New-WinEvent -ProviderName NonExistingProvider -Id 0 } | ShouldBeErrorID 'System.ArgumentException,Microsoft.PowerShell.Commands.NewWinEventCommand'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Typo. Please change "ShouldBeErrorID" -> "ShouldBeErrorId".

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Please move the comment on separate line.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Moved.

}

It 'Simple New-WinEvent' {
New-WinEvent -ProviderName Microsoft-Windows-PowerShell -Id 40962 -Version 1 # simple event without any payload

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Move the comment to a separate line.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

updated.

Steve Lee (SteveL-MSFT) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

use something like

$PSProviderId = 40962

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Updated.

Copy link
Copy Markdown
Author

This goes toward #4156

Copy link
Copy Markdown
Member

Based on the code coverage, you're missing some tests:
https://codecov.io/gh/PowerShell/PowerShell/src/9e41c647a9407e05d86f4971a6bd25719a7130d0/src/Microsoft.PowerShell.CoreCLR.Eventing/DotNetCode/Eventing/EventDescriptor.cs

The Reader code should probably be a different PR

Copy link
Copy Markdown
Author

Steve Lee (@SteveL-MSFT) All of the things that you've mentioned is ETW code and will go into separate PR.
This PR is specific to New-WinEvent cmdlet code.

Copy link
Copy Markdown
Member

Ilya (@iSazonov) Can you have a look again?

}

It 'Simple New-WinEvent' {
# simple event without any payload

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I believe we can remove the comment. And maybe move to the test name.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Andrew (@anmenaga) can you address this?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Updated.

Copy link
Copy Markdown
Collaborator

With one minor comment LGTM.

Aditya Patwardhan (adityapatwardhan) merged commit 0b7451b into PowerShell:master Aug 7, 2017
Andrew (anmenaga) deleted the NewWinEventTests branch October 31, 2018 21:19
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj/PowerShell that referenced this pull request Aug 6, 2026
* New-WinEvent tests

* PR feedback

* PR feedback 2

* PR feedback 3

* PR feedback 4

* PR feedback 5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

5 participants


Back | FazBrowse Home | New Git URL