Porting TTests from psl-monad Management DRTs
https://github.com/PowerShell/psl-monad/monad/tests/monad/DRT/commands/management/UnitTests/ClearEventLogDRT.cs https://github.com/PowerShell/psl-monad/monad/tests/monad/DRT/commands/management/UnitTests/CombinePathCommandTests.cs https://github.com/PowerShell/psl-monad/monad/tests/monad/DRT/commands/management/UnitTests/ContentCommandTests.cs https://github.com/PowerShell/psl-monad/monad/tests/monad/DRT/commands/management/UnitTests/ConvertPathCommandTests.cs https://github.com/PowerShell/psl-monad/monad/tests/monad/DRT/commands/management/UnitTests/DebugProcessDRT.cs https://github.com/PowerShell/psl-monad/monad/tests/monad/DRT/commands/management/UnitTests/EventlogCommandTests.cs https://github.com/PowerShell/psl-monad/monad/tests/monad/DRT/commands/management/UnitTests/GetEventLogDRTTests.cs https://github.com/PowerShell/psl-monad/monad/tests/monad/DRT/commands/management/UnitTests/GetHotFixDRTTests.cs https://github.com/PowerShell/psl-monad/monad/tests/monad/DRT/commands/management/UnitTests/GetProcessDRTTests.cs https://github.com/PowerShell/psl-monad/monad/tests/monad/DRT/commands/management/UnitTests/GetProviderCommandTest.cs https://github.com/PowerShell/psl-monad/monad/tests/monad/DRT/commands/management/UnitTests/GetServiceV2DRT.cs https://github.com/PowerShell/psl-monad/monad/tests/monad/DRT/commands/management/UnitTests/GetWMIObjectTest.cs https://github.com/PowerShell/psl-monad/monad/tests/monad/DRT/commands/management/UnitTests/InvokeWMIMethodTest.cs https://github.com/PowerShell/psl-monad/monad/tests/monad/DRT/commands/management/UnitTests/LimitEventLogDRT.cs https://github.com/PowerShell/psl-monad/monad/tests/monad/DRT/commands/management/UnitTests/NavigationTests.cs https://github.com/PowerShell/psl-monad/monad/tests/monad/DRT/commands/management/UnitTests/NewEventLogDRT.cs https://github.com/PowerShell/psl-monad/monad/tests/monad/DRT/commands/management/UnitTests/ParsePathCommandTests.cs https://github.com/PowerShell/psl-monad/monad/tests/monad/DRT/commands/management/UnitTests/PingComputerDRT.cs https://github.com/PowerShell/psl-monad/monad/tests/monad/DRT/commands/management/UnitTests/PingPathCommandTests.cs https://github.com/PowerShell/psl-monad/monad/tests/monad/DRT/commands/management/UnitTests/ProcessCommandTests.cs https://github.com/PowerShell/psl-monad/monad/tests/monad/DRT/commands/management/UnitTests/ProcessTaskTests.cs https://github.com/PowerShell/psl-monad/monad/tests/monad/DRT/commands/management/UnitTests/PropertyCommandTests.cs https://github.com/PowerShell/psl-monad/monad/tests/monad/DRT/commands/management/UnitTests/RemoveEventLogDRTTests.cs
This commit is contained in:
parent
aa95479307
commit
0eacf59dae
37
test/powershell/Clear-EventLog.Tests.ps1
Normal file
37
test/powershell/Clear-EventLog.Tests.ps1
Normal file
|
@ -0,0 +1,37 @@
|
|||
if (!$IsLinux -And !$IsOSX) {
|
||||
#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}
|
||||
}
|
||||
|
||||
|
||||
Describe "Clear-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 be able to Clear-EventLog" -Skip:($NonWinAdmin -or $IsLinux -Or $IsOSX) -Tag DRT {
|
||||
$result=Get-EventLog -LogName TestLog
|
||||
$result.Count | Should be 1
|
||||
$result.Message | Should BeExactly "Test"
|
||||
Clear-EventLog -LogName TestLog
|
||||
$result=Get-EventLog -LogName TestLog -ea Ignore
|
||||
$result.Count | Should be 0
|
||||
}
|
||||
It "should throw 'The Log name 'MissingTestLog' does not exist' when asked to clear a log that does not exist" -Skip:($IsLinux -Or $IsOSX) -Tag DRT {
|
||||
{Clear-EventLog -LogName MissingTestLog -ea stop} | Should Throw 'The Log name "MissingTestLog" does not exist'
|
||||
}
|
||||
}
|
60
test/powershell/Get-EventLog.Tests.ps1
Normal file
60
test/powershell/Get-EventLog.Tests.ps1
Normal file
|
@ -0,0 +1,60 @@
|
|||
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}
|
||||
}
|
||||
|
||||
|
||||
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'
|
||||
}
|
||||
}
|
43
test/powershell/Join-Path.Tests.ps1
Normal file
43
test/powershell/Join-Path.Tests.ps1
Normal file
|
@ -0,0 +1,43 @@
|
|||
Describe "Join-Path cmdlet tests" {
|
||||
BeforeAll {
|
||||
$StartingLocation = Get-Location
|
||||
}
|
||||
AfterEach {
|
||||
Set-Location $StartingLocation
|
||||
}
|
||||
It "should output multiple paths when called with multiple -Path targets" -Tag DRT {
|
||||
Setup -Dir SubDir1
|
||||
(Join-Path -Path TestDrive:,$TestDrive -ChildPath "SubDir1" -resolve).Length | Should be 2
|
||||
}
|
||||
It "should throw 'Cannot find drive' when drive cannot be found" -Tag DRT {
|
||||
{Join-Path bogusdrive:\\somedir otherdir -resolve -ea stop} | Should Throw "Cannot find drive"
|
||||
}
|
||||
It "should throw 'Cannot find path' when item cannot be found" -Tag DRT {
|
||||
{Join-Path "Bogus" "Path" -resolve -ea stop} | Should Throw "Cannot find path"
|
||||
}
|
||||
#[BugId(BugDatabase.WindowsOutOfBandReleases, 905237)] Note: Windows-specified bug, but the result should be the same on other platforms
|
||||
It "should return one object when called with a FileSystem::Redirector" -Tag DRT {
|
||||
set-location env:\
|
||||
$result=join-path FileSystem::windir system32
|
||||
$result.Count | Should be 1
|
||||
$result | Should BeExactly "FileSystem::windir\system32"
|
||||
}
|
||||
#[BugId(BugDatabase.WindowsOutOfBandReleases, 913084)]
|
||||
It "should be able to join-path special string 'Variable:' with 'foo'" -Tag DRT {
|
||||
$result=Join-Path "Variable:" "foo"
|
||||
$result.Count | Should be 1
|
||||
$result | Should BeExactly "Variable:\foo"
|
||||
}
|
||||
#[BugId(BugDatabase.WindowsOutOfBandReleases, 913084)]
|
||||
It "should be able to join-path special string 'Alias:' with 'foo'" -Tag DRT {
|
||||
$result=Join-Path "Alias:" "foo"
|
||||
$result.Count | Should be 1
|
||||
$result | Should BeExactly "Alias:\foo"
|
||||
}
|
||||
#[BugId(BugDatabase.WindowsOutOfBandReleases, 913084)]
|
||||
It "should be able to join-path special string 'Env:' with 'foo'" -Tag DRT {
|
||||
$result=Join-Path "Env:" "foo"
|
||||
$result.Count | Should be 1
|
||||
$result | Should BeExactly "Env:\foo"
|
||||
}
|
||||
}
|
52
test/powershell/New-EventLog.Tests.ps1
Normal file
52
test/powershell/New-EventLog.Tests.ps1
Normal file
|
@ -0,0 +1,52 @@
|
|||
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}
|
||||
}
|
||||
|
||||
|
||||
Describe "New-EventLog cmdlet tests" {
|
||||
BeforeEach {
|
||||
Remove-EventLog -LogName TestLog -ea Ignore
|
||||
}
|
||||
It "should be able to create a New-EventLog with a -Source paramter" -Skip:($NonWinAdmin -or $IsLinux -Or $IsOSX) -Tag DRT {
|
||||
{New-EventLog -LogName TestLog -Source TestSource -ea stop} | Should Not Throw
|
||||
{Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 1 -ea stop} | Should Not Throw
|
||||
$result=Get-EventLog -LogName TestLog
|
||||
$result.Count | Should be 1
|
||||
}
|
||||
It "should be able to create a New-EventLog with a -ComputerName paramter" -Skip:($NonWinAdmin -or $IsLinux -Or $IsOSX) -Tag DRT {
|
||||
{New-EventLog -LogName TestLog -Source TestSource -ComputerName $env:COMPUTERNAME -ea stop} | Should Not Throw
|
||||
{Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 1 -ea stop} | Should Not Throw
|
||||
$result=Get-EventLog -LogName TestLog
|
||||
$result.Count | Should be 1
|
||||
$result.EventID | Should be 1
|
||||
}
|
||||
It "should be able to create a New-EventLog with a -CategoryResourceFile paramter" -Skip:($NonWinAdmin -or $IsLinux -Or $IsOSX) -Tag DRT {
|
||||
{New-EventLog -LogName TestLog -Source TestSource -CategoryResourceFile "CategoryMessageFile" -ea stop} | Should Not Throw
|
||||
{Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 2 -ea stop} | Should Not Throw
|
||||
$result=Get-EventLog -LogName TestLog
|
||||
$result.Count | Should be 1
|
||||
$result.EventID | Should be 2
|
||||
}
|
||||
It "should be able to create a New-EventLog with a -MessageResourceFile paramter" -Skip:($NonWinAdmin -or $IsLinux -Or $IsOSX) -Tag DRT {
|
||||
{New-EventLog -LogName TestLog -Source TestSource -MessageResourceFile "ResourceMessageFile" -ea stop} | Should Not Throw
|
||||
{Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 3 -ea stop} | Should Not Throw
|
||||
$result=Get-EventLog -LogName TestLog
|
||||
$result.Count | Should be 1
|
||||
$result.EventID | Should be 3
|
||||
}
|
||||
It "should be able to create a New-EventLog with a -ParameterResourceFile paramter" -Skip:($NonWinAdmin -or $IsLinux -Or $IsOSX) -Tag DRT {
|
||||
{New-EventLog -LogName TestLog -Source TestSource -ParameterResourceFile "ParameterMessageFile" -ea stop} | Should Not Throw
|
||||
{Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 4 -ea stop} | Should Not Throw
|
||||
$result=Get-EventLog -LogName TestLog
|
||||
$result.Count | Should be 1
|
||||
$result.EventID | Should be 4
|
||||
}
|
||||
It "should throw 'The Log name 'MissingTestLog' does not exist' when asked to clear a log that does not exist" -Tag DRT {
|
||||
{Clear-EventLog -LogName MissingTestLog -ea stop} | Should Throw 'The Log name "MissingTestLog" does not exist'
|
||||
}
|
||||
}
|
27
test/powershell/Remove-EventLog.Tests.ps1
Normal file
27
test/powershell/Remove-EventLog.Tests.ps1
Normal file
|
@ -0,0 +1,27 @@
|
|||
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}
|
||||
}
|
||||
|
||||
|
||||
Describe "New-EventLog cmdlet tests" {
|
||||
BeforeEach {
|
||||
Remove-EventLog -LogName TestLog -ea Ignore
|
||||
New-EventLog -LogName TestLog -Source TestSource -ea Ignore
|
||||
Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 1 -ea ignore
|
||||
}
|
||||
It "should be able to Remove-EventLog -LogName <string> -ComputerName <string>" -Skip:($NonWinAdmin -or $IsLinux -Or $IsOSX) -Tag DRT {
|
||||
{Remove-EventLog -LogName TestLog -ComputerName $env:COMPUTERNAME -ea stop} | Should Not Throw
|
||||
{Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 1 -ea stop} | Should Throw
|
||||
{Get-EventLog -LogName TestLog -ea stop} | Should Throw
|
||||
}
|
||||
It "should be able to Remove-EventLog -Source <string> -ComputerName <string>" -Skip:($true -Or $NonWinAdmin -Or $IsLinux -Or $IsOSX) -Tag DRT {
|
||||
{Remove-EventLog -Source TestSource -ComputerName $env:COMPUTERNAME -ea stop} | Should Not Throw
|
||||
{Write-EventLog -LogName TestLog -Source TestSource -Message "Test" -EventID 1 -ea stop} | Should Throw
|
||||
{Get-EventLog -LogName TestLog -ea stop} | Should Throw
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue