Skip to content

Commit 2f6d6b4

Browse files
committed
add test for bubbling up properties from export
1 parent 202aed5 commit 2f6d6b4

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

dsc/tests/dsc_export.tests.ps1

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,23 @@ resources:
161161
$out.resources[1].properties.foo | Should -BeExactly 'bar'
162162
$out.resources[1].properties.hello | Should -BeExactly 'world'
163163
}
164+
165+
It 'Export can surface _kind, _securityContext, and _name from a resource' {
166+
$yaml = @'
167+
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/08/config/document.json
168+
resources:
169+
- name: Test Export
170+
type: Test/ExportBubble
171+
properties:
172+
'@
173+
$out = dsc config export -i $yaml | ConvertFrom-Json
174+
$LASTEXITCODE | Should -Be 0
175+
$out.resources.count | Should -Be 1
176+
$out.resources[0].name | Should -BeExactly 'TestName'
177+
$out.resources[0].kind | Should -BeExactly 'TestKind'
178+
$out.resources[0].securityContext | Should -BeExactly 'TestSecurityContext'
179+
$out.resources[0].properties.psobject.properties.name | Should -Not -Contain '_kind'
180+
$out.resources[0].properties.psobject.properties.name | Should -Not -Contain '_securityContext'
181+
$out.resources[0].properties.psobject.properties.name | Should -Not -Contain '_name'
182+
}
164183
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"$schema": "https://aka.ms/dsc/schemas/v3/bundled/resource/manifest.json",
3+
"type": "Test/ExportBubble",
4+
"version": "0.1.0",
5+
"export": {
6+
"executable": "dsctest",
7+
"args": [
8+
"export-bubble"
9+
]
10+
},
11+
"schema": {
12+
"command": {
13+
"executable": "dsctest",
14+
"args": [
15+
"schema",
16+
"-s",
17+
"export-bubble"
18+
]
19+
}
20+
}
21+
}

tools/dsctest/src/args.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub enum Schemas {
1010
ExitCode,
1111
InDesiredState,
1212
Export,
13+
ExportBubble,
1314
Exporter,
1415
Sleep,
1516
Trace,
@@ -54,6 +55,10 @@ pub enum SubCommand {
5455
#[clap(name = "input", short, long, help = "The input to the export command as JSON")]
5556
input: String,
5657
},
58+
59+
#[clap(name = "export-bubble", about = "Export properties that DSC will bubble up")]
60+
ExportBubble,
61+
5762
#[clap(name = "exporter", about = "Exports different types of resources")]
5863
Exporter {
5964
#[clap(name = "input", short, long, help = "The input to the exporter command as JSON")]

tools/dsctest/src/main.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ fn main() {
100100
}
101101
String::new()
102102
},
103+
SubCommand::ExportBubble => {
104+
let mut properties = Map::new();
105+
properties.insert("_kind".to_string(), serde_json::Value::String("TestKind".to_string()));
106+
properties.insert("_name".to_string(), serde_json::Value::String("TestName".to_string()));
107+
properties.insert("_securityContext".to_string(), serde_json::Value::String("TestSecurityContext".to_string()));
108+
serde_json::to_string(&properties).unwrap()
109+
},
103110
SubCommand::Exporter { input } => {
104111
let exporter = match serde_json::from_str::<Exporter>(&input) {
105112
Ok(exporter) => exporter,
@@ -137,6 +144,9 @@ fn main() {
137144
Schemas::Export => {
138145
schema_for!(Export)
139146
},
147+
Schemas::ExportBubble => {
148+
schema_for!(Resource)
149+
},
140150
Schemas::Exporter => {
141151
schema_for!(Exporter)
142152
},

0 commit comments

Comments
 (0)