Support internal core tasks modifications (private and namespacing) #201

This commit is contained in:
sagie gur ari
2019-03-15 20:16:25 +02:00
parent f51f2b4574
commit c80756ec19
11 changed files with 698 additions and 14 deletions
+4
View File
@@ -1,5 +1,9 @@
## CHANGELOG
### v0.17.0
* Support internal core tasks modifications (private and namespacing) #201
### v0.16.10 (2019-03-01)
* Fix docs
+16
View File
@@ -66,6 +66,7 @@
* [Flows/Other](#usage-predefined-flows-flows)
* [Full List](#usage-predefined-flows-full)
* [Disabling Predefined Tasks/Flows](#usage-predefined-flows-disable)
* [Modifing Predefined Tasks/Flows](#usage-predefined-flows-modify)
* [Diff Changes](#usage-diff-changes)
* [Cli Options](#usage-cli)
* [Global Configuration](#cargo-make-global-config)
@@ -2114,6 +2115,21 @@ In order to prevent loading of internal core tasks and flows, simply add the fol
skip_core_tasks = true
```
<a name="usage-predefined-flows-modify"></a>
#### Modifing Predefined Tasks/Flows
It is possible to modify the internal core tasks.<br>
All modifications are defines in the **config.modify_core_tasks** section.
```toml
[config.modify_core_tasks]
# if true, all core tasks are set to private (default false)
private = true
# if set to some value, all core tasks are modified to: <namespace>::<name> for example default::build
namespace = "default"
```
<a name="usage-diff-changes"></a>
### Diff Changes
Using the **--diff-steps** cli command flag, you can diff your correct overrides compared to the prebuilt internal makefile flow.
+15
View File
@@ -2030,6 +2030,21 @@ In order to prevent loading of internal core tasks and flows, simply add the fol
skip_core_tasks = true
```
<a name="usage-predefined-flows-modify"></a>
#### Modifing Predefined Tasks/Flows
It is possible to modify the internal core tasks.<br>
All modifications are defines in the **config.modify_core_tasks** section.
```toml
[config.modify_core_tasks]
# if true, all core tasks are set to private (default false)
private = true
# if set to some value, all core tasks are modified to: <namespace>::<name> for example default::build
namespace = "default"
```
<a name="usage-diff-changes"></a>
### Diff Changes
Using the **--diff-steps** cli command flag, you can diff your correct overrides compared to the prebuilt internal makefile flow.
+1
View File
@@ -59,6 +59,7 @@
* [Flows/Other](#usage-predefined-flows-flows)
* [Full List](#usage-predefined-flows-full)
* [Disabling Predefined Tasks/Flows](#usage-predefined-flows-disable)
* [Modifing Predefined Tasks/Flows](#usage-predefined-flows-modify)
* [Diff Changes](#usage-diff-changes)
* [Cli Options](#usage-cli)
* [Global Configuration](#cargo-make-global-config)
+7
View File
@@ -0,0 +1,7 @@
[config.modify_core_tasks]
private = true
namespace = "default"
[tasks.empty2]
run_task = "default::empty"
+1 -1
View File
@@ -109,7 +109,7 @@ fn run(cli_args: CliArgs, global_config: &GlobalConfig) {
if cli_args.list_all_steps {
cli_commands::list_steps::run(&config, &cli_args.output_format);
} else if cli_args.diff_execution_plan {
let default_config = descriptor::load_internal_descriptors(true, experimental);
let default_config = descriptor::load_internal_descriptors(true, experimental, None);
cli_commands::diff_steps::run(&default_config, &config, &task, &cli_args);
} else if cli_args.print_only {
cli_commands::print_steps::print(
+33 -5
View File
@@ -11,7 +11,7 @@
mod descriptor_test;
use crate::command;
use crate::types::{Config, ConfigSection, EnvValue, Extend, ExternalConfig, Task};
use crate::types::{Config, ConfigSection, EnvValue, Extend, ExternalConfig, ModifyConfig, Task};
use indexmap::IndexMap;
use std::env;
use std::fs::{canonicalize, File};
@@ -257,7 +257,11 @@ fn load_external_descriptor(
}
}
pub(crate) fn load_internal_descriptors(stable: bool, experimental: bool) -> Config {
pub(crate) fn load_internal_descriptors(
stable: bool,
experimental: bool,
modif_config: Option<ModifyConfig>,
) -> Config {
debug!("Loading base tasks.");
let base_descriptor = if stable {
@@ -289,6 +293,11 @@ pub(crate) fn load_internal_descriptors(stable: bool, experimental: bool) -> Con
base_config.tasks = all_tasks;
}
match modif_config {
Some(props) => base_config.apply(&props),
None => (),
};
base_config
}
@@ -302,8 +311,9 @@ fn load_descriptors(
env_map: Option<Vec<String>>,
stable: bool,
experimental: bool,
modify_core_tasks: Option<ModifyConfig>,
) -> Config {
let default_config = load_internal_descriptors(stable, experimental);
let default_config = load_internal_descriptors(stable, experimental, modify_core_tasks);
let mut external_config: ExternalConfig = load_external_descriptor(".", file_name, force, true);
@@ -397,10 +407,28 @@ pub(crate) fn load(
env_map: Option<Vec<String>>,
experimental: bool,
) -> Config {
let mut config = load_descriptors(&file_name, force, env_map.clone(), true, experimental);
let mut config = load_descriptors(&file_name, force, env_map.clone(), true, experimental, None);
if config.config.skip_core_tasks.unwrap_or(false) {
config = load_descriptors(&file_name, force, env_map.clone(), false, false);
config = load_descriptors(&file_name, force, env_map.clone(), false, false, None);
} else {
let modify_core_tasks = config.config.modify_core_tasks.clone();
match modify_core_tasks {
Some(modify_config) => {
if modify_config.is_modifications_defined() {
config = load_descriptors(
&file_name,
force,
env_map.clone(),
true,
experimental,
Some(modify_config),
);
}
}
None => (),
};
}
config
+83 -7
View File
@@ -341,7 +341,7 @@ fn load_descriptors_load_workspace_makefile() {
"CARGO_MAKE_WORKSPACE_MAKEFILE",
"./examples/workspace/Makefile.toml",
);
let config = load_descriptors("./bad/bad.toml", false, None, false, false);
let config = load_descriptors("./bad/bad.toml", false, None, false, false, None);
env::remove_var("CARGO_MAKE_WORKSPACE_MAKEFILE");
let task = config.tasks.get("workspace-echo");
@@ -354,7 +354,7 @@ fn load_descriptors_load_workspace_makefile_no_exists() {
"CARGO_MAKE_WORKSPACE_MAKEFILE",
"./examples/workspace/Makefile2.toml",
);
let config = load_descriptors("./bad/bad.toml", false, None, false, false);
let config = load_descriptors("./bad/bad.toml", false, None, false, false, None);
env::remove_var("CARGO_MAKE_WORKSPACE_MAKEFILE");
let task = config.tasks.get("workspace-echo");
@@ -364,7 +364,7 @@ fn load_descriptors_load_workspace_makefile_no_exists() {
#[test]
fn load_descriptors_no_load_workspace_makefile() {
env::remove_var("CARGO_MAKE_WORKSPACE_MAKEFILE");
let config = load_descriptors("./bad/bad.toml", false, None, false, false);
let config = load_descriptors("./bad/bad.toml", false, None, false, false, None);
let task = config.tasks.get("workspace-echo");
assert!(task.is_none());
@@ -394,6 +394,21 @@ fn load_with_stable() {
assert!(task.is_some());
}
#[test]
fn load_with_modify() {
let config = load("./examples/modify_core_tasks.toml", true, None, false);
assert!(config.env.get(&"RUST_BACKTRACE".to_string()).is_some());
let mut task = config.tasks.get("empty");
assert!(task.is_none());
task = config.tasks.get("default::empty");
assert!(task.is_some());
assert!(task.clone().unwrap().private.unwrap());
task = config.tasks.get("default::init");
assert!(task.is_some());
}
#[test]
#[should_panic]
fn load_not_found() {
@@ -402,7 +417,7 @@ fn load_not_found() {
#[test]
fn load_internal_descriptors_no_stable() {
let config = load_internal_descriptors(false, false);
let config = load_internal_descriptors(false, false, None);
let mut task = config.tasks.get("empty");
assert!(task.is_some());
@@ -412,7 +427,7 @@ fn load_internal_descriptors_no_stable() {
#[test]
fn load_internal_descriptors_with_stable() {
let config = load_internal_descriptors(true, false);
let config = load_internal_descriptors(true, false, None);
let mut task = config.tasks.get("empty");
assert!(task.is_some());
@@ -422,7 +437,7 @@ fn load_internal_descriptors_with_stable() {
#[test]
fn load_internal_descriptors_no_experimental() {
let config = load_internal_descriptors(true, false);
let config = load_internal_descriptors(true, false, None);
let mut task = config.tasks.get("ci-flow");
assert!(task.is_some());
@@ -432,7 +447,7 @@ fn load_internal_descriptors_no_experimental() {
#[test]
fn load_internal_descriptors_with_experimental() {
let config = load_internal_descriptors(true, true);
let config = load_internal_descriptors(true, true, None);
let mut task = config.tasks.get("ci-flow");
assert!(task.is_some());
@@ -440,6 +455,67 @@ fn load_internal_descriptors_with_experimental() {
assert!(task.is_some());
}
#[test]
fn load_internal_descriptors_modify_empty() {
let config = load_internal_descriptors(
true,
false,
Some(ModifyConfig {
private: None,
namespace: None,
}),
);
let mut task = config.tasks.get("empty");
assert!(task.is_some());
assert!(task.unwrap().private.is_none());
task = config.tasks.get("init");
assert!(task.is_some());
assert!(task.unwrap().private.is_none());
}
#[test]
fn load_internal_descriptors_modify_private() {
let config = load_internal_descriptors(
true,
false,
Some(ModifyConfig {
private: Some(true),
namespace: None,
}),
);
let mut task = config.tasks.get("empty");
assert!(task.is_some());
assert!(task.unwrap().private.unwrap());
task = config.tasks.get("init");
assert!(task.is_some());
assert!(task.unwrap().private.unwrap());
}
#[test]
fn load_internal_descriptors_modify_namespace() {
let config = load_internal_descriptors(
true,
false,
Some(ModifyConfig {
private: None,
namespace: Some("default".to_string()),
}),
);
let mut task = config.tasks.get("empty");
assert!(task.is_none());
task = config.tasks.get("default::empty");
assert!(task.is_some());
assert!(task.unwrap().private.is_none());
task = config.tasks.get("init");
assert!(task.is_none());
task = config.tasks.get("default::init");
assert!(task.is_some());
assert!(task.unwrap().private.is_none());
}
#[test]
fn load_external_descriptor_no_file() {
let config = load_external_descriptor(".", "bad_file.toml2", false, false);
+1 -1
View File
@@ -9,7 +9,7 @@ use ci_info;
use rust_info::types::RustInfo;
fn load_descriptor() -> Config {
descriptor::load_internal_descriptors(true, false)
descriptor::load_internal_descriptors(true, false, None)
}
fn get_task(name: &str, config: &Config) -> Task {
+174
View File
@@ -23,6 +23,18 @@ pub fn get_platform_name() -> String {
}
}
fn get_namespaced_task_name(namespace: &str, task: &str) -> String {
let mut namespaced_task = String::new();
if namespace.len() > 0 {
namespaced_task.push_str(namespace);
namespaced_task.push_str("::");
}
namespaced_task.push_str(task);
namespaced_task
}
#[derive(Debug, Clone)]
/// Holds CLI args
pub struct CliArgs {
@@ -669,6 +681,84 @@ impl Task {
}
}
/// Apply modifications
pub fn apply(self: &mut Task, modify_config: &ModifyConfig) {
match modify_config.private {
Some(value) => {
if value {
self.private = Some(true);
}
}
None => (),
};
match modify_config.namespace {
Some(ref namespace) => {
if namespace.len() > 0 {
if self.alias.is_some() {
self.alias = Some(get_namespaced_task_name(
namespace,
&self.alias.clone().unwrap(),
));
}
if self.linux_alias.is_some() {
self.linux_alias = Some(get_namespaced_task_name(
namespace,
&self.linux_alias.clone().unwrap(),
));
}
if self.windows_alias.is_some() {
self.windows_alias = Some(get_namespaced_task_name(
namespace,
&self.windows_alias.clone().unwrap(),
));
}
if self.mac_alias.is_some() {
self.mac_alias = Some(get_namespaced_task_name(
namespace,
&self.mac_alias.clone().unwrap(),
));
}
if self.run_task.is_some() {
let mut run_task = self.run_task.clone().unwrap();
run_task = match run_task {
RunTaskInfo::Name(value) => {
RunTaskInfo::Name(get_namespaced_task_name(namespace, &value))
}
RunTaskInfo::Routing(mut routing_info_vector) => {
for mut routing_info in &mut routing_info_vector {
routing_info.name =
get_namespaced_task_name(namespace, &routing_info.name);
}
RunTaskInfo::Routing(routing_info_vector)
}
};
self.run_task = Some(run_task);
}
if self.dependencies.is_some() {
let dependencies = self.dependencies.clone().unwrap();
let mut modified_dependencies = vec![];
for task in &dependencies {
modified_dependencies.push(get_namespaced_task_name(namespace, &task));
}
self.dependencies = Some(modified_dependencies);
}
}
}
None => (),
};
}
/// Copies values from the task into self.
///
/// # Arguments
@@ -1159,11 +1249,36 @@ pub enum Extend {
List(Vec<ExtendOptions>),
}
#[derive(Serialize, Deserialize, Debug, Clone)]
/// Holds properties to modify the core tasks
pub struct ModifyConfig {
/// If true, all core tasks will be set to private (default false)
pub private: Option<bool>,
/// If set to some value, all core tasks are modified to: <namespace>::<name> for example default::build
pub namespace: Option<String>,
}
impl ModifyConfig {
/// Returns true if config modifications is needed based on the current state
pub fn is_modifications_defined(self: &ModifyConfig) -> bool {
if self.private.unwrap_or(false) {
true
} else {
match self.namespace {
Some(ref value) => value.len() > 0,
None => false,
}
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
/// Holds the configuration found in the makefile toml config section.
pub struct ConfigSection {
/// If true, the default core tasks will not be loaded
pub skip_core_tasks: Option<bool>,
/// Modify core tasks config
pub modify_core_tasks: Option<ModifyConfig>,
/// Init task name which will be invoked at the start of every run
pub init_task: Option<String>,
/// End task name which will be invoked at the end of every run
@@ -1185,6 +1300,7 @@ impl ConfigSection {
pub fn new() -> ConfigSection {
ConfigSection {
skip_core_tasks: None,
modify_core_tasks: None,
init_task: None,
end_task: None,
on_error_task: None,
@@ -1195,6 +1311,35 @@ impl ConfigSection {
}
}
/// Apply modifications
pub fn apply(self: &mut ConfigSection, modify_config: &ModifyConfig) {
match modify_config.namespace {
Some(ref namespace) => {
if self.init_task.is_some() {
self.init_task = Some(get_namespaced_task_name(
namespace,
&self.init_task.clone().unwrap(),
));
}
if self.end_task.is_some() {
self.end_task = Some(get_namespaced_task_name(
namespace,
&self.end_task.clone().unwrap(),
));
}
if self.on_error_task.is_some() {
self.on_error_task = Some(get_namespaced_task_name(
namespace,
&self.on_error_task.clone().unwrap(),
));
}
}
None => (),
}
}
/// Copies values from the config section into self.
///
/// # Arguments
@@ -1205,6 +1350,10 @@ impl ConfigSection {
self.skip_core_tasks = extended.skip_core_tasks.clone();
}
if extended.modify_core_tasks.is_some() {
self.modify_core_tasks = extended.modify_core_tasks.clone();
}
if extended.init_task.is_some() {
self.init_task = extended.init_task.clone();
}
@@ -1271,6 +1420,31 @@ pub struct Config {
pub tasks: IndexMap<String, Task>,
}
impl Config {
/// Apply modifications
pub fn apply(self: &mut Config, modify_config: &ModifyConfig) {
self.config.apply(&modify_config);
let namespace = match modify_config.namespace {
Some(ref namespace) => namespace,
None => "",
};
let mut modified_tasks = IndexMap::<String, Task>::new();
for (key, value) in self.tasks.iter() {
let namespaced_task = get_namespaced_task_name(namespace, &key);
let mut task = value.clone();
task.apply(&modify_config);
modified_tasks.insert(namespaced_task, task);
}
self.tasks = modified_tasks;
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
/// Holds the entire externally read configuration such as task definitions and env vars where all values are optional
pub struct ExternalConfig {
+363
View File
@@ -1890,6 +1890,7 @@ fn config_section_new() {
let config = ConfigSection::new();
assert!(config.skip_core_tasks.is_none());
assert!(config.modify_core_tasks.is_none());
assert!(config.init_task.is_none());
assert!(config.end_task.is_none());
assert!(config.on_error_task.is_none());
@@ -1905,6 +1906,10 @@ fn config_section_extend_all_values() {
let mut extended = ConfigSection::new();
base.skip_core_tasks = Some(true);
base.modify_core_tasks = Some(ModifyConfig {
private: Some(true),
namespace: Some("base".to_string()),
});
base.init_task = Some("base_init".to_string());
base.end_task = Some("base_end".to_string());
base.on_error_task = Some("base_err".to_string());
@@ -1914,6 +1919,10 @@ fn config_section_extend_all_values() {
base.mac_load_script = Some(vec!["mac".to_string(), "base_info".to_string()]);
extended.skip_core_tasks = Some(false);
extended.modify_core_tasks = Some(ModifyConfig {
private: Some(false),
namespace: Some("extended".to_string()),
});
extended.init_task = Some("extended_init".to_string());
extended.end_task = Some("extended_end".to_string());
extended.on_error_task = Some("extended_err".to_string());
@@ -1925,6 +1934,9 @@ fn config_section_extend_all_values() {
base.extend(&mut extended);
assert!(!base.skip_core_tasks.unwrap());
let modify_core_tasks = base.modify_core_tasks.unwrap();
assert!(!modify_core_tasks.private.unwrap());
assert_eq!(modify_core_tasks.namespace.unwrap(), "extended".to_string());
assert_eq!(base.init_task.unwrap(), "extended_init".to_string());
assert_eq!(base.end_task.unwrap(), "extended_end".to_string());
assert_eq!(base.on_error_task.unwrap(), "extended_err".to_string());
@@ -1940,6 +1952,10 @@ fn config_section_extend_no_values() {
let mut extended = ConfigSection::new();
base.skip_core_tasks = Some(true);
base.modify_core_tasks = Some(ModifyConfig {
private: Some(true),
namespace: Some("base".to_string()),
});
base.init_task = Some("base_init".to_string());
base.end_task = Some("base_end".to_string());
base.on_error_task = Some("base_err".to_string());
@@ -1951,6 +1967,9 @@ fn config_section_extend_no_values() {
base.extend(&mut extended);
assert!(base.skip_core_tasks.unwrap());
let modify_core_tasks = base.modify_core_tasks.unwrap();
assert!(modify_core_tasks.private.unwrap());
assert_eq!(modify_core_tasks.namespace.unwrap(), "base".to_string());
assert_eq!(base.init_task.unwrap(), "base_init".to_string());
assert_eq!(base.end_task.unwrap(), "base_end".to_string());
assert_eq!(base.on_error_task.unwrap(), "base_err".to_string());
@@ -1966,6 +1985,10 @@ fn config_section_extend_some_values() {
let mut extended = ConfigSection::new();
base.skip_core_tasks = Some(true);
base.modify_core_tasks = Some(ModifyConfig {
private: Some(true),
namespace: Some("base".to_string()),
});
base.init_task = Some("base_init".to_string());
base.end_task = Some("base_end".to_string());
base.on_error_task = Some("base_err".to_string());
@@ -1980,6 +2003,9 @@ fn config_section_extend_some_values() {
base.extend(&mut extended);
assert!(!base.skip_core_tasks.unwrap());
let modify_core_tasks = base.modify_core_tasks.unwrap();
assert!(modify_core_tasks.private.unwrap());
assert_eq!(modify_core_tasks.namespace.unwrap(), "base".to_string());
assert_eq!(base.init_task.unwrap(), "extended_init".to_string());
assert_eq!(base.end_task.unwrap(), "base_end".to_string());
assert_eq!(base.on_error_task.unwrap(), "base_err".to_string());
@@ -2048,3 +2074,340 @@ fn git_info_new() {
assert!(git_info.user_name.is_none());
assert!(git_info.user_email.is_none());
}
#[test]
fn get_namespaced_task_name_empty() {
let output = get_namespaced_task_name("", "my_task");
assert_eq!(output, "my_task");
}
#[test]
fn get_namespaced_task_name_with_value() {
let output = get_namespaced_task_name("prefix", "my_task");
assert_eq!(output, "prefix::my_task");
}
#[test]
fn task_apply_task_empty_modify_empty() {
let modify_config = ModifyConfig {
private: None,
namespace: None,
};
let mut task = Task::new();
task.apply(&modify_config);
assert!(task.private.is_none());
assert!(task.alias.is_none());
assert!(task.linux_alias.is_none());
assert!(task.windows_alias.is_none());
assert!(task.mac_alias.is_none());
assert!(task.run_task.is_none());
assert!(task.dependencies.is_none());
}
#[test]
fn task_apply_task_empty_modify_private() {
let modify_config = ModifyConfig {
private: Some(true),
namespace: None,
};
let mut task = Task::new();
task.apply(&modify_config);
assert!(task.private.unwrap());
assert!(task.alias.is_none());
assert!(task.linux_alias.is_none());
assert!(task.windows_alias.is_none());
assert!(task.mac_alias.is_none());
assert!(task.run_task.is_none());
assert!(task.dependencies.is_none());
}
#[test]
fn task_apply_task_empty_modify_not_private() {
let modify_config = ModifyConfig {
private: Some(false),
namespace: None,
};
let mut task = Task::new();
task.apply(&modify_config);
assert!(task.private.is_none());
assert!(task.alias.is_none());
assert!(task.linux_alias.is_none());
assert!(task.windows_alias.is_none());
assert!(task.mac_alias.is_none());
assert!(task.run_task.is_none());
assert!(task.dependencies.is_none());
}
#[test]
fn task_apply_modify_empty() {
let modify_config = ModifyConfig {
private: None,
namespace: None,
};
let mut task = Task::new();
task.private = Some(true);
task.apply(&modify_config);
assert!(task.private.unwrap());
assert!(task.alias.is_none());
assert!(task.linux_alias.is_none());
assert!(task.windows_alias.is_none());
assert!(task.mac_alias.is_none());
assert!(task.run_task.is_none());
assert!(task.dependencies.is_none());
}
#[test]
fn task_apply_modify_private() {
let modify_config = ModifyConfig {
private: Some(true),
namespace: None,
};
let mut task = Task::new();
task.private = Some(false);
task.apply(&modify_config);
assert!(task.private.unwrap());
assert!(task.alias.is_none());
assert!(task.linux_alias.is_none());
assert!(task.windows_alias.is_none());
assert!(task.mac_alias.is_none());
assert!(task.run_task.is_none());
assert!(task.dependencies.is_none());
}
#[test]
fn task_apply_modify_not_private() {
let modify_config = ModifyConfig {
private: Some(false),
namespace: None,
};
let mut task = Task::new();
task.private = Some(true);
task.apply(&modify_config);
assert!(task.private.unwrap());
assert!(task.alias.is_none());
assert!(task.linux_alias.is_none());
assert!(task.windows_alias.is_none());
assert!(task.mac_alias.is_none());
assert!(task.run_task.is_none());
assert!(task.dependencies.is_none());
}
#[test]
fn task_apply_task_empty_modify_namespace() {
let modify_config = ModifyConfig {
private: None,
namespace: Some("default".to_string()),
};
let mut task = Task::new();
task.apply(&modify_config);
assert!(task.private.is_none());
assert!(task.alias.is_none());
assert!(task.linux_alias.is_none());
assert!(task.windows_alias.is_none());
assert!(task.mac_alias.is_none());
assert!(task.run_task.is_none());
assert!(task.dependencies.is_none());
}
#[test]
fn task_apply_no_run_task_modify_namespace() {
let modify_config = ModifyConfig {
private: None,
namespace: Some("default".to_string()),
};
let mut task = Task::new();
task.alias = Some("alias".to_string());
task.linux_alias = Some("linux_alias".to_string());
task.windows_alias = Some("windows_alias".to_string());
task.mac_alias = Some("mac_alias".to_string());
task.dependencies = Some(vec!["dep1".to_string(), "dep2".to_string()]);
task.apply(&modify_config);
assert!(task.private.is_none());
assert_eq!(task.alias.unwrap(), "default::alias");
assert_eq!(task.linux_alias.unwrap(), "default::linux_alias");
assert_eq!(task.windows_alias.unwrap(), "default::windows_alias");
assert_eq!(task.mac_alias.unwrap(), "default::mac_alias");
assert!(task.run_task.is_none());
assert_eq!(
task.dependencies.unwrap(),
vec!["default::dep1".to_string(), "default::dep2".to_string()]
);
}
#[test]
fn task_apply_run_task_name_modify_namespace() {
let modify_config = ModifyConfig {
private: None,
namespace: Some("default".to_string()),
};
let mut task = Task::new();
task.run_task = Some(RunTaskInfo::Name("run_task1".to_string()));
task.apply(&modify_config);
assert!(task.private.is_none());
assert!(task.alias.is_none());
assert!(task.linux_alias.is_none());
assert!(task.windows_alias.is_none());
assert!(task.mac_alias.is_none());
let run_task_name = match task.run_task.unwrap() {
RunTaskInfo::Name(name) => name,
_ => panic!("Invalid run task value."),
};
assert_eq!(run_task_name, "default::run_task1");
assert!(task.dependencies.is_none());
}
#[test]
fn task_apply_run_task_routing_info_modify_namespace() {
let modify_config = ModifyConfig {
private: None,
namespace: Some("default".to_string()),
};
let mut task = Task::new();
task.run_task = Some(RunTaskInfo::Routing(vec![RunTaskRoutingInfo {
name: "run_task1".to_string(),
condition: None,
condition_script: None,
}]));
task.apply(&modify_config);
assert!(task.private.is_none());
assert!(task.alias.is_none());
assert!(task.linux_alias.is_none());
assert!(task.windows_alias.is_none());
assert!(task.mac_alias.is_none());
let routing_info = match task.run_task.unwrap() {
RunTaskInfo::Routing(ref mut info) => info.pop(),
_ => panic!("Invalid run task value."),
};
assert_eq!(routing_info.unwrap().name, "default::run_task1");
assert!(task.dependencies.is_none());
}
#[test]
fn config_section_apply_config_empty_modify_empty() {
let modify_config = ModifyConfig {
private: None,
namespace: None,
};
let mut config_section = ConfigSection::new();
config_section.apply(&modify_config);
assert!(config_section.init_task.is_none());
assert!(config_section.end_task.is_none());
assert!(config_section.on_error_task.is_none());
}
#[test]
fn config_section_apply_config_empty_modify_namespace() {
let modify_config = ModifyConfig {
private: None,
namespace: Some("default".to_string()),
};
let mut config_section = ConfigSection::new();
config_section.apply(&modify_config);
assert!(config_section.init_task.is_none());
assert!(config_section.end_task.is_none());
assert!(config_section.on_error_task.is_none());
}
#[test]
fn config_section_apply_config_with_values_modify_empty() {
let modify_config = ModifyConfig {
private: None,
namespace: None,
};
let mut config_section = ConfigSection::new();
config_section.init_task = Some("init".to_string());
config_section.end_task = Some("end".to_string());
config_section.on_error_task = Some("error".to_string());
config_section.apply(&modify_config);
assert_eq!(config_section.init_task.unwrap(), "init");
assert_eq!(config_section.end_task.unwrap(), "end");
assert_eq!(config_section.on_error_task.unwrap(), "error");
}
#[test]
fn config_section_apply_config_with_values_modify_namespace() {
let modify_config = ModifyConfig {
private: None,
namespace: Some("config_ns".to_string()),
};
let mut config_section = ConfigSection::new();
config_section.init_task = Some("init".to_string());
config_section.end_task = Some("end".to_string());
config_section.on_error_task = Some("error".to_string());
config_section.apply(&modify_config);
assert_eq!(config_section.init_task.unwrap(), "config_ns::init");
assert_eq!(config_section.end_task.unwrap(), "config_ns::end");
assert_eq!(config_section.on_error_task.unwrap(), "config_ns::error");
}
#[test]
fn config_apply_modify_empty() {
let modify_config = ModifyConfig {
private: None,
namespace: None,
};
let mut config_section = ConfigSection::new();
config_section.init_task = Some("init".to_string());
let mut tasks = IndexMap::new();
let mut task = Task::new();
task.private = Some(false);
tasks.insert("test".to_string(), task);
let mut config = Config {
config: config_section,
env: IndexMap::new(),
tasks,
};
config.apply(&modify_config);
assert_eq!(config.config.init_task.unwrap(), "init");
assert_eq!(config.env.len(), 0);
assert_eq!(config.tasks.len(), 1);
assert!(!config.tasks.get("test").unwrap().private.unwrap());
}
#[test]
fn config_apply_modify_all() {
let modify_config = ModifyConfig {
private: Some(true),
namespace: Some("all".to_string()),
};
let mut config_section = ConfigSection::new();
config_section.init_task = Some("init".to_string());
let mut tasks = IndexMap::new();
let mut task = Task::new();
task.private = Some(false);
tasks.insert("test".to_string(), task);
let mut config = Config {
config: config_section,
env: IndexMap::new(),
tasks,
};
config.apply(&modify_config);
assert_eq!(config.config.init_task.unwrap(), "all::init");
assert_eq!(config.env.len(), 0);
assert_eq!(config.tasks.len(), 1);
assert!(config.tasks.get("all::test").unwrap().private.unwrap());
}