From 676c7b34dc12c3f16b01efc8d07a79f31fcf83bc Mon Sep 17 00:00:00 2001 From: Nathan Fisher Date: Wed, 7 Jun 2023 16:00:03 -0400 Subject: [PATCH] Status - complete test coverage --- src/status/mod.rs | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/src/status/mod.rs b/src/status/mod.rs index 36a3ed3..c1a1777 100644 --- a/src/status/mod.rs +++ b/src/status/mod.rs @@ -68,7 +68,7 @@ pub enum Redirect { /// The mailbox has moved to a different address, and all future /// messages should be sent to that address. Permanent = 1, - Other, + Other = 2, } impl TryFrom for Redirect { @@ -103,7 +103,7 @@ pub enum TemporaryFailure { RateLimit = 4, /// The mailbox isn't accepting mail right now, but it might in the future. MailboxFull = 5, - Other, + Other = 6, } impl TryFrom for TemporaryFailure { @@ -140,7 +140,7 @@ pub enum PermanentFailure { DomainNotServiced = 3, /// Your request is malformed, and won't be accepted by the mailserver. BadRequest = 9, - Other, + Other = 4, } impl TryFrom for PermanentFailure { @@ -178,7 +178,7 @@ pub enum AuthenticationFailure { /// The mailserver needs you to complete a task to confirm that you are a /// legitimate sender. (This is reserved for a Hashcash style anti-spam measure). ProofRequired = 4, - Other, + Other = 5, } impl TryFrom for AuthenticationFailure { @@ -209,8 +209,40 @@ mod tests { #[test] fn to_number_redirect() { - let num: u8 = Status::Redirect(Redirect::Temporary).into(); - assert_eq!(num, 30); + assert_eq!(u8::from(Status::Redirect(Redirect::Temporary)), 30); + assert_eq!(u8::from(Status::Redirect(Redirect::Permanent)), 31); + assert_eq!(u8::from(Status::Redirect(Redirect::Other)), 32); + } + + #[test] + fn to_number_temporary() { + assert_eq!(u8::from(Status::TemporaryFailure(TemporaryFailure::TemporaryError)), 40); + assert_eq!(u8::from(Status::TemporaryFailure(TemporaryFailure::ServerUnavailable)), 41); + assert_eq!(u8::from(Status::TemporaryFailure(TemporaryFailure::CgiError)), 42); + assert_eq!(u8::from(Status::TemporaryFailure(TemporaryFailure::ProxyError)), 43); + assert_eq!(u8::from(Status::TemporaryFailure(TemporaryFailure::RateLimit)), 44); + assert_eq!(u8::from(Status::TemporaryFailure(TemporaryFailure::MailboxFull)), 45); + assert_eq!(u8::from(Status::TemporaryFailure(TemporaryFailure::Other)), 46); + } + + #[test] + fn to_number_permanent() { + assert_eq!(u8::from(Status::PermanentFailure(PermanentFailure::PermanentError)), 50); + assert_eq!(u8::from(Status::PermanentFailure(PermanentFailure::MailboxNonexistent)), 51); + assert_eq!(u8::from(Status::PermanentFailure(PermanentFailure::MailboxGone)), 52); + assert_eq!(u8::from(Status::PermanentFailure(PermanentFailure::DomainNotServiced)), 53); + assert_eq!(u8::from(Status::PermanentFailure(PermanentFailure::BadRequest)), 59); + assert_eq!(u8::from(Status::PermanentFailure(PermanentFailure::Other)), 54); + } + + #[test] + fn to_number_auth() { + assert_eq!(u8::from(Status::AuthenticationFailure(AuthenticationFailure::CertificateRequired)), 60); + assert_eq!(u8::from(Status::AuthenticationFailure(AuthenticationFailure::UnauthorizedSender)), 61); + assert_eq!(u8::from(Status::AuthenticationFailure(AuthenticationFailure::CertificateInvalid)), 62); + assert_eq!(u8::from(Status::AuthenticationFailure(AuthenticationFailure::IdentityMismatch)), 63); + assert_eq!(u8::from(Status::AuthenticationFailure(AuthenticationFailure::ProofRequired)), 64); + assert_eq!(u8::from(Status::AuthenticationFailure(AuthenticationFailure::Other)), 65); } #[test]