Skip to content

Commit ff492c8

Browse files
authored
Merge branch 'PowerShell:main' into main
2 parents 3f42f5d + 3ea98ff commit ff492c8

File tree

12 files changed

+102
-7
lines changed

12 files changed

+102
-7
lines changed

build.ps1

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,6 @@ if ($null -ne $packageType) {
112112
}
113113
}
114114

115-
if ($IsLinux -and (Test-Path /etc/mariner-release)) {
116-
tdnf install -y openssl-devel
117-
}
118-
119115
$BuildToolsPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC"
120116

121117
& $rustup default stable

dsc/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ dsc_lib = { path = "../dsc_lib" }
2020
indicatif = { version = "0.17" }
2121
jsonschema = "0.18"
2222
path-absolutize = { version = "3.1.1" }
23+
reqwest = { version = "0.12", features = ["rustls-tls"], default-features = false }
2324
schemars = { version = "0.8.12" }
2425
serde = { version = "1.0", features = ["derive"] }
2526
serde_json = { version = "1.0", features = ["preserve_order"] }

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_list.tests.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,10 @@ Describe 'Tests for listing resources' {
6666
$resource.capabilities | Should -Contain 'Get'
6767
$resource.capabilities | Should -Contain 'Export'
6868
}
69+
70+
It 'Invalid adapter returns an error' {
71+
$out = dsc resource list --adapter 'foo*' 2>&1 | Out-String
72+
$LASTEXITCODE | Should -Be 0
73+
$out | Should -BeLike "*ERROR*Adapter 'foo`*' not found*"
74+
}
6975
}

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+
}

dsc_lib/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ base64 = "0.22"
88
chrono = { version = "0.4.26" }
99
derive_builder ="0.20"
1010
indicatif = { version = "0.17" }
11-
jsonschema = "0.17"
11+
jsonschema = "0.18"
1212
num-traits = "0.2"
1313
regex = "1.7"
14+
reqwest = { version = "0.12", features = ["rustls-tls"], default-features = false }
1415
schemars = { version = "0.8.12", features = ["preserve_order"] }
1516
serde = { version = "1.0", features = ["derive"] }
1617
serde_json = { version = "1.0", features = ["preserve_order"] }

dsc_lib/src/discovery/command_discovery.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,14 @@ impl ResourceDiscovery for CommandDiscovery {
204204

205205
let mut adapted_resources = BTreeMap::<String, Vec<DscResource>>::new();
206206

207+
let mut found_adapter: bool = false;
207208
for (adapter_name, adapters) in &self.adapters {
208209
for adapter in adapters {
209210
if !regex.is_match(adapter_name) {
210211
continue;
211212
}
212213

214+
found_adapter = true;
213215
info!("Enumerating resources for adapter '{}'", adapter_name);
214216
let pb_adapter_span = warn_span!("");
215217
pb_adapter_span.pb_set_style(&ProgressStyle::with_template(
@@ -272,6 +274,10 @@ impl ResourceDiscovery for CommandDiscovery {
272274
}
273275
}
274276

277+
if !found_adapter {
278+
return Err(DscError::AdapterNotFound(adapter_filter.to_string()));
279+
}
280+
275281
self.adapted_resources = adapted_resources;
276282
Ok(())
277283
}

dsc_lib/src/dscerror.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ use tree_sitter::LanguageError;
1010

1111
#[derive(Error, Debug)]
1212
pub enum DscError {
13+
#[error("Adapter '{0}' not found")]
14+
AdapterNotFound(String),
15+
1316
#[error("Function boolean argument conversion error: {0}")]
1417
BooleanConversion(#[from] std::str::ParseBoolError),
1518

powershell-adapter/Tests/TestClassResource/0.0.1/TestClassResource.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ VariablesToExport = @()
3434
AliasesToExport = @()
3535

3636
# DSC resources to export from this module
37-
DscResourcesToExport = 'TestClassResource'
37+
DscResourcesToExport = @('TestClassResource', 'NoExport')
3838

3939
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
4040
PrivateData = @{

powershell-adapter/Tests/TestClassResource/0.0.1/TestClassResource.psm1

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,33 @@ class TestClassResource : BaseTestClass
7474
}
7575
}
7676

77+
[DscResource()]
78+
class NoExport: BaseTestClass
79+
{
80+
[DscProperty(Key)]
81+
[string] $Name
82+
83+
[DscProperty()]
84+
[string] $Prop1
85+
86+
[DscProperty()]
87+
[string] $EnumProp
88+
89+
[void] Set()
90+
{
91+
}
92+
93+
[bool] Test()
94+
{
95+
return $true
96+
}
97+
98+
[NoExport] Get()
99+
{
100+
return $this
101+
}
102+
}
103+
77104
function Test-World()
78105
{
79106
"Hello world from PSTestModule!"

0 commit comments

Comments
 (0)