Skip to content

Commit c41e088

Browse files
committed
Broken state
1 parent a2434fa commit c41e088

File tree

4 files changed

+358
-358
lines changed

4 files changed

+358
-358
lines changed

wmi-adapter/Tests/wmi.tests.ps1

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -59,39 +59,27 @@ Describe 'WMI adapter resource tests' {
5959
$res.results[1].result.actualState.result[4].properties.AdapterType | Should -BeLike "Ethernet*"
6060
}
6161

62-
It 'Throws error when methodName is missing on set' -Skip:(!$IsWindows) {
63-
'{"Name":"wuauserv"}' | dsc -l trace resource set -r 'root.cimv2/Win32_Service' -f - 2> $TestDrive\tracing.txt
64-
$LASTEXITCODE | Should -Be 2
65-
"$TestDrive/tracing.txt" | Should -FileContentMatch "'methodName' property is required for invoking a WMI/CIM method."
62+
It 'Set does not work with missing key property' -Skip:(!$IsWindows) {
63+
$s = dsc resource set --resource root.cimv2/Win32_Environment --input '{}' 2>&1
64+
$LASTEXITCODE | Should -Be 1
65+
$s | Should -BeLike "*Key property 'Name' is required*"
6666
}
6767

68-
It 'Throws error when methodName is set but parameters are missing on set' -Skip:(!$IsWindows) {
69-
'{"Name":"wuauserv", "methodName":"StartService"}' | dsc -l trace resource set -r 'root.cimv2/Win32_Service' -f - 2> $TestDrive\tracing.txt
70-
$LASTEXITCODE | Should -Be 2
71-
"$TestDrive/tracing.txt" | Should -FileContentMatch "'parameters' property is required for invoking a WMI/CIM method."
72-
}
73-
74-
It 'Set works on a WMI resource with methodName and parameters' -Skip:(!$IsWindows) {
75-
BeforeAll {
76-
$script:service = Get-Service -Name wuauserv -ErrorAction Ignore
77-
78-
if ($service -and $service.Status -eq 'Running') {
79-
$service.Stop()
80-
}
81-
}
68+
It 'Set works on a WMI resource' -Skip:(!$IsWindows) {
69+
$i = @{
70+
UserName = ("{0}\{1}" -f $env:USERDOMAIN, $env:USERNAME) # Read-only property required
71+
Name = "TestVariable"
72+
VariableValue = "TestValue"
73+
} | ConvertTo-Json
8274

75+
$r = dsc -l trace resource set -r root.cimv2/Win32_Environment -i $i
8376

84-
$r = '{"Name":"wuauserv", "methodName":"StartService", "parameters":{}}' | dsc resource set -r 'root.cimv2/Win32_Service' -f -
77+
$s = dsc resource set --resource root.cimv2/Win32_Environment --input '{"Name":"TestVariable","Value":"TestValue"}'
8578
$LASTEXITCODE | Should -Be 0
86-
87-
$res = '{"Name":"wuauserv", "State": null}' | dsc resource get -r 'root.cimv2/Win32_Service' -f - | ConvertFrom-Json
88-
$res.actualState.Name | Should -Be 'wuauserv'
89-
$res.actualState.State | Should -Be 'Running'
79+
$s | Should -BeLike "*Set operation completed successfully*"
9080

91-
AfterAll {
92-
if ($service -and $service.Status -eq 'Running') {
93-
$service.Stop()
94-
}
95-
}
81+
# Verify the variable was set
82+
$get = dsc resource get -r root.cimv2/Win32_Environment -i '{"Name":"TestVariable"}'
83+
$get | Should -BeLike "*TestValue*"
9684
}
9785
}

wmi-adapter/wmi.resource.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ param(
1010
)
1111

1212
# Import private functions
13-
$wmiAdapter = Import-Module "$PSScriptRoot/wmiAdapter.psm1" -Force -PassThru
13+
$wmiAdapter = Import-Module "$PSScriptRoot\wmiAdapter.psm1" -Force -PassThru
1414

1515
if ('Validate' -ne $Operation) {
1616
# initialize OUTPUT as array

0 commit comments

Comments
 (0)