Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions crates/cli/src/commands/apply_migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ pub struct ApplyMigrationArgs {
/// Print verbose output
#[clap(long)]
pub(crate) verbose: bool,
// Capture remaining arguments
#[arg(trailing_var_arg = true, allow_hyphen_values = true, index = 2)]
pub(crate) inputs: Vec<String>,
}

impl ApplyMigrationArgs {
Expand Down Expand Up @@ -104,3 +107,27 @@ pub(crate) async fn run_apply_migration(

Ok(workflow_status.clone())
}

#[cfg(test)]
mod tests {
use super::*;
use anyhow::Result;
use clap::{Arg, ArgAction, Command, FromArgMatches};

#[test]
fn test_arg_parsing() -> Result<()> {
let args = ApplyMigrationArgs::augment_args(Command::new("test"));

let matches =
args.get_matches_from(vec!["test", "--watch", "--test", "bob", "--suzy=queue"]);

let apply_args = ApplyMigrationArgs::from_arg_matches(&matches)?;

println!("{:?}", apply_args);

// assert_eq!(payload.get("test").unwrap().as_str().unwrap(), "bob");
// assert_eq!(payload.get("suzy").unwrap().as_str().unwrap(), "queue");

Ok(())
}
}
1 change: 1 addition & 0 deletions crates/cli/src/commands/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ pub(crate) async fn run_plumbing(
workflow_id: None,
verbose: true,
watch: false,
inputs: vec![],
},
emitter,
execution_id.clone(),
Expand Down
29 changes: 19 additions & 10 deletions crates/cli/src/workflows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,20 @@ where
);
}

let auth = updater.get_valid_auth().await.map_err(|_| {
anyhow::anyhow!(
let auth = updater.get_valid_auth().await;
if auth.is_err() {
log::warn!(
"No valid authentication token found, please run {}",
style("grit auth login").bold().red()
)
})?;
);
}

if let Some(username) = auth.get_user_name()? {
if !arg.input.contains_key(GRIT_VCS_USER_NAME) {
arg.input
.insert(GRIT_VCS_USER_NAME.to_string(), username.into());
if let Ok(ref auth) = auth {
if let Some(username) = auth.get_user_name()? {
if !arg.input.contains_key(GRIT_VCS_USER_NAME) {
arg.input
.insert(GRIT_VCS_USER_NAME.to_string(), username.into());
}
}
}

Expand Down Expand Up @@ -157,11 +160,17 @@ where

let mut final_child = child
.env(ENV_VAR_GRIT_API_URL, get_grit_api_url())
.env(ENV_VAR_GRIT_AUTH_TOKEN, auth.access_token)
.env(ENV_GRIT_WORKSPACE_ROOT, root)
.arg("--file")
.arg(&tempfile_path)
.kill_on_drop(true)
.kill_on_drop(true);

let mut final_child = if let Ok(auth) = auth {
final_child.env(ENV_VAR_GRIT_AUTH_TOKEN, auth.access_token)
} else {
final_child
};
let mut final_child = final_child
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
Expand Down
55 changes: 55 additions & 0 deletions crates/cli_bin/tests/workflows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,58 @@ fn applies_user_workflows() -> Result<()> {

Ok(())
}

#[test]
fn run_workflow_input() -> Result<()> {
let (_temp_dir, temp_fixtures_root) = get_fixture("grit_modules", true)?;

let mut cmd = get_test_cmd()?;
cmd.arg("apply")
.arg("https://storage.googleapis.com/grit-workflows-dev-workflow_definitions/test/hello.js")
.arg("--input")
.arg("{\"query\": \"John\"}")
.current_dir(temp_fixtures_root);

let output = cmd.output()?;
println!("stdout: {:?}", String::from_utf8(output.stdout.clone())?);
println!("stderr: {:?}", String::from_utf8(output.stderr.clone())?);

assert!(
output.status.success(),
"Command didn't finish successfully"
);

let stdout = String::from_utf8(output.stdout)?;
assert!(stdout.contains("Running hello workflow"),);

assert!(stdout.contains("John as the query"));

Ok(())
}

#[test]
fn run_workflow_arg_input() -> Result<()> {
let (_temp_dir, temp_fixtures_root) = get_fixture("grit_modules", true)?;

let mut cmd = get_test_cmd()?;
cmd.arg("apply")
.arg("https://storage.googleapis.com/grit-workflows-dev-workflow_definitions/test/hello.js")
.arg("--query=John")
.current_dir(temp_fixtures_root);

let output = cmd.output()?;
println!("stdout: {:?}", String::from_utf8(output.stdout.clone())?);
println!("stderr: {:?}", String::from_utf8(output.stderr.clone())?);

assert!(
output.status.success(),
"Command didn't finish successfully"
);

let stdout = String::from_utf8(output.stdout)?;
assert!(stdout.contains("Running hello workflow"),);

assert!(stdout.contains("John as the query"));

Ok(())
}