@@ -5,7 +5,7 @@ use crate::args::{ConfigSubCommand, DscType, OutputFormat, ResourceSubCommand};
55use crate :: resolve:: { get_contents, Include } ;
66use crate :: resource_command:: { get_resource, self } ;
77use crate :: tablewriter:: Table ;
8- use crate :: util:: { DSC_CONFIG_ROOT , EXIT_DSC_ERROR , EXIT_INVALID_ARGS , EXIT_INVALID_INPUT , EXIT_JSON_ERROR , get_schema, write_output, get_input, set_dscconfigroot, validate_json} ;
8+ use crate :: util:: { DSC_CONFIG_ROOT , EXIT_DSC_ERROR , EXIT_DSC_ASSERTION_FAILED , EXIT_INVALID_ARGS , EXIT_INVALID_INPUT , EXIT_JSON_ERROR , get_schema, write_output, get_input, in_desired_state , set_dscconfigroot, validate_json} ;
99use dsc_lib:: {
1010 configure:: {
1111 config_doc:: {
@@ -106,7 +106,7 @@ pub fn config_set(configurator: &mut Configurator, format: Option<&OutputFormat>
106106 }
107107}
108108
109- pub fn config_test ( configurator : & mut Configurator , format : Option < & OutputFormat > , as_group : & bool , as_get : & bool , as_config : & bool )
109+ pub fn config_test ( configurator : & mut Configurator , format : Option < & OutputFormat > , as_group : & bool , as_get : & bool , as_config : & bool , as_assert : & bool )
110110{
111111 match configurator. invoke_test ( ) {
112112 Ok ( result) => {
@@ -115,6 +115,10 @@ pub fn config_test(configurator: &mut Configurator, format: Option<&OutputFormat
115115 let mut result_configuration = Configuration :: new ( ) ;
116116 result_configuration. resources = Vec :: new ( ) ;
117117 for test_result in result. results {
118+ if * as_assert && !in_desired_state ( & test_result) {
119+ error ! ( "{}" , t!( "subcommand.assertionFailed" , resource_type = test_result. resource_type) ) ;
120+ exit ( EXIT_DSC_ASSERTION_FAILED ) ;
121+ }
118122 let properties = match test_result. result {
119123 TestResult :: Resource ( test_response) => {
120124 if test_response. actual_state . is_object ( ) {
@@ -150,6 +154,10 @@ pub fn config_test(configurator: &mut Configurator, format: Option<&OutputFormat
150154 else if * as_get {
151155 let mut group_result = Vec :: < ResourceGetResult > :: new ( ) ;
152156 for test_result in result. results {
157+ if * as_assert && !in_desired_state ( & test_result) {
158+ error ! ( "{}" , t!( "subcommand.assertionFailed" , resource_type = test_result. resource_type) ) ;
159+ exit ( EXIT_DSC_ASSERTION_FAILED ) ;
160+ }
153161 group_result. push ( test_result. into ( ) ) ;
154162 }
155163 match serde_json:: to_string ( & group_result) {
@@ -161,6 +169,14 @@ pub fn config_test(configurator: &mut Configurator, format: Option<&OutputFormat
161169 }
162170 }
163171 else {
172+ if * as_assert {
173+ for test_result in & result. results {
174+ if !in_desired_state ( test_result) {
175+ error ! ( "{}" , t!( "subcommand.assertionFailed" , resource_type = test_result. resource_type) ) ;
176+ exit ( EXIT_DSC_ASSERTION_FAILED ) ;
177+ }
178+ }
179+ }
164180 match serde_json:: to_string ( & ( result. results ) ) {
165181 Ok ( json) => json,
166182 Err ( err) => {
@@ -252,7 +268,7 @@ fn initialize_config_root(path: Option<&String>) -> Option<String> {
252268}
253269
254270#[ allow( clippy:: too_many_lines) ]
255- pub fn config ( subcommand : & ConfigSubCommand , parameters : & Option < String > , mounted_path : Option < & String > , as_group : & bool , as_include : & bool , progress_format : ProgressFormat ) {
271+ pub fn config ( subcommand : & ConfigSubCommand , parameters : & Option < String > , mounted_path : Option < & String > , as_group : & bool , as_assert : & bool , as_include : & bool , progress_format : ProgressFormat ) {
256272 let ( new_parameters, json_string) = match subcommand {
257273 ConfigSubCommand :: Get { input, file, .. } |
258274 ConfigSubCommand :: Set { input, file, .. } |
@@ -363,7 +379,7 @@ pub fn config(subcommand: &ConfigSubCommand, parameters: &Option<String>, mounte
363379 config_set ( & mut configurator, output_format. as_ref ( ) , as_group) ;
364380 } ,
365381 ConfigSubCommand :: Test { output_format, as_get, as_config, .. } => {
366- config_test ( & mut configurator, output_format. as_ref ( ) , as_group, as_get, as_config) ;
382+ config_test ( & mut configurator, output_format. as_ref ( ) , as_group, as_get, as_config, as_assert ) ;
367383 } ,
368384 ConfigSubCommand :: Validate { input, file, output_format} => {
369385 let mut result = ValidateResult {
0 commit comments