Skip to content

Commit 6dc4d40

Browse files
committed
add tests
1 parent ffa3ceb commit 6dc4d40

File tree

5 files changed

+55
-11
lines changed

5 files changed

+55
-11
lines changed

dsc/examples/hello_world.dsc.bicep

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ resource echo 'Microsoft.DSC.Debug/Echo@2025-08-27' = {
1010
}
1111
}
1212

13-
output exampleOutput string = echo.properties.output
13+
// This is waiting on https://github.com/Azure/bicep/issues/17670 to be resolved
14+
// output exampleOutput string = echo.properties.output

dsc/tests/dsc_osinfo.tests.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
14
Describe 'Tests for osinfo examples' {
25
It 'Config with default parameters and get works' {
36
$out = dsc config get -f $PSScriptRoot/../examples/osinfo_parameters.dsc.yaml | ConvertFrom-Json -Depth 10

dsc/tests/dsc_output.tests.ps1

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
Describe 'output tests' {
5+
It 'config with output property works' {
6+
$configYaml = @'
7+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
8+
variables:
9+
arrayVar:
10+
- 1
11+
- 2
12+
- 3
13+
resources:
14+
- name: echo
15+
type: Microsoft.DSC.Debug/Echo
16+
properties:
17+
output: This is a test
18+
outputs:
19+
simpleText:
20+
type: string
21+
value: Hello World
22+
expression:
23+
type: string
24+
value: "[reference(resourceId('Microsoft.DSC.Debug/Echo', 'echo')).output]"
25+
conditionSucceed:
26+
type: int
27+
condition: "[equals(1, 1)]"
28+
value: "[variables('arrayVar')[1]]"
29+
conditionFail:
30+
type: int
31+
condition: "[equals(1, 2)]"
32+
value: "[variables('arrayVar')[1]]"
33+
'@
34+
$out = dsc config get -i $configYaml | ConvertFrom-Json -Depth 10
35+
$LASTEXITCODE | Should -Be 0
36+
$out.outputs.simpleText | Should -Be 'Hello World'
37+
$out.outputs.expression | Should -Be 'This is a test'
38+
$out.outputs.conditionSucceed | Should -Be 2
39+
$out.outputs.conditionFail | Should -BeNullOrEmpty
40+
}
41+
}

lib/dsc-lib/src/configure/config_doc.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use schemars::{JsonSchema, json_schema};
77
use serde::{Deserialize, Serialize};
88
use serde_json::{Map, Value};
99
use std::{collections::HashMap, fmt::Display};
10-
use std::fmt::Display;
1110

1211
use crate::{dscerror::DscError, schemas::DscRepoSchema};
1312

@@ -131,7 +130,7 @@ pub struct UserFunctionOutput {
131130
}
132131

133132
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]
134-
#[serde(untagged)]
133+
#[serde(rename_all = "camelCase")]
135134
pub enum ValueOrCopy {
136135
Value(String),
137136
Copy(Copy),
@@ -142,6 +141,7 @@ pub enum ValueOrCopy {
142141
pub struct Output {
143142
pub condition: Option<String>,
144143
pub r#type: DataType,
144+
#[serde(flatten)]
145145
pub value_or_copy: ValueOrCopy,
146146
}
147147

@@ -156,14 +156,14 @@ pub struct Configuration {
156156
#[serde(skip_serializing_if = "Option::is_none")]
157157
pub functions: Option<Vec<UserFunction>>,
158158
#[serde(skip_serializing_if = "Option::is_none")]
159-
pub parameters: Option<HashMap<String, Parameter>>,
160-
#[serde(skip_serializing_if = "Option::is_none")]
161-
pub variables: Option<Map<String, Value>>,
162-
pub resources: Vec<Resource>,
163-
#[serde(skip_serializing_if = "Option::is_none")]
164159
pub metadata: Option<Metadata>,
165160
#[serde(skip_serializing_if = "Option::is_none")]
166161
pub outputs: Option<HashMap<String, Output>>,
162+
#[serde(skip_serializing_if = "Option::is_none")]
163+
pub parameters: Option<HashMap<String, Parameter>>,
164+
pub resources: Vec<Resource>,
165+
#[serde(skip_serializing_if = "Option::is_none")]
166+
pub variables: Option<Map<String, Value>>,
167167
}
168168

169169
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, JsonSchema)]

lib/dsc-lib/src/configure/context.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub struct Context {
2525
pub dsc_version: Option<String>,
2626
pub execution_type: ExecutionKind,
2727
pub extensions: Vec<DscExtension>,
28+
pub outputs: Map<String, Value>,
2829
pub parameters: HashMap<String, (Value, DataType)>,
2930
pub process_expressions: bool,
3031
pub process_mode: ProcessMode,
@@ -36,7 +37,6 @@ pub struct Context {
3637
pub system_root: PathBuf,
3738
pub user_functions: HashMap<String, UserFunctionDefinition>,
3839
pub variables: Map<String, Value>,
39-
pub outputs: Map<String, Value>,
4040
}
4141

4242
impl Context {
@@ -48,6 +48,7 @@ impl Context {
4848
dsc_version: None,
4949
execution_type: ExecutionKind::Actual,
5050
extensions: Vec::new(),
51+
outputs: Map::new(),
5152
parameters: HashMap::new(),
5253
process_expressions: true,
5354
process_mode: ProcessMode::Normal,
@@ -62,8 +63,6 @@ impl Context {
6263
system_root: get_default_os_system_root(),
6364
user_functions: HashMap::new(),
6465
variables: Map::new(),
65-
restart_required: None,
66-
outputs: Map::new(),
6766
}
6867
}
6968
}

0 commit comments

Comments
 (0)