mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Convert ShouldBeErrorId to Should -Throw -ErrorId in PowerShell tests.
Get rid of try { } catch { } formula to assert that errors were thrown.
Small fixes in tests to obey the new Pester -Parameter syntax.
35 lines
2.1 KiB
PowerShell
35 lines
2.1 KiB
PowerShell
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
# Licensed under the MIT License.
|
|
Describe "New-EventLog cmdlet tests" -Tags @('CI', 'RequireAdminOnWindows') {
|
|
|
|
BeforeAll {
|
|
$defaultParamValues = $PSdefaultParameterValues.Clone()
|
|
$IsNotSkipped = ($IsWindows -and !$IsCoreCLR)
|
|
$PSDefaultParameterValues["it:skip"] = !$IsNotSkipped
|
|
}
|
|
|
|
AfterAll {
|
|
$global:PSDefaultParameterValues = $defaultParamValues
|
|
}
|
|
|
|
BeforeEach {
|
|
if ($IsNotSkipped) {
|
|
Remove-EventLog -LogName TestLog -ErrorAction 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
|
|
}
|
|
}
|
|
#CmdLet is NYI - change to -Skip:($NonWinAdmin) when implemented
|
|
It "should be able to Remove-EventLog -LogName <string> -ComputerName <string>" -Pending:($True) {
|
|
{ Remove-EventLog -LogName TestLog -ComputerName $env:COMPUTERNAME -ErrorAction Stop } | Should -Not -Throw
|
|
{ Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 1 -ErrorAction Stop } | Should -Throw -ErrorId "Microsoft.PowerShell.Commands.WriteEventLogCommand"
|
|
{ Get-EventLog -LogName TestLog -ErrorAction Stop } | Should -Throw -ErrorId "System.InvalidOperationException,Microsoft.PowerShell.Commands.GetEventLogCommand"
|
|
}
|
|
#CmdLet is NYI - change to -Skip:($NonWinAdmin) when implemented
|
|
It "should be able to Remove-EventLog -Source <string> -ComputerName <string>" -Pending:($True) {
|
|
{Remove-EventLog -Source TestSource -ComputerName $env:COMPUTERNAME -ErrorAction Stop} | Should -Not -Throw
|
|
{ Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 1 -ErrorAction Stop } | Should -Throw -ErrorId "Microsoft.PowerShell.Commands.WriteEventLogCommand"
|
|
{ Get-EventLog -LogName TestLog -ErrorAction Stop; } | Should -Throw -ErrorId "System.InvalidOperationException,Microsoft.PowerShell.Commands.GetEventLogCommand"
|
|
}
|
|
}
|