mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 12:45:47 +00:00
Incorporating feedback from code-review
This commit is contained in:
1 parent
0eacf59dae
commit
e9606484da
9 files changed
+427
-461
No files matched your search
@@ -1,60 +1,44 @@
|
||||
if ($IsWindows) {
|
||||
#check to see whether we're running as admin in Windows...
|
||||
$windowsIdentity = [Security.Principal.WindowsIdentity]::GetCurrent()
|
||||
$windowsPrincipal = new-object 'Security.Principal.WindowsPrincipal' $windowsIdentity
|
||||
if ($windowsPrincipal.IsInRole("Administrators") -eq $true) {
|
||||
$NonWinAdmin=$false
|
||||
} else {$NonWinAdmin=$true}
|
||||
#check to see whether we're running as admin in Windows...
|
||||
$windowsIdentity = [Security.Principal.WindowsIdentity]::GetCurrent()
|
||||
$windowsPrincipal = new-object 'Security.Principal.WindowsPrincipal' $windowsIdentity
|
||||
if ($windowsPrincipal.IsInRole("Administrators") -eq $true) {
|
||||
$NonWinAdmin=$false
|
||||
} else {exit}
|
||||
Describe "Get-EventLog cmdlet tests" -Tags:DRT {
|
||||
#CmdLets are not yet implemented, so these cases are -Pending:($True) for now...
|
||||
It "should return an array of eventlogs objects when called with -AsString parameter" -Pending:($True) {
|
||||
{$result=Get-EventLog -AsString -ea stop} | Should Not Throw
|
||||
$result.GetType().BaseType.Name | Should Be "Array"
|
||||
$result -eq "Application" | Should Be "Application"
|
||||
$result.Count -ge 3 | Should Be $true
|
||||
}
|
||||
It "should return a list of eventlog objects when called with -List parameter" -Pending:($True) {
|
||||
{$result=Get-EventLog -List -ea stop} | Should Not Throw
|
||||
$result.GetType().BaseType.Name | Should Be "array"
|
||||
{$logs=$result|Select -ExpandProperty Log} | Should Not Throw
|
||||
$logs -eq "System" | Should Be "System"
|
||||
$logs.Count -ge 3 | Should Be $true
|
||||
}
|
||||
It "should be able to Get-EventLog -LogName Application -Newest 100" -Pending:($True) {
|
||||
{$result=get-eventlog -LogName Application -Newest 100 -ea stop} | Should Not Throw
|
||||
$result | Should Not BeNullOrEmpty
|
||||
$result.Length -le 100 | Should Be $true
|
||||
$result[0].GetType().Name | Should Be "EventLogEntry"
|
||||
}
|
||||
It "should throw 'AmbiguousParameterSetException' when called with both -LogName and -List parameters" -Pending:($True) {
|
||||
try {Get-EventLog -LogName System -List -ea stop; Throw "Previous statement unexpectedly succeeded..."
|
||||
} catch {echo $_.FullyQualifiedErrorId | Should Be "AmbiguousParameterSet,Microsoft.PowerShell.Commands.GetEventLogCommand"}
|
||||
}
|
||||
It "should be able to Get-EventLog -LogName * with multiple matches" -Pending:($True) {
|
||||
{$result=get-eventlog -LogName * -ea stop} | Should Not Throw
|
||||
$result | Should Not BeNullOrEmpty
|
||||
$result -eq "Security" | Should Be "Security"
|
||||
$result.Count -ge 3 | Should Be $true
|
||||
}
|
||||
It "should throw 'InvalidOperationException' when asked to get a log that does not exist" -Pending:($True) {
|
||||
try {Get-EventLog -LogName MissingTestLog -ea stop; Throw "Previous statement unexpectedly succeeded..."
|
||||
} catch {echo $_.FullyQualifiedErrorId | Should Be "System.InvalidOperationException,Microsoft.PowerShell.Commands.GetEventLogCommand"}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Describe "Get-EventLog cmdlet tests" {
|
||||
BeforeAll {
|
||||
Remove-EventLog -LogName TestLog -ea Ignore
|
||||
Remove-EventLog -LogName MissingTestLog -ea Ignore
|
||||
New-EventLog -LogName TestLog -Source TestSource -ea Ignore
|
||||
}
|
||||
BeforeEach {
|
||||
Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 1 -ea Ignore
|
||||
}
|
||||
AfterEach {
|
||||
Clear-EventLog -LogName TestLog -ea Ignore
|
||||
}
|
||||
AfterAll {
|
||||
Remove-EventLog -LogName TestLog -ea Ignore
|
||||
}
|
||||
It "should return an array of strings when called with -AsString parameter" -Skip:($IsLinux -Or $IsOSX) -Tag DRT {
|
||||
{$result=Get-EventLog -AsString -ea stop} | Should Not Throw
|
||||
{$result.GetType()|% { $_.IsArray }} | Should Be $true
|
||||
{$result.Contains("System")} | Should Be $true
|
||||
{$result.Contains("TestLog")} | Should Be $true
|
||||
($result.Count -ge 4) | Should Be $true
|
||||
}
|
||||
It "should return a list of strings when called with -List parameter" -Skip:($IsLinux -Or $IsOSX) -Tag DRT {
|
||||
{$result=Get-EventLog -List -ea stop} | Should Not Throw
|
||||
{$result.GetType()|% { $_.IsArray }} | Should Be $true
|
||||
{$logs=$result|Select -ExpandProperty Log} | Should Not Throw
|
||||
{$logs.Contains("System")} | Should Be $true
|
||||
{$logs.Contains("TestLog")} | Should Be $true
|
||||
($logs.Count -ge 4) | Should Be $true
|
||||
}
|
||||
It "should be able to Get-EventLog -LogName Application -Newest 100" -Skip:($IsLinux -Or $IsOSX) -Tag DRT {
|
||||
{$result=get-eventlog -LogName Application -Newest 100 -ea stop} | Should Not Throw
|
||||
($result) | Should Not BeNullOrEmpty
|
||||
($result.Length -le 100) | Should Be $true
|
||||
($result[0].GetType().Name) | Should Be EventLog
|
||||
}
|
||||
It "should throw 'ParameterBindingException' when called with both -List and -AsString" -Skip:($IsLinux -Or $IsOSX) -Tag DRT {
|
||||
{Get-EventLog -LogName MissingTestLog -ea stop} | Should Throw
|
||||
}
|
||||
It "should be able to Get-EventLog -LogName * with multiple matches" -Skip:($IsLinux -Or $IsOSX) -Tag DRT {
|
||||
{$result=get-eventlog -LogName * -ea stop}| Should Not Throw
|
||||
($result) | Should Not BeNullOrEmpty
|
||||
{$result.Contains("System")} | Should Be $true
|
||||
{$result.Contains("TestLog")} | Should Be $true
|
||||
($result.count -ge 4) | Should Be $true
|
||||
}
|
||||
It "should throw 'The Log name 'MissingTestLog' does not exist' when asked to get a log that does not exist" -Skip:($IsLinux -Or $IsOSX) -Tag DRT {
|
||||
{Get-EventLog -LogName MissingTestLog -ea stop} | Should Throw 'does not exist'
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user