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

Adding tests for PSDiagnostics Module #8431

Merged
merged 13 commits into from
Jan 16, 2019
67 changes: 67 additions & 0 deletions test/powershell/Modules/PSDiagnostics/PSDiagnostics.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

Describe -Name "PSDiagnostics cmdlets tests" -Tag "CI","RequireAdminOnWindows" {
Context -Name "Test for Enable-PSTrace cmdlet" {
it -Name "Should enable Analytic logs for Microsoft-Windows-PowerShell." -Skip:(-not $IsWindows) {
kvprasoon marked this conversation as resolved.
Show resolved Hide resolved
Enable-PSTrace -Force
kvprasoon marked this conversation as resolved.
Show resolved Hide resolved

[XML]$WevtUtilOutput = & wevtutil gl Microsoft-Windows-PowerShell/Analytic /f:xml

$WevtUtilOutput.Channel.enabled | Should -Be 'true'
kvprasoon marked this conversation as resolved.
Show resolved Hide resolved
}
}

Context -Name "Test for Disable-PSTrace cmdlet" {
it -Name "Should disable Analytic logs for Microsoft-Windows-PowerShell." -Skip:(-not $IsWindows) {
Disable-PSTrace
adityapatwardhan marked this conversation as resolved.
Show resolved Hide resolved

[XML]$WevtUtilOutput = & wevtutil gl Microsoft-Windows-PowerShell/Analytic /f:xml

$WevtUtilOutput.Channel.enabled | Should -Be 'false'
}
}

Context -Name "Test for Get-LogProperties cmdlet" {
it -Name "Should show properties of Admin logs for 'Microsoft-Windows-PowerShell'." -Skip:(-not $IsWindows) {
[XML]$WevtUtilOutput = wevtutil gl Microsoft-Windows-PowerShell/Admin /f:xml
kvprasoon marked this conversation as resolved.
Show resolved Hide resolved

$LogProperty = Get-LogProperties -Name Microsoft-Windows-PowerShell/Admin

$LogProperty.Name | Should -Be $WevtUtilOutput.channel.Name
$LogProperty.Enabled | Should -Be $WevtUtilOutput.channel.Enabled
$LogProperty.Retention | Should -Be $WevtUtilOutput.channel.Logging.Retention
$LogProperty.AutoBackup | Should -Be $WevtUtilOutput.channel.Logging.AutoBackup
$LogProperty.MaxLogSize | Should -Be $WevtUtilOutput.channel.Logging.MaxSize
kvprasoon marked this conversation as resolved.
Show resolved Hide resolved
}
}

Context -Name "Test for Set-LogProperties cmdlet" {
BeforeAll {
kvprasoon marked this conversation as resolved.
Show resolved Hide resolved
$LogType = 'Analytic'
if($IsWindows){
kvprasoon marked this conversation as resolved.
Show resolved Hide resolved
[XML]$WevtUtilBefore = wevtutil gl Microsoft-Windows-PowerShell/$LogType /f:xml
$LogPropertyToSet = [Microsoft.PowerShell.Diagnostics.LogDetails]::new($WevtUtilBefore.channel.Name,
$WevtUtilBefore.channel.Enabled -as [bool],
kvprasoon marked this conversation as resolved.
Show resolved Hide resolved
$LogType,
$WevtUtilBefore.channel.Logging.Retention -as [bool],
$WevtUtilBefore.channel.Logging.AutoBackup -as [bool],
kvprasoon marked this conversation as resolved.
Show resolved Hide resolved
$WevtUtilBefore.channel.Logging.MaxSize -as [int]
)
}
}

it -Name "Should invert AutoBackup setting of $LogType logs for 'Microsoft-Windows-PowerShell'." -Skip:(-not $IsWindows) {
$LogPropertyToSet.AutoBackup = -not $LogPropertyToSet.AutoBackup
$LogProperty = Set-LogProperties -LogDetails $LogPropertyToSet -Force

[XML]$WevtUtilOutput = & wevtutil gl Microsoft-Windows-PowerShell/$LogType /f:xml

$LogPropertyToSet.AutoBackup | Should -Be $WevtUtilOutput.Channel.Logging.AutoBackup
}

it -Name "Should throw excpetion for invalid LogName." -Skip:(-not $IsWindows) {
{Set-LogProperties -LogDetails 'Foo' -Force } | Should -Throw -ErrorId 'ParameterArgumentTransformationError'
}
}
}