Skip to content

Commit

Permalink
Test missing name and command.
Browse files Browse the repository at this point in the history
  • Loading branch information
joaander committed May 13, 2024
1 parent da0e8c5 commit 387a58e
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ pub enum Error {
#[error("Cannot compare {0} and {1} while checking directory '{2}'.")]
CannotCompareInclude(Value, Value, PathBuf),

#[error("Action at index {0} is missing name.")]
ActionMissingName(usize),

#[error("Action '{0}' is missing command.")]
ActionMissingCommand(String),

// submission errors
#[error("Error encountered while executing action '{0}': {1}.")]
ExecuteAction(String, String),
Expand Down
68 changes: 65 additions & 3 deletions src/workflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ pub struct Action {
/// The group of jobs to submit.
#[serde(default)]
pub group: Group,

// Name of the group to copy defaults from.
pub from: Option<String>,
}

/// Default tables
Expand Down Expand Up @@ -547,13 +550,20 @@ impl Workflow {
fn validate_and_set_defaults(mut self) -> Result<Self, Error> {
let mut action_names = HashSet::with_capacity(self.action.len());

for action in &mut self.action {
for (action_idx, action) in self.action.iter_mut().enumerate() {
//TODO: implement from, validate no recursive from's
action.resolve(&self.default.action);

action_names.insert(action.name().to_string());
trace!("Validating action '{}'.", action.name());

if action.name == None {
return Err(Error::ActionMissingName(action_idx));
}
if action.command == None {
return Err(Error::ActionMissingCommand(action.name().into()));
}

// Warn for apparently invalid sort_by.
for pointer in &action.group.sort_by {
if !pointer.is_empty() && !pointer.starts_with('/') {
Expand Down Expand Up @@ -812,9 +822,34 @@ command = "c"
assert!(!action.group.reverse_sort);
}

// TODO: test action with no name
// TODO: test action with no command
#[test]
#[parallel]
fn action_no_name() {
let temp = TempDir::new().unwrap();
let workflow = r#"
[[action]]
command = "c"
"#;
let result = Workflow::open_str(temp.path(), workflow);
assert!(result.is_err());

assert!(result.unwrap_err().to_string().contains("missing name"));
}

#[test]
#[parallel]
fn action_no_command() {
let temp = TempDir::new().unwrap();
let workflow = r#"
[[action]]
name = "a"
"#;
let result = Workflow::open_str(temp.path(), workflow);
assert!(result.is_err());

assert!(result.unwrap_err().to_string().contains("missing command"));
}

#[test]
#[parallel]
fn group_defaults() {
Expand Down Expand Up @@ -1296,6 +1331,33 @@ command = "c"
assert_eq!(submit_options.partition, Some("i".to_string()));
}

#[test]
#[parallel]
fn empty_action_default() {
let temp = TempDir::new().unwrap();
let workflow = r#"
[default.action]
"#;

let workflow = Workflow::open_str(temp.path(), workflow).unwrap();

assert_eq!(workflow.action.len(), 0);

let action = workflow.default.action;
assert_eq!(action.name, None);
assert_eq!(action.command, None);
assert_eq!(action.launchers, None);
assert_eq!(action.previous_actions, None);
assert_eq!(action.products, None);
assert_eq!(action.resources.processes, None);
assert_eq!(action.resources.threads_per_process, None);
assert_eq!(action.resources.gpus_per_process, None);
assert_eq!(action.resources.walltime, None);
assert!(action.submit_options.is_empty());
// TODO: Group
assert_eq!(action.from, None);
}

// TODO: Test action default all keys
// TODO: Test action from all keys
// TODO: Test action override from
Expand Down

0 comments on commit 387a58e

Please sign in to comment.