Skip to content

Commit e8e7cdc

Browse files
authoredFeb 26, 2025
Merge pull request #660 from SteveL-MSFT/backport-progress-json
Backport: progress json updates
2 parents 765c8c4 + 13419d6 commit e8e7cdc

File tree

26 files changed

+857
-869
lines changed

26 files changed

+857
-869
lines changed
 

‎dsc/Cargo.lock

+77-85
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dsc/src/args.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use clap::{Parser, Subcommand, ValueEnum};
55
use clap_complete::Shell;
66
use dsc_lib::dscresources::command_resource::TraceLevel;
7-
use dsc_lib::util::ProgressFormat;
7+
use dsc_lib::progress::ProgressFormat;
88
use rust_i18n::t;
99
use serde::Deserialize;
1010

‎dsc/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rust_i18n::{i18n, t};
88
use std::{io, process::exit};
99
use sysinfo::{Process, RefreshKind, System, get_current_pid, ProcessRefreshKind};
1010
use tracing::{error, info, warn, debug};
11-
use dsc_lib::util::ProgressFormat;
11+
use dsc_lib::progress::ProgressFormat;
1212

1313
#[cfg(debug_assertions)]
1414
use crossterm::event;

‎dsc/src/subcommand.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use dsc_lib::{
2525
},
2626
dscresources::dscresource::{Capability, ImplementedAs, Invoke},
2727
dscresources::resource_manifest::{import_manifest, ResourceManifest},
28-
util::ProgressFormat,
28+
progress::ProgressFormat,
2929
};
3030
use rust_i18n::t;
3131
use std::{
@@ -288,16 +288,14 @@ pub fn config(subcommand: &ConfigSubCommand, parameters: &Option<String>, mounte
288288
}
289289
};
290290

