Skip to content

Commit 3049f4a

Browse files
authored
Merge pull request #504 from SteveL-MSFT/test-empty
Add error if input to `dsc resource test` is empty
2 parents 4a5aa3a + da402c8 commit 3049f4a

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

dsc/src/resource_command.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub fn get_all(dsc: &DscManager, resource_type: &str, format: &Option<OutputForm
9696

9797
pub fn set(dsc: &DscManager, resource_type: &str, mut input: String, format: &Option<OutputFormat>) {
9898
if input.is_empty() {
99-
error!("Error: Input is empty");
99+
error!("Error: Desired input is empty");
100100
exit(EXIT_INVALID_ARGS);
101101
}
102102

@@ -137,6 +137,11 @@ pub fn set(dsc: &DscManager, resource_type: &str, mut input: String, format: &Op
137137
}
138138

139139
pub fn test(dsc: &DscManager, resource_type: &str, mut input: String, format: &Option<OutputFormat>) {
140+
if input.is_empty() {
141+
error!("Error: Expected input is required");
142+
exit(EXIT_INVALID_ARGS);
143+
}
144+
140145
let Some(mut resource) = get_resource(dsc, resource_type) else {
141146
error!("{}", DscError::ResourceNotFound(resource_type.to_string()).to_string());
142147
return

dsc/tests/dsc_resource_test.tests.ps1

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
Describe 'Invoke a resource test directly' {
5+
It 'test can be called on a resource' {
6+
$os = if ($IsWindows) {
7+
'Windows'
8+
} elseif ($IsLinux) {
9+
'Linux'
10+
} elseif ($IsMacOS) {
11+
'macOS'
12+
} else {
13+
'Unknown'
14+
}
15+
16+
$out = @"
17+
{ "family": "$os" }
18+
"@ | dsc resource test -r Microsoft/OSInfo | ConvertFrom-Json
19+
$LASTEXITCODE | Should -Be 0
20+
$out.actualState.family | Should -BeExactly $os
21+
$out.inDesiredState | Should -Be $true
22+
}
23+
24+
It 'test returns proper error code if no input is provded' {
25+
$out = dsc resource test -r Microsoft/OSInfo 2>&1
26+
$LASTEXITCODE | Should -Be 1
27+
$out | Should -BeLike '*ERROR*'
28+
}
29+
}

0 commit comments

Comments
 (0)