Skip to content

Commit

Permalink
fix: additional test
Browse files Browse the repository at this point in the history
  • Loading branch information
conblem committed Feb 12, 2021
1 parent a5c7fc1 commit ceebbcc
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 14 deletions.
15 changes: 2 additions & 13 deletions src/api/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,8 @@ fn create_server_config(db_cert: &Cert) -> Result<Arc<ServerConfig>> {
#[cfg(test)]
mod tests {
use super::create_server_config;
use crate::facade::{Cert, State};
use crate::util::{now, to_i64};

fn create_cert() -> Cert {
Cert {
id: "1".to_owned(),
update: to_i64(&now()),
state: State::Ok,
cert: Some(include_str!("../../tests/cert.crt").to_owned()),
private: Some(include_str!("../../tests/key.key").to_owned()),
domain: "acme-dns-rust.com".to_owned(),
}
}
use crate::facade::cert::tests::create_cert;
use crate::facade::Cert;

#[test]
fn test_create_server_config_alpn() {
Expand Down
46 changes: 46 additions & 0 deletions src/facade/cert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,49 @@ impl CertFacade for InMemoryFacade {
Ok(())
}
}

#[cfg(test)]
pub(crate) mod tests {
use testcontainers::*;

use super::{Cert, CertFacade, DatabaseFacade, State};
use crate::setup_database;
use crate::util::{now, to_i64};

pub(crate) fn create_cert() -> Cert {
Cert {
id: "1".to_owned(),
update: to_i64(&now()),
state: State::Ok,
cert: Some(include_str!("../../tests/cert.crt").to_owned()),
private: Some(include_str!("../../tests/key.key").to_owned()),
domain: "acme-dns-rust.com".to_owned(),
}
}

#[cfg(not(feature = "disable-docker"))]
//#[tokio::test]
async fn _test_postgres_cert_facade() {
let docker = clients::Cli::default();
let node = docker.run(images::postgres::Postgres::default());

let connection_string = &format!(
"postgres://postgres:postgres@localhost:{}/postgres",
node.get_host_port(5432).unwrap()
);

let pool = setup_database(connection_string).await.unwrap();
let facade = DatabaseFacade::from(pool);
let mut cert = create_cert();

facade.create_cert(&cert).await.unwrap();

let actual = facade.first_cert().await.unwrap().unwrap();
assert_eq!(cert, actual);

cert.state = State::Updating;
facade.update_cert(&cert).await.unwrap();
let actual = facade.first_cert().await.unwrap().unwrap();
assert_eq!(cert, actual);
}
}
2 changes: 1 addition & 1 deletion src/facade/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use sqlx::{Database, PgPool, Pool, Postgres};
use std::collections::HashMap;
use std::sync::Arc;

mod cert;
pub(crate) mod cert;
mod domain;

pub use cert::{Cert, CertFacade, State};
Expand Down

0 comments on commit ceebbcc

Please sign in to comment.