Skip to content

Commit 9550bd8

Browse files
authored
Merge pull request #675 from SteveL-MSFT/no-properties
Fix allowing no properties to resource in config
2 parents 416c770 + b530520 commit 9550bd8

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

Diff for: dsc/tests/dsc_config_get.tests.ps1

+16
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,20 @@ Describe 'dsc config get tests' {
166166
$result.results[0].result.actualState.output | Should -Be 'hello'
167167
$LASTEXITCODE | Should -Be 0
168168
}
169+
170+
It 'no properties is supported' {
171+
$config_yaml = @'
172+
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
173+
resources:
174+
- name: OS
175+
type: Microsoft/OSInfo
176+
'@
177+
$result = dsc config get -i $config_yaml | ConvertFrom-Json
178+
$result.hadErrors | Should -BeFalse
179+
$result.results.Count | Should -Be 1
180+
$result.results[0].Name | Should -Be 'OS'
181+
$result.results[0].type | Should -BeExactly 'Microsoft/OSInfo'
182+
$result.results[0].result.actualState.family | Should -BeIn @('Windows', 'Linux', 'macOS')
183+
$LASTEXITCODE | Should -Be 0
184+
}
169185
}

Diff for: dsc_lib/src/configure/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,14 @@ fn add_metadata(kind: &Kind, mut properties: Option<Map<String, Value>> ) -> Res
151151
return Ok(serde_json::to_string(&properties)?);
152152
}
153153

154-
Ok(serde_json::to_string(&properties)?)
154+
match properties {
155+
Some(properties) => {
156+
Ok(serde_json::to_string(&properties)?)
157+
},
158+
_ => {
159+
Ok(String::new())
160+
}
161+
}
155162
}
156163

157164
fn check_security_context(metadata: Option<&Metadata>) -> Result<(), DscError> {

0 commit comments

Comments
 (0)