-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Adding tests for PSDiagnostics Module #8431
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5437345
Adding testes for PSDiagnostics Module as per #8367
kvprasoon 981e929
Added missing Skip switch for a test
kvprasoon 7b435eb
Check if Windows in BeforeEah block.
kvprasoon fe68ac4
changes as per review comments
kvprasoon f67007b
Bool convertion changes as per review comment.
kvprasoon 8013fa8
Changes as per review comments for skipping test cases
kvprasoon 770cb94
removing -Name parameter usages
kvprasoon 331112d
Changes as per review comments
kvprasoon d24d4a3
Adding periods.
kvprasoon 90d8702
Adding check for resetting log settings
kvprasoon 5c9d194
Merge branch 'master' into psd-tests
kvprasoon d511d0e
Review comment fixes
kvprasoon 3f61287
remove hardcode
kvprasoon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
test/powershell/Modules/PSDiagnostics/PSDiagnostics.Tests.ps1
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| Describe "PSDiagnostics cmdlets tests." -Tag "CI", "RequireAdminOnWindows" { | ||
| BeforeAll { | ||
| $LogType = 'Analytic' | ||
| $OriginalDefaultParameterValues = $PSDefaultParameterValues.Clone() | ||
| if (-not $IsWindows) { | ||
| $PSDefaultParameterValues["it:skip"] = $true | ||
| } | ||
| else{ | ||
| $LogSettingBak = Get-LogProperties -Name Microsoft-Windows-PowerShell/$LogType | ||
| } | ||
| } | ||
| AfterAll { | ||
| if ($IsWindows) { | ||
| Set-LogProperties -LogDetails $LogSettingBak -Force | ||
| } | ||
| $Global:PSDefaultParameterValues = $OriginalDefaultParameterValues | ||
| } | ||
|
|
||
| Context "Test for Enable-PSTrace and Disable-PSTrace cmdlets." { | ||
| it "Should enable $LogType logs for Microsoft-Windows-PowerShell." { | ||
| [XML]$CurrentSetting = & wevtutil gl Microsoft-Windows-PowerShell/$LogType /f:xml | ||
| if($CurrentSetting.Channel.Enabled -eq 'true'){ | ||
| & wevtutil sl Microsoft-Windows-PowerShell/$LogType /e:false /q | ||
| } | ||
|
|
||
| Enable-PSTrace -Force | ||
kvprasoon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| [XML]$ExpectedOutput = & wevtutil gl Microsoft-Windows-PowerShell/$LogType /f:xml | ||
|
|
||
| $ExpectedOutput.Channel.enabled | Should -BeExactly 'true' | ||
| } | ||
|
|
||
| it "Should disable $LogType logs for Microsoft-Windows-PowerShell." { | ||
| [XML]$CurrentState = & wevtutil gl Microsoft-Windows-PowerShell/$LogType /f:xml | ||
| if($CurrentState.channel.enabled -eq 'false'){ | ||
| & wevtutil sl Microsoft-Windows-PowerShell/$LogType /e:true /q | ||
| } | ||
| Disable-PSTrace | ||
adityapatwardhan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| [XML]$ExpectedOutput = & wevtutil gl Microsoft-Windows-PowerShell/$LogType /f:xml | ||
|
|
||
| $ExpectedOutput.Channel.enabled | Should -Be 'false' | ||
| } | ||
| } | ||
|
|
||
| Context "Test for Get-LogProperties cmdlet." { | ||
| it "Should return properties of $LogType logs for 'Microsoft-Windows-PowerShell'." { | ||
| [XML]$ExpectedOutput = wevtutil gl Microsoft-Windows-PowerShell/$LogType /f:xml | ||
|
|
||
| $LogProperty = Get-LogProperties -Name Microsoft-Windows-PowerShell/$LogType | ||
|
|
||
| $LogProperty.Name | Should -Be $ExpectedOutput.channel.Name | ||
| $LogProperty.Enabled | Should -Be $ExpectedOutput.channel.Enabled | ||
| $LogProperty.Retention | Should -Be $ExpectedOutput.channel.Logging.Retention | ||
| $LogProperty.AutoBackup | Should -Be $ExpectedOutput.channel.Logging.AutoBackup | ||
| $LogProperty.MaxLogSize | Should -Be $ExpectedOutput.channel.Logging.MaxSize | ||
|
|
||
| #Verifying the property count. Adding 2 to count from the wevtutil output as the Enabled and Name property as the count is taken only for Logging property. | ||
| ($LogProperty | Get-Member -MemberType Property | Measure-Object).Count | | ||
| Should -Be (($ExpectedOutput.Channel.Logging | Get-Member -MemberType Property | Measure-Object).Count + 2) | ||
adityapatwardhan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| Context "Test for Set-LogProperties cmdlet." { | ||
| BeforeAll { | ||
| if ($IsWindows) { | ||
| [XML]$WevtUtilBefore = wevtutil gl Microsoft-Windows-PowerShell/$LogType /f:xml | ||
| $LogPropertyToSet = [Microsoft.PowerShell.Diagnostics.LogDetails]::new($WevtUtilBefore.channel.Name, | ||
| [bool]::Parse($WevtUtilBefore.channel.Enabled), | ||
| $LogType, | ||
| [bool]::Parse($WevtUtilBefore.channel.Logging.Retention), | ||
| [bool]::Parse($WevtUtilBefore.channel.Logging.AutoBackup), | ||
| $WevtUtilBefore.channel.Logging.MaxSize -as [int] | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| it "Should invert AutoBackup setting of $LogType logs for 'Microsoft-Windows-PowerShell'." { | ||
| $LogPropertyToSet.AutoBackup = -not $LogPropertyToSet.AutoBackup | ||
| Set-LogProperties -LogDetails $LogPropertyToSet -Force | ||
|
|
||
| [XML]$ExpectedOutput = & wevtutil gl Microsoft-Windows-PowerShell/$LogType /f:xml | ||
| (Get-LogProperties -Name Microsoft-Windows-PowerShell/$LogType).AutoBackup | Should -Be ([bool]::Parse($ExpectedOutput.Channel.Logging.AutoBackup)) | ||
| } | ||
|
|
||
| it "Should throw exception for invalid LogName." { | ||
| {Set-LogProperties -LogDetails 'Foo' -Force } | Should -Throw -ErrorId 'ParameterArgumentTransformationError' | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.