Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new Pester syntax: -Parameter for Pester tests in Modules/CimCmdlets #6306

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions test/powershell/Modules/CimCmdlets/CimInstance.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ Try {
# we can't use equals here as on windows cimclassname
# is win32_computersystem, but that's not likely to be the
# case on non-Windows systems
$instance.cimClass.CimClassName | should match _computersystem
$instance.cimClass.CimClassName | Should -Match _computersystem
}
It "Property access should be case insensitive" {
foreach($property in $instance.psobject.properties.name) {
$pUpper = $property.ToUpper()
$pLower = $property.ToLower()
[string]$pLowerValue = $pinstance.$pLower -join ","
[string]$pUpperValue = $pinstance.$pUpper -join ","
$pLowerValue | should be $pUpperValue
$pLowerValue | Should -BeExactly $pUpperValue
}
}
It "GetCimSessionInstanceId method invocation should return data" {
$instance.GetCimSessionInstanceId() | Should BeOfType "Guid"
$instance.GetCimSessionInstanceId() | Should -BeOfType "Guid"
}
It "should produce an error for a non-existing classname" {
try {
get-ciminstance -classname thisnameshouldnotexist -ea stop
throw "expected error did not occur"
}
catch {
$_.FullyQualifiedErrorId | should be "HRESULT 0x80041010,Microsoft.Management.Infrastructure.CimCmdlets.GetCimInstanceCommand"
$_.FullyQualifiedErrorId | Should -Be "HRESULT 0x80041010,Microsoft.Management.Infrastructure.CimCmdlets.GetCimInstanceCommand"
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions test/powershell/Modules/CimCmdlets/CimSession.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@ try {
$sessionName = [guid]::NewGuid()
$session = New-CimSession -ComputerName . -name $sessionName
$sessions += $session
$session.Name | Should be $sessionName
$session.InstanceId | should BeOfType "System.Guid"
$session.Name | Should -Be $sessionName
$session.InstanceId | Should -BeOfType "System.Guid"
}
It "A Cim session can be retrieved" {
$sessionName = [guid]::NewGuid()
$session = New-CimSession -ComputerName . -name $sessionName
$sessions += $session
(get-cimsession -Name $sessionName).InstanceId | should be $session.InstanceId
(get-cimsession -Id $session.Id).InstanceId | should be $session.InstanceId
(get-cimsession -InstanceId $session.InstanceId).InstanceId | should be $session.InstanceId
(get-cimsession -Name $sessionName).InstanceId | Should -Be $session.InstanceId
(get-cimsession -Id $session.Id).InstanceId | Should -Be $session.InstanceId
(get-cimsession -InstanceId $session.InstanceId).InstanceId | Should -Be $session.InstanceId
}
It "A cim session can be removed" {
$sessionName = [guid]::NewGuid()
$session = New-CimSession -ComputerName . -name $sessionName
$sessions += $session
$session.Name | Should be $sessionName
$session.Name | Should -Be $sessionName
$session | Remove-CimSession
Get-CimSession $session.Id -ErrorAction SilentlyContinue | should BeNullOrEmpty
Get-CimSession $session.Id -ErrorAction SilentlyContinue | Should -BeNullOrEmpty
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions test/powershell/Modules/CimCmdlets/Get-CimClass.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ try {

Describe 'Get-CimClass' -tags "CI" {
It 'can get CIM_Error CIM class' {
Get-CimClass -ClassName CIM_Error | Should Not BeNullOrEmpty
Get-CimClass -ClassName CIM_Error | Should -Not -BeNullOrEmpty
}
It 'can get class when namespace is specified' {
Get-CimClass -ClassName CIM_OperatingSystem -Namespace root/cimv2 | Should Not BeNullOrEmpty
Get-CimClass -ClassName CIM_OperatingSystem -Namespace root/cimv2 | Should -Not -BeNullOrEmpty
}

It 'produces an error when a non-existent class is used' {
Expand All @@ -20,7 +20,7 @@ try {
throw "Expected error did not occur"
}
catch {
$_.FullyQualifiedErrorId | should be "HRESULT 0x80041002,Microsoft.Management.Infrastructure.CimCmdlets.GetCimClassCommand"
$_.FullyQualifiedErrorId | Should -Be "HRESULT 0x80041002,Microsoft.Management.Infrastructure.CimCmdlets.GetCimClassCommand"
}
}
It 'produces an error when an improper namespace is used' {
Expand All @@ -29,15 +29,15 @@ try {
throw "Expected error did not occur"
}
catch {
$_.FullyQualifiedErrorId | should be "HRESULT 0x8004100e,Microsoft.Management.Infrastructure.CimCmdlets.GetCimClassCommand"
$_.FullyQualifiedErrorId | Should -Be "HRESULT 0x8004100e,Microsoft.Management.Infrastructure.CimCmdlets.GetCimClassCommand"
}
}
}

# feature tests
Describe 'Get-CimClass' -tags @("Feature") {
It 'can retrieve a class when a method is provided' {
Get-CimClass -MethodName Reboot | Should Not BeNullOrEmpty
Get-CimClass -MethodName Reboot | Should -Not -BeNullOrEmpty
}
}
}
Expand Down