Test saving and loading of LoginParam

This commit is contained in:
link2xt
2021-04-15 02:56:08 +03:00
parent ac54301923
commit a795ae98ee
2 changed files with 40 additions and 5 deletions

View File

@@ -30,7 +30,7 @@ impl Default for CertificateChecks {
} }
/// Login parameters for a single server, either IMAP or SMTP /// Login parameters for a single server, either IMAP or SMTP
#[derive(Default, Debug, Clone)] #[derive(Default, Debug, Clone, PartialEq)]
pub struct ServerLoginParam { pub struct ServerLoginParam {
pub server: String, pub server: String,
pub user: String, pub user: String,
@@ -43,7 +43,7 @@ pub struct ServerLoginParam {
pub certificate_checks: CertificateChecks, pub certificate_checks: CertificateChecks,
} }
#[derive(Default, Debug, Clone)] #[derive(Default, Debug, Clone, PartialEq)]
pub struct LoginParam { pub struct LoginParam {
pub addr: String, pub addr: String,
pub imap: ServerLoginParam, pub imap: ServerLoginParam,
@@ -304,6 +304,8 @@ pub fn dc_build_tls(strict_tls: bool) -> async_native_tls::TlsConnector {
mod tests { mod tests {
use super::*; use super::*;
use crate::test_utils::TestContext;
#[test] #[test]
fn test_certificate_checks_display() { fn test_certificate_checks_display() {
use std::string::ToString; use std::string::ToString;
@@ -313,4 +315,37 @@ mod tests {
CertificateChecks::AcceptInvalidCertificates.to_string() CertificateChecks::AcceptInvalidCertificates.to_string()
); );
} }
#[async_std::test]
async fn test_save_load_login_param() -> anyhow::Result<()> {
let t = TestContext::new().await;
let param = LoginParam {
addr: "alice@example.com".to_string(),
imap: ServerLoginParam {
server: "imap.example.com".to_string(),
user: "alice".to_string(),
password: "foo".to_string(),
port: 123,
security: Socket::Starttls,
certificate_checks: CertificateChecks::Strict,
},
smtp: ServerLoginParam {
server: "smtp.example.com".to_string(),
user: "alice@example.com".to_string(),
password: "bar".to_string(),
port: 456,
security: Socket::Ssl,
certificate_checks: CertificateChecks::AcceptInvalidCertificates,
},
server_flags: 0,
provider: get_provider_by_id("example.com"),
};
param.save_to_database(&t, "foobar_").await?;
let loaded = LoginParam::from_database(&t, "foobar_").await?;
assert_eq!(param, loaded);
Ok(())
}
} }

View File

@@ -51,7 +51,7 @@ pub enum Oauth2Authorizer {
Gmail = 2, Gmail = 2,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone, PartialEq)]
pub struct Server { pub struct Server {
pub protocol: Protocol, pub protocol: Protocol,
pub socket: Socket, pub socket: Socket,
@@ -60,13 +60,13 @@ pub struct Server {
pub username_pattern: UsernamePattern, pub username_pattern: UsernamePattern,
} }
#[derive(Debug)] #[derive(Debug, PartialEq)]
pub struct ConfigDefault { pub struct ConfigDefault {
pub key: Config, pub key: Config,
pub value: &'static str, pub value: &'static str,
} }
#[derive(Debug)] #[derive(Debug, PartialEq)]
pub struct Provider { pub struct Provider {
/// Unique ID, corresponding to provider database filename. /// Unique ID, corresponding to provider database filename.
pub id: &'static str, pub id: &'static str,