diff --git a/dsc/src/args.rs b/dsc/src/args.rs index 9f4cd7be..94ac07ee 100644 --- a/dsc/src/args.rs +++ b/dsc/src/args.rs @@ -103,7 +103,7 @@ pub enum ConfigSubCommand { #[clap(long, hide = true)] as_get: bool, #[clap(long, hide = true)] - as_test: bool, + as_config: bool, }, #[clap(name = "validate", about = "Validate the current configuration", hide = true)] Validate { diff --git a/dsc/src/subcommand.rs b/dsc/src/subcommand.rs index 65cf5057..66f0ad7a 100644 --- a/dsc/src/subcommand.rs +++ b/dsc/src/subcommand.rs @@ -101,12 +101,12 @@ pub fn config_set(configurator: &mut Configurator, format: &Option } } -pub fn config_test(configurator: &mut Configurator, format: &Option, as_group: &bool, as_get: &bool, as_test: &bool) +pub fn config_test(configurator: &mut Configurator, format: &Option, as_group: &bool, as_get: &bool, as_config: &bool) { match configurator.invoke_test() { Ok(result) => { if *as_group { - let json = if *as_test { + let json = if *as_config { let mut result_configuration = Configuration::new(); result_configuration.resources = Vec::new(); for test_result in result.results { @@ -329,8 +329,8 @@ pub fn config(subcommand: &ConfigSubCommand, parameters: &Option, stdin: ConfigSubCommand::Set { format, .. } => { config_set(&mut configurator, format, as_group); }, - ConfigSubCommand::Test { format, as_get, as_test, .. } => { - config_test(&mut configurator, format, as_group, as_get, as_test); + ConfigSubCommand::Test { format, as_get, as_config, .. } => { + config_test(&mut configurator, format, as_group, as_get, as_config); }, ConfigSubCommand::Validate { document, path, format} => { let mut result = ValidateResult { diff --git a/dsc_lib/src/dscresources/dscresource.rs b/dsc_lib/src/dscresources/dscresource.rs index 4b876b37..f82f9bf3 100644 --- a/dsc_lib/src/dscresources/dscresource.rs +++ b/dsc_lib/src/dscresources/dscresource.rs @@ -467,10 +467,74 @@ fn array_contains(array: &Vec, find: &Value) -> bool { } } - if find.is_array() && item.is_array() && array_contains(item.as_array().unwrap(), find) { + if find.is_array() && item.is_array() && is_same_array(item.as_array().unwrap(), find.as_array().unwrap()) { return true; } } false } + +#[test] +fn same_array() { + use serde_json::json; + let array_one = vec![json!("a"), json!(1), json!(r#"{"a":"b"}"#), json!(null)]; + let array_two = vec![json!("a"), json!(1), json!(r#"{"a":"b"}"#), json!(null)]; + assert_eq!(is_same_array(&array_one, &array_two), true); +} + +#[test] +fn same_array_out_of_order() { + use serde_json::json; + let array_one = vec![json!("a"), json!(true), json!(r#"{"a":"b"}"#)]; + let array_two = vec![json!(r#"{"a":"b"}"#), json!("a"), json!(true)]; + assert_eq!(is_same_array(&array_one, &array_two), true); +} + +#[test] +fn different_array() { + use serde_json::json; + let array_one = vec![json!("a"), json!(1), json!(r#"{"a":"b"}"#)]; + let array_two = vec![json!(r#"{"a":"b"}"#), json!("a"), json!(2)]; + assert_eq!(is_same_array(&array_one, &array_two), false); +} + +#[test] +fn different_array_sizes() { + use serde_json::json; + let array_one = vec![json!("a"), json!(1), json!(r#"{"a":"b"}"#)]; + let array_two = vec![json!(r#"{"a":"b"}"#), json!("a")]; + assert_eq!(is_same_array(&array_one, &array_two), false); +} + +#[test] +fn array_with_multiple_objects_with_superset() { + use serde_json::json; + let array_one = vec![json!("a"), json!(1), json!(r#"{"a":"b"}"#), json!(r#"{"c":"d"}"#)]; + let array_two = vec![json!("a"), json!(1), json!(r#"{"a":"b", "c":"d"}"#), json!(r#"{"c":"d"}"#)]; + assert_eq!(is_same_array(&array_one, &array_two), false); +} + +#[test] +fn array_with_duplicates_out_of_order() { + use serde_json::json; + let array_one = vec![json!("a"), json!(1), json!(r#"{"a":"b"}"#), json!(r#"{"a":"b"}"#)]; + let array_two = vec![json!(r#"{"a":"b"}"#), json!("a"), json!(1), json!(r#"{"a":"b"}"#)]; + assert_eq!(is_same_array(&array_one, &array_two), true); +} + +#[test] +fn same_array_with_nested_array() { + use serde_json::json; + let array_one = vec![json!("a"), json!(1), json!(r#"{"a":"b"}"#), json!(vec![json!("a"), json!(1)])]; + let array_two = vec![json!("a"), json!(1), json!(r#"{"a":"b"}"#), json!(vec![json!("a"), json!(1)])]; + assert_eq!(is_same_array(&array_one, &array_two), true); +} + +#[test] +fn different_array_with_nested_array() { + use serde_json::json; + let array_one = vec![json!("a"), json!(1), json!(r#"{"a":"b"}"#), json!(vec![json!("a"), json!(1)])]; + let array_two = vec![json!("a"), json!(1), json!(r#"{"a":"b"}"#), json!(vec![json!("a"), json!(2)])]; + assert_eq!(is_same_array(&array_one, &array_two), false); +}