Skip to content

Commit 43d58cc

Browse files
author
Steve Lee (POWERSHELL HE/HIM) (from Dev Box)
committed
update test to not use osinfo since that explicitly supports export now
1 parent 8349d69 commit 43d58cc

File tree

2 files changed

+34
-29
lines changed

2 files changed

+34
-29
lines changed

dsc/tests/dsc_export.tests.ps1

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -203,20 +203,14 @@ resources:
203203
$yaml = @'
204204
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
205205
resources:
206-
- name: OS
207-
type: Microsoft/OSInfo
206+
- name: NoFilter
207+
type: Test/Get
208208
'@
209209
$out = dsc config export -i $yaml | ConvertFrom-Json
210210
$LASTEXITCODE | Should -Be 0
211211
$out.resources.count | Should -Be 1
212-
$out.resources[0].type | Should -BeExactly 'Microsoft/OSInfo'
213-
$expectedOs = if ($IsWindows) {
214-
'Windows'
215-
} elseif ($IsMacOS) {
216-
'macOS'
217-
} else {
218-
'Linux'
219-
}
220-
$out.resources[0].properties.family | Should -BeExactly $expectedOs
212+
$out.resources[0].type | Should -BeExactly 'Test/Get'
213+
$out.resources[0].properties.name | Should -BeExactly 'one'
214+
$out.resources[0].properties.id | Should -Be 1
221215
}
222216
}

tools/dsctest/src/main.rs

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,6 @@ fn main() {
116116
String::new()
117117
},
118118
SubCommand::Get { input } => {
119-
let get = match serde_json::from_str::<Get>(&input) {
120-
Ok(get) => get,
121-
Err(err) => {
122-
eprintln!("Error JSON does not match schema: {err}");
123-
std::process::exit(1);
124-
}
125-
};
126119
let instances = vec![
127120
Get {
128121
name : Some("one".to_string()),
@@ -137,20 +130,38 @@ fn main() {
137130
id: Some(3),
138131
},
139132
];
140-
// depending on the input, return the appropriate instance whether it is name or id or both
141-
let resource = if let Some(name) = get.name {
142-
instances.into_iter().find(|i| i.name.as_ref() == Some(&name)).unwrap_or_else(|| {
143-
eprintln!("No instance found with name: {name}");
144-
std::process::exit(1);
145-
})
146-
} else if let Some(id) = get.id {
147-
instances.into_iter().find(|i| i.id == Some(id)).unwrap_or_else(|| {
148-
eprintln!("No instance found with id: {id}");
133+
134+
let resource = if input.is_empty() {
135+
// If neither name nor id is provided, return the first instance
136+
instances.into_iter().next().unwrap_or_else(|| {
137+
eprintln!("No instances found");
149138
std::process::exit(1);
150139
})
151140
} else {
152-
eprintln!("No name or id provided in input");
153-
std::process::exit(1);
141+
let get = match serde_json::from_str::<Get>(&input) {
142+
Ok(get) => get,
143+
Err(err) => {
144+
eprintln!("Error JSON does not match schema: {err}");
145+
std::process::exit(1);
146+
}
147+
};
148+
// depending on the input, return the appropriate instance whether it is name or id or both
149+
if let Some(name) = get.name {
150+
instances.into_iter().find(|i| i.name.as_ref() == Some(&name)).unwrap_or_else(|| {
151+
eprintln!("No instance found with name: {name}");
152+
std::process::exit(1);
153+
})
154+
} else if let Some(id) = get.id {
155+
instances.into_iter().find(|i| i.id == Some(id)).unwrap_or_else(|| {
156+
eprintln!("No instance found with id: {id}");
157+
std::process::exit(1);
158+
})
159+
} else {
160+
instances.into_iter().next().unwrap_or_else(|| {
161+
eprintln!("No instances found");
162+
std::process::exit(1);
163+
})
164+
}
154165
};
155166
serde_json::to_string(&resource).unwrap()
156167
},

0 commit comments

Comments
 (0)