Skip to content

Commit

Permalink
partial rust impl test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mxfactorial committed Aug 13, 2023
1 parent bec0fb3 commit 19fe95e
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions crates/pg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,36 @@ impl DB {
}
}

#[cfg(test)]
mod tests {
use super::*;

use std::env;

#[test]
fn it_returns_a_conn_uri() {
env::set_var("PGUSER", "a");
env::set_var("PGPASSWORD", "b");
env::set_var("PGHOST", "c");
env::set_var("PGPORT", "d");
env::set_var("PGDATABASE", "e");
let got = DB::create_conn_uri_from_env_vars();
env::remove_var("PGUSER");
env::remove_var("PGPASSWORD");
env::remove_var("PGHOST");
env::remove_var("PGPORT");
env::remove_var("PGDATABASE");
let want = String::from("postgresql://a:b@c:d/e");
assert_eq!(got, want)
}

#[test]
#[should_panic]
fn it_panics_from_unset_env_var() {
DB::get_env_var("NOT_SET");
}
}

// https://github.com/tokio-rs/axum/blob/5793e75aacfeae16f02fea144ecc2ee7dcb12f55/examples/tokio-postgres/src/main.rs
#[derive(Clone)]
pub struct ConnectionPool(Pool<PostgresConnectionManager<NoTls>>);
Expand Down

0 comments on commit 19fe95e

Please sign in to comment.