From 8d8bf79c312ef96893613eefa52d3816f2e69e2f Mon Sep 17 00:00:00 2001 From: Ayodeji Ige Date: Tue, 12 Nov 2024 17:09:13 -0800 Subject: [PATCH] New env_not condition --- README.md | 1 + docs/_includes/content.md | 1 + src/lib/condition.rs | 38 +- src/lib/condition_test.rs | 649 ++++++++++++++++++ src/lib/environment/mod_test.rs | 6 + src/lib/plugin/runner_test.rs | 1 + .../cm_plugin_check_task_condition_test.rs | 1 + src/lib/runner_test.rs | 9 + src/lib/types.rs | 2 + src/lib/types_test.rs | 20 + 10 files changed, 721 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index d5b5804a..f3e6186a 100644 --- a/README.md +++ b/README.md @@ -1859,6 +1859,7 @@ The following condition types are available: * **env_false** - List of environment variables that must be defined and set to any of the following (case insensitive): false, no, 0 or empty * **env** - Map of environment variables that must be defined and equal to the provided values * **env_contains** - Map of environment variables that must be defined and contain (case insensitive) the provided values +* **env_not** - Map of environment variables that must not be equal to the provided values * **rust_version** - Optional definition of min, max, and/or specific rust version * **files_exist** - List of absolute path files to check they exist. Environment substitution is supported so you can define relative paths such as **`${CARGO_MAKE_WORKING_DIRECTORY}/Cargo.toml`** * **files_not_exist** - List of absolute path files to check they do not exist. Environment substitution is supported so you can define relative paths such as **`${CARGO_MAKE_WORKING_DIRECTORY}/Cargo.toml`** diff --git a/docs/_includes/content.md b/docs/_includes/content.md index 352ac455..d7f0bb4f 100755 --- a/docs/_includes/content.md +++ b/docs/_includes/content.md @@ -1720,6 +1720,7 @@ The following condition types are available: * **env_true** - List of environment variables that must be defined and must not be set to any of the following (case insensitive): false, no, 0 or empty * **env_false** - List of environment variables that must be defined and set to any of the following (case insensitive): false, no, 0 or empty * **env** - Map of environment variables that must be defined and equal to the provided values +* **env_not** - Map of environment variables that must not be equal to the provided values * **env_contains** - Map of environment variables that must be defined and contain (case insensitive) the provided values * **rust_version** - Optional definition of min, max, and/or specific rust version * **files_exist** - List of absolute path files to check they exist. Environment substitution is supported so you can define relative paths such as **`${CARGO_MAKE_WORKING_DIRECTORY}/Cargo.toml`** diff --git a/src/lib/condition.rs b/src/lib/condition.rs index 4b044582..2777a747 100755 --- a/src/lib/condition.rs +++ b/src/lib/condition.rs @@ -23,9 +23,19 @@ use indexmap::IndexMap; use rust_info::types::{RustChannel, RustInfo}; use std::path::Path; +/// Enum indicates what kind of env map we are validating. Used in `validate_env_map` function. +enum EnvMapType { + /// Validate map for `env` in `TaskCondition`. + Env, + /// Validate map for `env_contains` in `TaskCondition`. + EnvContains, + /// Validate map for `env_not` in `TaskCondition`. + EnvNot +} + fn validate_env_map( env: Option>, - equal: bool, + env_map_type: EnvMapType, validate_any: bool, ) -> bool { match env { @@ -33,10 +43,10 @@ fn validate_env_map( let mut found_any = env_vars.is_empty(); for (key, current_value) in env_vars.iter() { - let valid = if equal { - envmnt::is_equal(key, current_value) - } else { - envmnt::contains_ignore_case(key, current_value) + let valid = match env_map_type { + EnvMapType::Env => envmnt::is_equal(key, current_value), + EnvMapType::EnvContains => envmnt::contains_ignore_case(key, current_value), + EnvMapType::EnvNot => !envmnt::is_equal(key, current_value), }; if valid { @@ -57,13 +67,18 @@ fn validate_env_map( } fn validate_env(condition: &TaskCondition, validate_any: bool) -> bool { - validate_env_map(condition.env.clone(), true, validate_any) + validate_env_map(condition.env.clone(), EnvMapType::Env, validate_any) +} + +fn validate_env_not(condition: &TaskCondition, validate_any: bool) -> bool { + validate_env_map(condition.env_not.clone(), EnvMapType::EnvNot, validate_any) } fn validate_env_contains(condition: &TaskCondition, validate_any: bool) -> bool { - validate_env_map(condition.env_contains.clone(), false, validate_any) + validate_env_map(condition.env_contains.clone(), EnvMapType::EnvContains, validate_any) } + fn validate_env_set(condition: &TaskCondition, validate_any: bool) -> bool { let env = condition.env_set.clone(); match env { @@ -505,6 +520,15 @@ fn validate_criteria(flow_info: Option<&FlowInfo>, condition: &Option::new(); + env_values.insert("ENV_SET1".to_string(), "NotEmpty".to_string()); + env_values.insert("ENV_SET2".to_string(), "NotValue".to_string()); + + let condition = TaskCondition { + condition_type: None, + fail_message: None, + profiles: None, + os: None, + platforms: None, + channels: None, + env_set: None, + env_not_set: None, + env_true: None, + env_false: None, + env: None, + env_not: Some(env_values), + env_contains: None, + rust_version: None, + files_exist: None, + files_not_exist: None, + files_modified: None, + }; + + let enabled = validate_env_not(&condition, false); + + assert!(enabled); +} + +#[test] +#[ignore] +fn validate_env_not_valid_with_any() { + envmnt::set("ENV_SET1", ""); + envmnt::set("ENV_SET2", "value"); + envmnt::set("ENV_SET3", "anothervalue"); + + let mut env_values = IndexMap::::new(); + env_values.insert("ENV_SET1".to_string(), "NotEmpty".to_string()); + env_values.insert("ENV_SET2".to_string(), "value".to_string()); + env_values.insert("ENV_SET3".to_string(), "anothervalue".to_string()); + + let condition = TaskCondition { + condition_type: None, + fail_message: None, + profiles: None, + os: None, + platforms: None, + channels: None, + env_set: None, + env_not_set: None, + env_true: None, + env_false: None, + env: None, + env_not: Some(env_values), + env_contains: None, + rust_version: None, + files_exist: None, + files_not_exist: None, + files_modified: None, + }; + + let enabled = validate_env_not(&condition, true); + + assert!(enabled); +} + +#[test] +#[ignore] +fn validate_env_not_valid_not_found() { + let mut env_values = IndexMap::::new(); + env_values.insert("BAD_ENV_SET1".to_string(), "".to_string()); + env_values.insert("BAD_ENV_SET2".to_string(), "value".to_string()); + + let condition = TaskCondition { + condition_type: None, + fail_message: None, + profiles: None, + os: None, + platforms: None, + channels: None, + env_set: None, + env_not_set: None, + env_true: None, + env_false: None, + env: None, + env_not: Some(env_values), + env_contains: None, + rust_version: None, + files_exist: None, + files_not_exist: None, + files_modified: None, + }; + + let enabled = validate_env_not(&condition, false); + + assert!(enabled); +} + +#[test] +#[ignore] +fn validate_env_not_valid_not_found_with_any() { + let mut env_values = IndexMap::::new(); + env_values.insert("BAD_ENV_SET1".to_string(), "".to_string()); + env_values.insert("BAD_ENV_SET2".to_string(), "value".to_string()); + + let condition = TaskCondition { + condition_type: None, + fail_message: None, + profiles: None, + os: None, + platforms: None, + channels: None, + env_set: None, + env_not_set: None, + env_true: None, + env_false: None, + env: None, + env_not: Some(env_values), + env_contains: None, + rust_version: None, + files_exist: None, + files_not_exist: None, + files_modified: None, + }; + + let enabled = validate_env_not(&condition, true); + + assert!(enabled); +} + +#[test] +#[ignore] +fn validate_env_not_invalid_not_equal() { + envmnt::set("ENV_SET2", "value"); + + let mut env_values = IndexMap::::new(); + env_values.insert("ENV_SET2".to_string(), "value".to_string()); + + let condition = TaskCondition { + condition_type: None, + fail_message: None, + profiles: None, + os: None, + platforms: None, + channels: None, + env_set: None, + env_not_set: None, + env_true: None, + env_false: None, + env: None, + env_not: Some(env_values), + env_contains: None, + rust_version: None, + files_exist: None, + files_not_exist: None, + files_modified: None, + }; + + let enabled = validate_env_not(&condition, false); + + assert!(!enabled); +} + +#[test] +#[ignore] +fn validate_env_not_invalid_not_equal_with_any() { + envmnt::set("ENV_SET2", "value"); + + let mut env_values = IndexMap::::new(); + env_values.insert("ENV_SET2".to_string(), "value".to_string()); + + let condition = TaskCondition { + condition_type: None, + fail_message: None, + profiles: None, + os: None, + platforms: None, + channels: None, + env_set: None, + env_not_set: None, + env_true: None, + env_false: None, + env: None, + env_not: Some(env_values), + env_contains: None, + rust_version: None, + files_exist: None, + files_not_exist: None, + files_modified: None, + }; + + let enabled = validate_env_not(&condition, true); + + assert!(!enabled); +} + +#[test] +#[ignore] +fn validate_env_not_invalid_partial_found() { + envmnt::set("ENV_SET1", "good"); + envmnt::set("ENV_SET2", "good"); + + let mut env_values = IndexMap::::new(); + env_values.insert("ENV_SET1".to_string(), "good".to_string()); + env_values.insert("ENV_SET2".to_string(), "bad".to_string()); + + let condition = TaskCondition { + condition_type: None, + fail_message: None, + profiles: None, + os: None, + platforms: None, + channels: None, + env_set: None, + env_not_set: None, + env_true: None, + env_false: None, + env: None, + env_not: Some(env_values), + env_contains: None, + rust_version: None, + files_exist: None, + files_not_exist: None, + files_modified: None, + }; + + let enabled = validate_env_not(&condition, false); + + assert!(!enabled); +} + +#[test] +#[ignore] +fn validate_env_not_invalid_partial_found_with_any() { + envmnt::set("ENV_SET1", "good"); + envmnt::set("ENV_SET2", "good"); + + let mut env_values = IndexMap::::new(); + env_values.insert("ENV_SET1".to_string(), "good".to_string()); + env_values.insert("ENV_SET2".to_string(), "bad".to_string()); + + let condition = TaskCondition { + condition_type: None, + fail_message: None, + profiles: None, + os: None, + platforms: None, + channels: None, + env_set: None, + env_not_set: None, + env_true: None, + env_false: None, + env: Some(env_values), + env_not: None, + env_contains: None, + rust_version: None, + files_exist: None, + files_not_exist: None, + files_modified: None, + }; + + let enabled = validate_env_not(&condition, true); + + assert!(enabled); +} + #[test] #[ignore] fn validate_env_contains_valid_same() { @@ -1420,6 +1792,7 @@ fn validate_env_contains_valid_same() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: Some(env_values), rust_version: None, files_exist: None, @@ -1454,6 +1827,7 @@ fn validate_env_contains_valid_same_with_any() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: Some(env_values), rust_version: None, files_exist: None, @@ -1488,6 +1862,7 @@ fn validate_env_contains_valid() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: Some(env_values), rust_version: None, files_exist: None, @@ -1522,6 +1897,7 @@ fn validate_env_contains_valid_with_any() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: Some(env_values), rust_version: None, files_exist: None, @@ -1553,6 +1929,7 @@ fn validate_env_contains_invalid_not_found() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: Some(env_values), rust_version: None, files_exist: None, @@ -1584,6 +1961,7 @@ fn validate_env_contains_invalid_not_found_with_any() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: Some(env_values), rust_version: None, files_exist: None, @@ -1616,6 +1994,7 @@ fn validate_env_contains_invalid_not_equal() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: Some(env_values), rust_version: None, files_exist: None, @@ -1648,6 +2027,7 @@ fn validate_env_contains_invalid_not_equal_with_any() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: Some(env_values), rust_version: None, files_exist: None, @@ -1682,6 +2062,7 @@ fn validate_env_contains_invalid_partial_found() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: Some(env_values), rust_version: None, files_exist: None, @@ -1716,6 +2097,7 @@ fn validate_env_contains_invalid_partial_found_with_any() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: Some(env_values), rust_version: None, files_exist: None, @@ -1808,6 +2190,7 @@ fn validate_profile_valid() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -1837,6 +2220,7 @@ fn validate_profile_invalid() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -1867,6 +2251,7 @@ fn validate_os_valid() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -1893,6 +2278,7 @@ fn validate_os_invalid() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -1923,6 +2309,7 @@ fn validate_platform_valid() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -1949,6 +2336,7 @@ fn validate_platform_invalid() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2005,6 +2393,7 @@ fn validate_channel_valid() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2031,6 +2420,7 @@ fn validate_channel_valid() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2058,6 +2448,7 @@ fn validate_channel_valid() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2109,6 +2500,7 @@ fn validate_channel_invalid() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2134,6 +2526,7 @@ fn validate_file_exists_valid() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: Some(vec![ @@ -2162,6 +2555,7 @@ fn validate_file_exists_valid_with_any() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: Some(vec![ @@ -2190,6 +2584,7 @@ fn validate_file_exists_partial_invalid() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: Some(vec![ @@ -2219,6 +2614,7 @@ fn validate_file_exists_partial_invalid_with_any() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: Some(vec![ @@ -2248,6 +2644,7 @@ fn validate_file_exists_invalid() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: Some(vec![ @@ -2276,6 +2673,7 @@ fn validate_file_exists_invalid_with_any() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: Some(vec![ @@ -2304,6 +2702,7 @@ fn validate_file_not_exists_valid() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2332,6 +2731,7 @@ fn validate_file_not_exists_valid_with_any() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2360,6 +2760,7 @@ fn validate_file_not_exists_partial_invalid() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2389,6 +2790,7 @@ fn validate_file_not_exists_partial_invalid_with_any() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2418,6 +2820,7 @@ fn validate_file_not_exists_invalid() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2446,6 +2849,7 @@ fn validate_file_not_exists_invalid_with_any() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2474,6 +2878,7 @@ fn validate_files_modified_all_empty() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2503,6 +2908,7 @@ fn validate_files_modified_only_input() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2532,6 +2938,7 @@ fn validate_files_modified_only_output() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2561,6 +2968,7 @@ fn validate_files_modified_same_timestamp() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2598,6 +3006,7 @@ fn validate_files_modified_output_newer() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2636,6 +3045,7 @@ fn validate_files_modified_input_newer() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2671,6 +3081,7 @@ fn validate_files_modified_output_newer_env() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2706,6 +3117,7 @@ fn validate_files_modified_input_newer_env() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2763,6 +3175,7 @@ fn validate_criteria_empty() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2819,6 +3232,7 @@ fn validate_criteria_valid_os() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2871,6 +3285,7 @@ fn validate_criteria_invalid_os() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2927,6 +3342,7 @@ fn validate_criteria_valid_platform() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2979,6 +3395,7 @@ fn validate_criteria_invalid_platform() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -3032,6 +3449,7 @@ fn validate_criteria_valid_profile() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -3085,6 +3503,7 @@ fn validate_criteria_invalid_profile() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -3142,6 +3561,7 @@ fn validate_criteria_valid_channel() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -3171,6 +3591,7 @@ fn validate_criteria_valid_channel() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -3200,6 +3621,7 @@ fn validate_criteria_valid_channel() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -3253,6 +3675,7 @@ fn validate_criteria_invalid_channel() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -3305,6 +3728,7 @@ fn validate_criteria_valid_file_exists() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: Some(vec![ @@ -3359,6 +3783,7 @@ fn validate_criteria_invalid_file_exists() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: Some(vec![ @@ -3413,6 +3838,7 @@ fn validate_criteria_valid_file_not_exists() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -3467,6 +3893,7 @@ fn validate_criteria_invalid_file_not_exists() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -3528,6 +3955,7 @@ fn validate_condition_for_step_both_valid() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -3589,6 +4017,7 @@ fn validate_condition_for_step_valid_script_invalid() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -3650,6 +4079,7 @@ fn validate_condition_for_step_valid_script_invalid_or() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -3707,6 +4137,7 @@ fn validate_condition_for_step_invalid_script_valid() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -3765,6 +4196,7 @@ fn validate_condition_for_step_invalid_env_set() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -3825,6 +4257,7 @@ fn validate_condition_for_step_invalid_env_not_set() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -3890,6 +4323,7 @@ fn validate_condition_for_step_valid_env() { env_true: None, env_false: None, env: Some(env_values), + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -3952,6 +4386,7 @@ fn validate_condition_for_step_invalid_env_not_found() { env_true: None, env_false: None, env: Some(env_values), + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -4017,6 +4452,202 @@ fn validate_condition_for_step_invalid_env_not_equal() { env_true: None, env_false: None, env: Some(env_values), + env_not: None, + env_contains: None, + rust_version: None, + files_exist: None, + files_not_exist: None, + files_modified: None, + }); + step.config.condition_script = Some(ConditionScriptValue::Text(vec!["exit 0".to_string()])); + + let enabled = validate_condition_for_step(&flow_info, &step).unwrap(); + + assert!(!enabled); +} + +#[test] +#[ignore] +fn validate_condition_for_step_valid_env_not() { + let mut step = Step { + name: "test".to_string(), + config: Task::new(), + }; + + let config = Config { + config: ConfigSection::new(), + env_files: vec![], + env: IndexMap::new(), + env_scripts: vec![], + tasks: IndexMap::new(), + plugins: None, + }; + let flow_info = FlowInfo { + config, + task: "test".to_string(), + env_info: EnvInfo { + rust_info: RustInfo::new(), + crate_info: CrateInfo::new(), + git_info: GitInfo::new(), + ci_info: ci_info::get(), + }, + disable_workspace: false, + disable_on_error: false, + allow_private: false, + skip_init_end_tasks: false, + skip_tasks_pattern: None, + cli_arguments: None, + }; + + envmnt::set("ENV_SET1", "good1"); + envmnt::set("ENV_SET2", "good2"); + + let mut env_values = IndexMap::::new(); + env_values.insert("ENV_SET1".to_string(), "bad1".to_string()); + env_values.insert("ENV_SET2".to_string(), "bad2".to_string()); + + step.config.condition = Some(TaskCondition { + condition_type: None, + fail_message: None, + profiles: None, + os: None, + platforms: None, + channels: None, + env_set: None, + env_not_set: None, + env_true: None, + env_false: None, + env: None, + env_not: Some(env_values), + env_contains: None, + rust_version: None, + files_exist: None, + files_not_exist: None, + files_modified: None, + }); + step.config.condition_script = Some(ConditionScriptValue::Text(vec!["exit 0".to_string()])); + + let enabled = validate_condition_for_step(&flow_info, &step).unwrap(); + + assert!(enabled); +} + +#[test] +#[ignore] +fn validate_condition_for_step_valid_env_not_not_found() { + let mut step = Step { + name: "test".to_string(), + config: Task::new(), + }; + + let config = Config { + config: ConfigSection::new(), + env_files: vec![], + env: IndexMap::new(), + env_scripts: vec![], + tasks: IndexMap::new(), + plugins: None, + }; + let flow_info = FlowInfo { + config, + task: "test".to_string(), + env_info: EnvInfo { + rust_info: RustInfo::new(), + crate_info: CrateInfo::new(), + git_info: GitInfo::new(), + ci_info: ci_info::get(), + }, + disable_workspace: false, + disable_on_error: false, + allow_private: false, + skip_init_end_tasks: false, + skip_tasks_pattern: None, + cli_arguments: None, + }; + + let mut env_values = IndexMap::::new(); + env_values.insert("BAD_ENV_SET1".to_string(), "good".to_string()); + env_values.insert("BAD_ENV_SET2".to_string(), "bad".to_string()); + + step.config.condition = Some(TaskCondition { + condition_type: None, + fail_message: None, + profiles: None, + os: None, + platforms: None, + channels: None, + env_set: None, + env_not_set: None, + env_true: None, + env_false: None, + env: None, + env_not: Some(env_values), + env_contains: None, + rust_version: None, + files_exist: None, + files_not_exist: None, + files_modified: None, + }); + step.config.condition_script = Some(ConditionScriptValue::Text(vec!["exit 0".to_string()])); + + let enabled = validate_condition_for_step(&flow_info, &step).unwrap(); + + assert!(enabled); +} + +#[test] +#[ignore] +fn validate_condition_for_step_invalid_env_not_not_equal() { + let mut step = Step { + name: "test".to_string(), + config: Task::new(), + }; + + let config = Config { + config: ConfigSection::new(), + env_files: vec![], + env: IndexMap::new(), + env_scripts: vec![], + tasks: IndexMap::new(), + plugins: None, + }; + let flow_info = FlowInfo { + config, + task: "test".to_string(), + env_info: EnvInfo { + rust_info: RustInfo::new(), + crate_info: CrateInfo::new(), + git_info: GitInfo::new(), + ci_info: ci_info::get(), + }, + disable_workspace: false, + disable_on_error: false, + allow_private: false, + skip_init_end_tasks: false, + skip_tasks_pattern: None, + cli_arguments: None, + }; + + envmnt::set("ENV_SET1", "good"); + envmnt::set("ENV_SET2", "good"); + + let mut env_values = IndexMap::::new(); + env_values.insert("ENV_SET1".to_string(), "good".to_string()); + env_values.insert("ENV_SET2".to_string(), "bad".to_string()); + + step.config.condition = Some(TaskCondition { + condition_type: None, + fail_message: None, + profiles: None, + os: None, + platforms: None, + channels: None, + env_set: None, + env_not_set: None, + env_true: None, + env_false: None, + env: None, + env_not: Some(env_values), env_contains: None, rust_version: None, files_exist: None, @@ -4082,6 +4713,7 @@ fn validate_condition_for_step_valid_env_contains_same() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: Some(env_values), rust_version: None, files_exist: None, @@ -4147,6 +4779,7 @@ fn validate_condition_for_step_valid_env_contains() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: Some(env_values), rust_version: None, files_exist: None, @@ -4209,6 +4842,7 @@ fn validate_condition_for_step_invalid_env_contains_not_found() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: Some(env_values), rust_version: None, files_exist: None, @@ -4274,6 +4908,7 @@ fn validate_condition_for_step_invalid_env_contains_not_contains() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: Some(env_values), rust_version: None, files_exist: None, @@ -4334,6 +4969,7 @@ fn validate_condition_for_step_valid_rust_version() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: Some(RustVersionCondition { min: None, @@ -4398,6 +5034,7 @@ fn validate_condition_for_step_invalid_rust_version() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: Some(RustVersionCondition { min: None, @@ -4462,6 +5099,7 @@ fn validate_condition_for_step_both_valid_and() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -4526,6 +5164,7 @@ fn validate_condition_for_step_value_partial_valid_and() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -4587,6 +5226,7 @@ fn validate_condition_for_step_group_partial_valid_and() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -4648,6 +5288,7 @@ fn validate_condition_for_step_both_valid_or() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -4712,6 +5353,7 @@ fn validate_condition_for_step_value_partial_valid_or() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -4773,6 +5415,7 @@ fn validate_condition_for_step_group_partial_valid_or() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -4834,6 +5477,7 @@ fn validate_condition_for_step_both_valid_group_or() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -4898,6 +5542,7 @@ fn validate_condition_for_step_value_partial_valid_group_or() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -4958,6 +5603,7 @@ fn validate_condition_for_step_group_partial_valid_group_or() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -5374,6 +6020,7 @@ fn validate_rust_version_no_condition() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -5403,6 +6050,7 @@ fn validate_rust_version_with_valid_condition() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: Some(RustVersionCondition { min: Some(version.clone()), @@ -5437,6 +6085,7 @@ fn validate_rust_version_with_invalid_condition() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: Some(RustVersionCondition { min: None, diff --git a/src/lib/environment/mod_test.rs b/src/lib/environment/mod_test.rs index f4cd39f5..573b935a 100755 --- a/src/lib/environment/mod_test.rs +++ b/src/lib/environment/mod_test.rs @@ -324,6 +324,7 @@ fn set_env_script_with_condition_true() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -444,6 +445,7 @@ fn set_env_for_decode_info_condition_true() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -484,6 +486,7 @@ fn set_env_for_decode_info_condition_false() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -538,6 +541,7 @@ fn set_env_for_conditional_value_condition_true() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -575,6 +579,7 @@ fn set_env_for_conditional_value_condition_false() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -721,6 +726,7 @@ fn set_env_for_config_conditional() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, diff --git a/src/lib/plugin/runner_test.rs b/src/lib/plugin/runner_test.rs index 7d5dc690..e88dfd07 100644 --- a/src/lib/plugin/runner_test.rs +++ b/src/lib/plugin/runner_test.rs @@ -467,6 +467,7 @@ fn run_task_invoked_valid() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, diff --git a/src/lib/plugin/sdk/cm_plugin_check_task_condition_test.rs b/src/lib/plugin/sdk/cm_plugin_check_task_condition_test.rs index c55b93d8..e2ca8e3d 100644 --- a/src/lib/plugin/sdk/cm_plugin_check_task_condition_test.rs +++ b/src/lib/plugin/sdk/cm_plugin_check_task_condition_test.rs @@ -45,6 +45,7 @@ fn run_valid() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, diff --git a/src/lib/runner_test.rs b/src/lib/runner_test.rs index ea7f303c..6b2b578e 100755 --- a/src/lib/runner_test.rs +++ b/src/lib/runner_test.rs @@ -1773,6 +1773,7 @@ fn run_sub_task_and_report_routing_condition_not_met() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -1978,6 +1979,7 @@ fn get_sub_task_info_for_routing_info_condition_not_met() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2042,6 +2044,7 @@ fn get_sub_task_info_for_routing_info_condition_found() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2106,6 +2109,7 @@ fn get_sub_task_info_for_routing_info_condition_found_multiple_tasks() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2265,6 +2269,7 @@ fn get_sub_task_info_for_routing_info_multiple_found() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2340,6 +2345,7 @@ fn get_sub_task_info_for_routing_info_default() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2424,6 +2430,7 @@ fn get_sub_task_info_for_routing_info_multiple() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2516,6 +2523,7 @@ fn get_sub_task_info_for_routing_info_fork_false() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2580,6 +2588,7 @@ fn get_sub_task_info_for_routing_info_fork_true() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, diff --git a/src/lib/types.rs b/src/lib/types.rs index 9f4fe0a7..237b7a12 100755 --- a/src/lib/types.rs +++ b/src/lib/types.rs @@ -399,6 +399,8 @@ pub struct TaskCondition { pub env_not_set: Option>, /// Environment variables and their values pub env: Option>, + /// Environment variables and the values which they must not be defined as + pub env_not: Option>, /// Environment variables which are defined as true pub env_true: Option>, /// Environment variables which are defined as false diff --git a/src/lib/types_test.rs b/src/lib/types_test.rs index 33f2252c..b1e84f6b 100755 --- a/src/lib/types_test.rs +++ b/src/lib/types_test.rs @@ -1969,6 +1969,7 @@ fn task_extend_extended_have_all_fields() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2022,6 +2023,7 @@ fn task_extend_extended_have_all_fields() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2072,6 +2074,7 @@ fn task_extend_extended_have_all_fields() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2122,6 +2125,7 @@ fn task_extend_extended_have_all_fields() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2273,6 +2277,7 @@ fn task_extend_clear_with_no_data() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2326,6 +2331,7 @@ fn task_extend_clear_with_no_data() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2376,6 +2382,7 @@ fn task_extend_clear_with_no_data() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2426,6 +2433,7 @@ fn task_extend_clear_with_no_data() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2530,6 +2538,7 @@ fn task_extend_clear_with_all_data() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2583,6 +2592,7 @@ fn task_extend_clear_with_all_data() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2633,6 +2643,7 @@ fn task_extend_clear_with_all_data() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2683,6 +2694,7 @@ fn task_extend_clear_with_all_data() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -2951,6 +2963,7 @@ fn task_get_normalized_task_with_override_no_clear() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -3000,6 +3013,7 @@ fn task_get_normalized_task_with_override_no_clear() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -3175,6 +3189,7 @@ fn task_get_normalized_task_with_override_clear_false() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -3227,6 +3242,7 @@ fn task_get_normalized_task_with_override_clear_false() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -3399,6 +3415,7 @@ fn task_get_normalized_task_with_override_clear_false_partial_override() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -3447,6 +3464,7 @@ fn task_get_normalized_task_with_override_clear_false_partial_override() { force: None, env_files: None, env: None, + env_not: None, cwd: None, install_script: None, args: None, @@ -3572,6 +3590,7 @@ fn task_get_normalized_task_with_override_clear_true() { env_true: None, env_false: None, env: None, + env_not: None, env_contains: None, rust_version: None, files_exist: None, @@ -3620,6 +3639,7 @@ fn task_get_normalized_task_with_override_clear_true() { force: None, env_files: None, env: None, + env_not: None, cwd: None, install_script: None, args: None,