Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ approx = "0.4.0"
derive_more = "0.99.13"
function_name = "0.2.0"
futures = "0.3"
home = "0.5"
pretty_assertions = "0.7.1"
serde_json = "1.0.64"
semver = "1.0.0"
Expand Down
19 changes: 16 additions & 3 deletions src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ pub(crate) use self::{
},
};

use home::home_dir;
use lazy_static::lazy_static;

use self::util::TestLock;
use crate::{
client::options::{ServerApi, ServerApiVersion},
options::ClientOptions,
};
use std::str::FromStr;
use std::{fs::read_to_string, str::FromStr};

const MAX_POOL_SIZE: u32 = 100;

Expand All @@ -48,8 +49,7 @@ lazy_static! {
options
};
pub(crate) static ref LOCK: TestLock = TestLock::new();
pub(crate) static ref DEFAULT_URI: String =
std::env::var("MONGODB_URI").unwrap_or_else(|_| "mongodb://localhost:27017".to_string());
pub(crate) static ref DEFAULT_URI: String = get_default_uri();
pub(crate) static ref SERVER_API: Option<ServerApi> = match std::env::var("MONGODB_API_VERSION")
{
Ok(server_api_version) if !server_api_version.is_empty() => Some(ServerApi {
Expand All @@ -62,3 +62,16 @@ lazy_static! {
pub(crate) static ref SERVERLESS: bool =
matches!(std::env::var("SERVERLESS"), Ok(s) if s == "serverless");
}

fn get_default_uri() -> String {
if let Ok(uri) = std::env::var("MONGODB_URI") {
return uri;
}
if let Some(mut home) = home_dir() {
home.push(".mongodb_uri");
if let Ok(uri) = read_to_string(home) {
return uri;
}
}
return "mongodb://localhost:27017".to_string();
}