291-
let mut configurator = match Configurator::new(&json_string) {
291+
let mut configurator = match Configurator::new(&json_string, progress_format) {
292292
Ok(configurator) => configurator,
293293
Err(err) => {
294294
error!("Error: {err}");
295295
exit(EXIT_DSC_ERROR);
296296
}
297297
};
298298

299-
configurator.set_progress_format(progress_format);
300-
301299
if let ConfigSubCommand::Set { what_if , .. } = subcommand {
302300
if *what_if {
303301
configurator.context.execution_type = ExecutionKind::WhatIf;

‎dsc/tests/dsc_args.tests.ps1

+6
Original file line numberDiff line numberDiff line change
@@ -293,4 +293,10 @@ resources:
293293
$LASTEXITCODE | Should -Be 1
294294
"$TestDrive/tracing.txt" | Should -FileContentMatchExactly "Target path does not exist: '/invalid/path'"
295295
}
296+
297+
It '--progress-format can be None' {
298+
dsc -p none resource list 2> $TestDrive/tracing.txt
299+
$LASTEXITCODE | Should -Be 0
300+
(Get-Content $TestDrive/tracing.txt -Raw) | Should -BeNullOrEmpty
301+
}
296302
}

‎dsc/tests/dsc_config_get.tests.ps1

+73-4
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,92 @@ Describe 'dsc config get tests' {
6060
$config_yaml = @"
6161
`$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
6262
resources:
63-
- name: Echo
63+
- name: Echo 1
6464
type: Microsoft.DSC.Debug/Echo
6565
properties:
6666
output: hello
67+
- name: Echo 2
68+
type: Microsoft.DSC.Debug/Echo
69+
properties:
70+
output: world
6771
"@
6872
$config_yaml | dsc --progress-format json config get -f - 2> $TestDrive/ErrorStream.txt
6973
$LASTEXITCODE | Should -Be 0
7074
$lines = Get-Content $TestDrive/ErrorStream.txt
71-
$ProgressMessagesFound = $False
75+
$ProgressMessagesFound = $false
76+
$InstanceOneFound = $false
77+
$InstanceTwoFound = $false
7278
foreach ($line in $lines) {
7379
$jp = $line | ConvertFrom-Json
7480
if ($jp.activity) { # if line is a progress message
75-
$jp.percent_complete | Should -BeIn (0..100)
76-
$ProgressMessagesFound = $True
81+
$jp.id | Should -Not -BeNullOrEmpty
82+
$jp.totalItems | Should -Not -BeNullOrEmpty
83+
$jp.completedItems | Should -Not -BeNullOrEmpty
84+
$ProgressMessagesFound = $true
85+
}
86+
87+
if ($null -ne $jp.result -and $jp.resourceType -eq 'Microsoft.DSC.Debug/Echo') {
88+
if ($jp.resourceName -eq 'Echo 1') {
89+
$InstanceOneFound = $true
90+
$jp.result.actualState.output | Should -BeExactly 'hello'
91+
} elseif ($jp.resourceName -eq 'Echo 2') {
92+
$InstanceTwoFound = $true
93+
$jp.result.actualState.output | Should -BeExactly 'world'
94+
}
95+
}
96+
}
97+
$ProgressMessagesFound | Should -BeTrue
98+
$InstanceOneFound | Should -BeTrue
99+
$InstanceTwoFound | Should -BeTrue
100+
}
101+
102+
It 'json progress returns correctly for failed resource' {
103+
$config_yaml = @'
104+
$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
105+
resources:
106+
- name: Echo 1
107+
type: Microsoft.DSC.Debug/Echo
108+
properties:
109+
output: hello
110+
- name: ErrorTest
111+
type: Test/ExitCode
112+
properties:
113+
exitCode: 8
114+
'@
115+
dsc --progress-format json --trace-format json config get -i $config_yaml 2> $TestDrive/ErrorStream.txt
116+
$LASTEXITCODE | Should -Be 2
117+
$lines = Get-Content $TestDrive/ErrorStream.txt
118+
$ProgressMessagesFound = $false
119+
$InstanceOneFound = $false
120+
$InstanceTwoFound = $false
121+
foreach ($line in $lines) {
122+
$jp = $line | ConvertFrom-Json
123+
if ($jp.activity) { # if line is a progress message
124+
$jp.id | Should -Not -BeNullOrEmpty
125+
$jp.totalItems | Should -Not -BeNullOrEmpty
126+
$jp.completedItems | Should -Not -BeNullOrEmpty
127+
$ProgressMessagesFound = $true
128+
}
129+
130+
if ($null -ne $jp.result -and $jp.resourceType -eq 'Microsoft.DSC.Debug/Echo') {
131+
if ($jp.resourceName -eq 'Echo 1') {
132+
$InstanceOneFound = $true
133+
$jp.result.actualState.output | Should -BeExactly 'hello'
134+
$jp.failed | Should -BeNullOrEmpty
135+
}
136+
}
137+
elseif ($null -ne $jp.failure -and $jp.resourceType -eq 'Test/ExitCode') {
138+
if ($jp.resourceName -eq 'ErrorTest') {
139+
$InstanceTwoFound = $true
140+
$jp.result | Should -BeNullOrEmpty
141+
$jp.failure.exitCode | Should -Be 8
142+
$jp.failure.message | Should -Not -BeNullOrEmpty
143+
}
77144
}
78145
}
79146
$ProgressMessagesFound | Should -BeTrue
147+
$InstanceOneFound | Should -BeTrue
148+
$InstanceTwoFound | Should -BeTrue
80149
}
81150

82151
It 'contentVersion is ignored' {

‎dsc/tests/dsc_resource_list.tests.ps1

+3-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ Describe 'Tests for listing resources' {
6666
foreach ($line in $lines) {
6767
$jp = $line | ConvertFrom-Json
6868
if ($jp.activity) { # if line is a progress message
69-
$jp.percent_complete | Should -BeIn (0..100)
69+
$jp.id | Should -Not -BeNullOrEmpty
70+
$jp.totalItems | Should -Not -BeNullOrEmpty
71+
$jp.completedItems | Should -Not -BeNullOrEmpty
7072
$ProgressMessagesFound = $True
7173
}
7274
}

0 commit comments

Comments
 (0)