Skip to content

Commit

Permalink
Add new tests for Get-WinEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesWTruher committed Sep 28, 2016
1 parent 18f732f commit 4809414
Showing 1 changed file with 61 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,66 @@
Describe 'Get-WinEvent' -Tags "CI" {
BeforeAll {
if ( ! $IsWindows )
{
$origDefaults = $PSDefaultParameterValues.Clone()
$PSDefaultParameterValues['it:skip'] = $true
}
}
AfterAll {
if ( ! $IsWindows ){
$global:PSDefaultParameterValues = $origDefaults
}
}
Context "Get-WinEvent ListProvider parameter" {
It 'Get-WinEvent can list the providers' {
$result = Get-WinEvent -listprovider * -erroraction ignore
$result | should not BeNullOrEmpty
}
It 'Get-WinEvent can get a provider by name' {
$providers = Get-WinEvent -listprovider * -erroraction ignore
$result = Get-WinEvent -listprovider ($providers[0].name)
$result | should not BeNullOrEmpty
}

}
Context "Get-WinEvent can retrieve events" {
# for this set of tests we need to have a provider which has multiple events
BeforeAll {
$foundEvents = $false
$providers = Get-WinEvent -listprovider * -erroraction ignore
foreach($provider in $providers) {
$events = Get-WinEvent -provider $provider.name -erroraction ignore
if ( $events.Count -gt 2 ) {
$providerForTests = $provider
$foundEvents = $true
break
}
}
}
It 'Get-WinEvent can get events from a provider' {
# we sample the first 20 results, as this could be very large
$results = Get-WinEvent -provider $providerForTests.Name -max 20
foreach($event in $results ) {
$event.providername | should be $providerForTests.name
}
}
It 'Get-WinEvent can get events via logname' {
$results = get-winevent -logname $providerForTests.LogLinks.LogName -MaxEvents 10
$results | should not BeNullOrEmpty
}
It 'Get-WinEvent can use the simplest of filters' {
$filter = @{ ProviderName = $providerForTests.Name }
$testEvents = Get-WinEvent -filterhashtable $filter
$testEvents.Count | should be $events.Count
}
It 'Get-WinEvent can use a filter which includes two items' {
$filter = @{ ProviderName = $providerForTests.Name; Id = $events[0].Id}
$results = Get-WinEvent -filterHashtable $filter
$results | Should not BeNullOrEmpty
}
}
# Get-WinEvent works only on windows
It 'can query a System log' -Skip:(-not $IsWindows) {
Get-WinEvent -LogName System -MaxEvents 1 | Should Not Be $null
It 'can query a System log' {
Get-WinEvent -LogName System -MaxEvents 1 | Should Not BeNullOrEmpty
}
}

0 comments on commit 4809414

Please sign in to comment.