Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error if input to dsc resource test is empty #504

Merged
merged 2 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion dsc/src/resource_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub fn get_all(dsc: &DscManager, resource_type: &str, format: &Option<OutputForm

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

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

pub fn test(dsc: &DscManager, resource_type: &str, mut input: String, format: &Option<OutputFormat>) {
if input.is_empty() {
error!("Error: Expected input is required");
exit(EXIT_INVALID_ARGS);
}

let Some(mut resource) = get_resource(dsc, resource_type) else {
error!("{}", DscError::ResourceNotFound(resource_type.to_string()).to_string());
return
Expand Down
29 changes: 29 additions & 0 deletions dsc/tests/dsc_resource_test.tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

Describe 'Invoke a resource test directly' {
It 'test can be called on a resource' {
$os = if ($IsWindows) {
'Windows'
} elseif ($IsLinux) {
'Linux'
} elseif ($IsMacOS) {
'macOS'
} else {
'Unknown'
}

$out = @"
{ "family": "$os" }
"@ | dsc resource test -r Microsoft/OSInfo | ConvertFrom-Json
$LASTEXITCODE | Should -Be 0
$out.actualState.family | Should -BeExactly $os
$out.inDesiredState | Should -Be $true
}

It 'test returns proper error code if no input is provded' {
$out = dsc resource test -r Microsoft/OSInfo 2>&1
$LASTEXITCODE | Should -Be 1
$out | Should -BeLike '*ERROR*'
}
}
Loading