Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@ Describe "Clear-EventLog cmdlet tests" -Tags @('CI', 'RequireAdminOnWindows') {

It "should be able to Clear-EventLog" -Pending:($True) {
Remove-EventLog -LogName TestLog -ea Ignore
{New-EventLog -LogName TestLog -Source TestSource -ErrorAction Stop} | Should -Not -Throw
{Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 1 -ErrorAction Stop } | Should -Not -Throw
{$result=Get-EventLog -LogName TestLog} | Should -Not -Throw
($result.Count) | Should -Be 1
{Clear-EventLog -LogName TestLog} | Should -Not -Throw
$result=Get-EventLog -LogName TestLog -ea Ignore
($result.Count) | Should -Be 0
{Remove-EventLog -LogName TestLog -ErrorAction Stop} | Should -Not -Throw
}
It "should throw 'The Log name 'MissingTestLog' does not exist' when asked to clear a log that does not exist" -Pending:($True) {
Remove-EventLog -LogName MissingTestLog -ea Ignore
{ Clear-EventLog -LogName MissingTestLog -ErrorAction Stop } | Should -Throw -ErrorId "Microsoft.PowerShell.Commands.ClearEventLogCommand"
{ New-EventLog -LogName TestLog -Source TestSource -ErrorAction Stop } | Should -Not -Throw
{ Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 1 -ErrorAction Stop } | Should -Not -Throw
{ Get-EventLog -LogName TestLog } | Should -Not -Throw
$result = Get-EventLog -LogName TestLog
$result.Count | Should -Be 1
{ Clear-EventLog -LogName TestLog } | Should -Not -Throw
$result = Get-EventLog -LogName TestLog -ErrorAction Ignore
$result.Count | Should -Be 0
{ Remove-EventLog -LogName TestLog -ErrorAction Stop } | Should -Not -Throw
}

It "should throw 'System.InvalidOperationException' when asked to clear a log that does not exist" -Pending:($True) {
{ Clear-EventLog -LogName MissingTestLog -ErrorAction Stop } | Should -Throw -ExceptionType "System.InvalidOperationException"
}

It "should throw 'Microsoft.PowerShell.Commands.ClearEventLogCommand' ErrorId when asked to clear a log that does not exist" -Pending:($True) {
{ Clear-EventLog -LogName MissingTestLog -ErrorAction Stop } | Should -Throw -ErrorId "Microsoft.PowerShell.Commands.ClearEventLogCommand"
}
}