(configurator: &mut Configurator, format: Option<&OutputFormat>, as_group: &bool, as_get: &bool, as_config: &bool, as_assert: &bool)
| 115 | } |
| 116 | |
| 117 | pub fn config_test(configurator: &mut Configurator, format: Option<&OutputFormat>, as_group: &bool, as_get: &bool, as_config: &bool, as_assert: &bool) |
| 118 | { |
| 119 | match configurator.invoke_test() { |
| 120 | Ok(result) => { |
| 121 | if *as_group { |
| 122 | let json = if *as_config { |
| 123 | let mut result_configuration = Configuration::new(); |
| 124 | result_configuration.resources = Vec::new(); |
| 125 | for test_result in result.results { |
| 126 | if *as_assert && !in_desired_state(&test_result) { |
| 127 | error!("{}", t!("subcommand.assertionFailed", resource_type = test_result.resource_type)); |
| 128 | exit(EXIT_DSC_ASSERTION_FAILED); |
| 129 | } |
| 130 | let properties = match test_result.result { |
| 131 | TestResult::Resource(test_response) => { |
| 132 | if test_response.actual_state.is_object() { |
| 133 | test_response.actual_state.as_object().cloned() |
| 134 | } else { |
| 135 | debug!("{}", t!("subcommand.actualStateNotObject")); |
| 136 | None |
| 137 | } |
| 138 | }, |
| 139 | TestResult::Group(_) => { |
| 140 | // not expected |
| 141 | debug!("{}", t!("subcommand.unexpectedTestResult")); |
| 142 | None |
| 143 | } |
| 144 | }; |
| 145 | let resource = Resource { |
| 146 | name: test_result.name, |
| 147 | resource_type: test_result.resource_type, |
| 148 | properties, |
| 149 | ..Default::default() |
| 150 | }; |
| 151 | result_configuration.resources.push(resource); |
| 152 | } |
| 153 | match serde_json::to_string(&result_configuration) { |
| 154 | Ok(json) => json, |
| 155 | Err(err) => { |
| 156 | error!("JSON: {err}"); |
| 157 | exit(EXIT_JSON_ERROR); |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | else if *as_get { |
| 162 | let mut group_result = Vec::<ResourceGetResult>::new(); |
| 163 | for test_result in result.results { |
| 164 | if *as_assert && !in_desired_state(&test_result) { |
| 165 | error!("{}", t!("subcommand.assertionFailed", resource_type = test_result.resource_type)); |
| 166 | exit(EXIT_DSC_ASSERTION_FAILED); |
| 167 | } |
| 168 | group_result.push(test_result.into()); |
| 169 | } |
| 170 | match serde_json::to_string(&group_result) { |
| 171 | Ok(json) => json, |
| 172 | Err(err) => { |
| 173 | error!("JSON: {err}"); |
| 174 | exit(EXIT_JSON_ERROR); |
no test coverage detected