fixup tests

This commit is contained in:
Wez Furlong
2023-02-12 15:26:24 -07:00
parent 79816d9479
commit 3bddce299a
3 changed files with 10 additions and 12 deletions
+3 -9
View File
@@ -303,14 +303,11 @@ mod test {
);
assert_equal!(
Command::parse("MAIL From:<>").unwrap(),
Command::Mail(EnvelopeAddress::Null)
Command::Mail(EnvelopeAddress::null_sender())
);
assert_equal!(
Command::parse("MAIL From:<user@example.com>").unwrap(),
Command::Mail(EnvelopeAddress::Mailbox {
user: "user".to_string(),
domain: "example.com".to_string()
})
Command::Mail(EnvelopeAddress::parse("user@example.com").unwrap())
);
assert_equal!(
Command::parse("rcpt to:<>").unwrap_err().to_string(),
@@ -318,10 +315,7 @@ mod test {
);
assert_equal!(
Command::parse("rcpt TO:<user@example.com>").unwrap(),
Command::Rcpt(EnvelopeAddress::Mailbox {
user: "user".to_string(),
domain: "example.com".to_string()
})
Command::Rcpt(EnvelopeAddress::parse("user@example.com").unwrap())
);
}
}
+5 -1
View File
@@ -8,7 +8,7 @@ pub struct EnvelopeAddress(String);
impl EnvelopeAddress {
pub fn parse(text: &str) -> anyhow::Result<Self> {
if text.is_empty() {
Ok(Self("".to_string()))
Ok(Self::null_sender())
} else {
let fields: Vec<&str> = text.split('@').collect();
anyhow::ensure!(fields.len() == 2, "expected user@domain");
@@ -30,6 +30,10 @@ impl EnvelopeAddress {
None => "",
}
}
pub fn null_sender() -> Self {
Self("".to_string())
}
}
impl UserData for EnvelopeAddress {
+2 -2
View File
@@ -1,5 +1,5 @@
pub mod address;
pub mod message;
pub use address::EnvelopeAddress;
pub use message::Message;
pub use crate::address::EnvelopeAddress;
pub use crate::message::Message;