Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
quambene committed Apr 3, 2024
1 parent 2b77593 commit 1d4fd64
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub mod val {
}

pub fn value<'a>(name: &str, matches: &'a ArgMatches) -> Result<&'a str, anyhow::Error> {
match matches.get_one::<&str>(name) {
match matches.get_one::<String>(name) {
Some(query) => Ok(query),
None => Err(anyhow!("Missing value for argument '{}'", name)),
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub fn connect(matches: &ArgMatches) -> Result<(), anyhow::Error> {
}

if matches.contains_id(cmd::CONNECT) {
match matches.get_one::<&str>(cmd::CONNECT) {
match matches.get_one::<String>(cmd::CONNECT) {
Some(connection) => match connection.to_lowercase().as_str() {
val::SMTP => {
let _client = SmtpClient::new()?;
Expand Down
10 changes: 6 additions & 4 deletions src/cmd/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ pub fn query(matches: &ArgMatches) -> Result<(), anyhow::Error> {
}

if matches.contains_id(cmd::QUERY) {
match matches.get_one::<&str>(cmd::QUERY) {
match matches.get_one::<String>(cmd::QUERY) {
Some(query) => {
let now = Utc::now();
let conn_vars = ConnVars::from_env()?;
let ssh_tunnel = matches.get_one::<&str>(arg::SSH_TUNNEL).copied();
let ssh_tunnel = matches
.get_one::<String>(arg::SSH_TUNNEL)
.map(|arg| arg.as_ref());
let connection = DbConnection::new(&conn_vars, ssh_tunnel)?;
let mut df_query = sources::query_postgres(&connection, query)?;

Expand All @@ -29,8 +31,8 @@ pub fn query(matches: &ArgMatches) -> Result<(), anyhow::Error> {
let save_dir = Path::new(arg::value(arg::SAVE_DIR, matches)?);

// If argument 'FILE_TYPE' is not present the default value 'csv' will be used
match matches.get_one::<&str>(arg::FILE_TYPE) {
Some(file_type) => match *file_type {
match matches.get_one::<String>(arg::FILE_TYPE) {
Some(file_type) => match file_type.as_ref() {
"csv" => {
sources::write_csv(&mut df_query, save_dir, now)?;
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub fn read(matches: &ArgMatches) -> Result<(), anyhow::Error> {
}

if matches.contains_id(cmd::READ) {
match matches.get_one::<&str>(cmd::READ) {
match matches.get_one::<String>(cmd::READ) {
Some(csv_file) => {
let path = PathBuf::from(csv_file);
let csv = sources::read_csv(&path)?;
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn send(matches: &ArgMatches) -> Result<(), anyhow::Error> {
let sender = Sender(arg::value(arg::SENDER, matches)?);
let receiver = Receiver(arg::value(arg::RECEIVER, matches)?);
let message = Message::from_args(matches)?;
let attachment = matches.get_one::<&str>(arg::ATTACHMENT).map(Path::new);
let attachment = matches.get_one::<String>(arg::ATTACHMENT).map(Path::new);
let mime_format = MimeFormat::new(sender, receiver, &message, attachment, now)?;
let email = Email::new(sender, receiver, &message, &mime_format)?;

Expand Down
8 changes: 5 additions & 3 deletions src/cmd/send_bulk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ pub fn send_bulk(matches: &ArgMatches) -> Result<(), anyhow::Error> {
let sender = Sender(arg::value(arg::SENDER, matches)?);
let receivers = BulkReceiver::from_args(matches)?;
let message = Message::from_args(matches)?;
let attachment = matches.get_one::<&str>(arg::ATTACHMENT).map(Path::new);
let attachment = matches.get_one::<String>(arg::ATTACHMENT).map(Path::new);

let bulk_email = if matches.contains_id(arg::PERSONALIZE) {
if let Some(personalized_columns) = matches.get_many::<&str>(arg::PERSONALIZE) {
let personalized_columns = personalized_columns.copied().collect::<Vec<_>>();
if let Some(personalized_columns) = matches.get_many::<String>(arg::PERSONALIZE) {
let personalized_columns = personalized_columns
.map(|arg| arg.as_ref())
.collect::<Vec<_>>();
BulkEmail::new(
sender,
&receivers,
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/simple_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn simple_query(matches: &ArgMatches) -> Result<(), anyhow::Error> {

if matches.contains_id(cmd::SIMPLE_QUERY) {
let conn_vars = ConnVars::from_env()?;
let simple_query = match matches.get_one::<&str>(cmd::SIMPLE_QUERY) {
let simple_query = match matches.get_one::<String>(cmd::SIMPLE_QUERY) {
Some(query) => query,
None => {
return Err(anyhow!(
Expand Down
10 changes: 5 additions & 5 deletions src/email_builder/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ impl Message {
pub fn from_args(matches: &ArgMatches) -> Result<Self, anyhow::Error> {
if matches.contains_id(arg::SUBJECT) && matches.contains_id(arg::CONTENT) {
match (
matches.get_one::<&str>(arg::SUBJECT),
matches.get_one::<&str>(arg::CONTENT),
matches.get_one::<String>(arg::SUBJECT),
matches.get_one::<String>(arg::CONTENT),
) {
(Some(subject), Some(content)) => {
let message = Message::new(*subject, Some(content), None);
let message = Message::new(subject, Some(content), None);
Ok(message)
}
(Some(_), None) => Err(anyhow!("Missing value for argument '{}'", arg::CONTENT)),
Expand All @@ -72,8 +72,8 @@ impl Message {
&& (matches.contains_id(arg::TEXT_FILE) || matches.contains_id(arg::HTML_FILE))
{
let subject = arg::value(arg::SUBJECT, matches)?;
let text_path = matches.get_one::<&str>(arg::TEXT_FILE).map(Path::new);
let html_path = matches.get_one::<&str>(arg::HTML_FILE).map(Path::new);
let text_path = matches.get_one::<String>(arg::TEXT_FILE).map(Path::new);
let html_path = matches.get_one::<String>(arg::HTML_FILE).map(Path::new);
let text = if let Some(path) = text_path {
Some(utils::read_file(path)?)
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/email_builder/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ impl BulkReceiver {

pub fn from_args(matches: &ArgMatches) -> Result<Self, anyhow::Error> {
let column_name = arg::value(arg::RECEIVER_COLUMN, matches)?;
let receiver_query = matches.get_one::<&str>(arg::RECEIVER_QUERY);
let receiver_path = matches.get_one::<&str>(arg::RECEIVER_FILE).map(Path::new);
let receiver_query = matches.get_one::<String>(arg::RECEIVER_QUERY);
let receiver_path = matches.get_one::<String>(arg::RECEIVER_FILE).map(Path::new);

match (receiver_query, receiver_path) {
(Some(query), None) => {
let conn_vars = ConnVars::from_env()?;
let ssh_tunnel = matches.get_one::<&str>(arg::SSH_TUNNEL).copied();
let ssh_tunnel = matches.get_one::<String>(arg::SSH_TUNNEL).map(|arg| arg.as_ref());
let connection = DbConnection::new(&conn_vars, ssh_tunnel)?;
let df_receiver = sources::query_postgres(&connection, query)?;

Expand Down

0 comments on commit 1d4fd64

Please sign in to comment.