MegaBites-AI/Windows-powershell
0372
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3Describe "Clear-EventLog cmdlet tests" -Tags @('CI', 'RequireAdminOnWindows') {4 5 BeforeAll {6 $defaultParamValues = $PSDefaultParameterValues.Clone()7 $PSDefaultParameterValues["it:skip"] = !$IsWindows -or $IsCoreCLR8 }9 10 AfterAll {11 $global:PSDefaultParameterValues = $defaultParamValues12 }13 14 It "should be able to Clear-EventLog" -Pending:($true) {15 Remove-EventLog -LogName TestLog -ErrorAction Ignore16 { New-EventLog -LogName TestLog -Source TestSource -ErrorAction Stop } | Should -Not -Throw17 { Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventId 1 -ErrorAction Stop } | Should -Not -Throw18 { Get-EventLog -LogName TestLog } | Should -Not -Throw19 $result = Get-EventLog -LogName TestLog20 $result.Count | Should -Be 121 { Clear-EventLog -LogName TestLog } | Should -Not -Throw22 $result = Get-EventLog -LogName TestLog -ErrorAction Ignore23 $result.Count | Should -Be 024 { Remove-EventLog -LogName TestLog -ErrorAction Stop } | Should -Not -Throw25 }26 27 It "should throw 'System.InvalidOperationException' when asked to clear a log that does not exist" -Pending:($true) {28 { Clear-EventLog -LogName MissingTestLog -ErrorAction Stop } | Should -Throw -ExceptionType "System.InvalidOperationException"29 }30 31 It "should throw 'Microsoft.PowerShell.Commands.ClearEventLogCommand' ErrorId when asked to clear a log that does not exist" -Pending:($true) {32 { Clear-EventLog -LogName MissingTestLog -ErrorAction Stop } | Should -Throw -ErrorId "Microsoft.PowerShell.Commands.ClearEventLogCommand"33 }34}35 