Skip to content

Commit 0012818

Browse files
committed
progress
1 parent 3f539f1 commit 0012818

1 file changed

Lines changed: 0 additions & 115 deletions

File tree

crates/pgls_configuration/src/database.rs

Lines changed: 0 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -100,118 +100,3 @@ impl PartialDatabaseConfiguration {
100100
})
101101
}
102102
}
103-
104-
#[cfg(test)]
105-
mod tests {
106-
use super::*;
107-
use std::sync::Mutex;
108-
109-
static ENV_MUTEX: Mutex<()> = Mutex::new(());
110-
111-
const ALL_VARS: &[&str] = &[
112-
"DATABASE_URL",
113-
"PGHOST",
114-
"PGPORT",
115-
"PGUSER",
116-
"PGPASSWORD",
117-
"PGDATABASE",
118-
];
119-
120-
fn clear_env_vars() {
121-
for var in ALL_VARS {
122-
unsafe {
123-
std::env::remove_var(var);
124-
}
125-
}
126-
}
127-
128-
#[test]
129-
fn from_env_none_when_no_vars_set() {
130-
let _lock = ENV_MUTEX.lock().unwrap();
131-
clear_env_vars();
132-
133-
assert!(PartialDatabaseConfiguration::from_env().is_none());
134-
}
135-
136-
#[test]
137-
fn from_env_all_vars_set() {
138-
let _lock = ENV_MUTEX.lock().unwrap();
139-
clear_env_vars();
140-
141-
unsafe {
142-
std::env::set_var("DATABASE_URL", "postgres://u:p@h:1234/d");
143-
std::env::set_var("PGHOST", "myhost");
144-
std::env::set_var("PGPORT", "5433");
145-
std::env::set_var("PGUSER", "myuser");
146-
std::env::set_var("PGPASSWORD", "mypass");
147-
std::env::set_var("PGDATABASE", "mydb");
148-
}
149-
150-
let config = PartialDatabaseConfiguration::from_env().unwrap();
151-
assert_eq!(
152-
config.connection_string,
153-
Some("postgres://u:p@h:1234/d".to_string())
154-
);
155-
assert_eq!(config.host, Some("myhost".to_string()));
156-
assert_eq!(config.port, Some(5433));
157-
assert_eq!(config.username, Some("myuser".to_string()));
158-
assert_eq!(config.password, Some("mypass".to_string()));
159-
assert_eq!(config.database, Some("mydb".to_string()));
160-
161-
clear_env_vars();
162-
}
163-
164-
#[test]
165-
fn from_env_partial_vars() {
166-
let _lock = ENV_MUTEX.lock().unwrap();
167-
clear_env_vars();
168-
169-
unsafe {
170-
std::env::set_var("PGHOST", "remotehost");
171-
std::env::set_var("PGDATABASE", "appdb");
172-
}
173-
174-
let config = PartialDatabaseConfiguration::from_env().unwrap();
175-
assert_eq!(config.connection_string, None);
176-
assert_eq!(config.host, Some("remotehost".to_string()));
177-
assert_eq!(config.port, None);
178-
assert_eq!(config.username, None);
179-
assert_eq!(config.password, None);
180-
assert_eq!(config.database, Some("appdb".to_string()));
181-
182-
clear_env_vars();
183-
}
184-
185-
#[test]
186-
fn from_env_invalid_pgport_ignored() {
187-
let _lock = ENV_MUTEX.lock().unwrap();
188-
clear_env_vars();
189-
190-
unsafe {
191-
std::env::set_var("PGHOST", "localhost");
192-
std::env::set_var("PGPORT", "not_a_number");
193-
}
194-
195-
let config = PartialDatabaseConfiguration::from_env().unwrap();
196-
assert_eq!(config.host, Some("localhost".to_string()));
197-
assert_eq!(config.port, None);
198-
199-
clear_env_vars();
200-
}
201-
202-
#[test]
203-
fn from_env_only_invalid_pgport_returns_none() {
204-
let _lock = ENV_MUTEX.lock().unwrap();
205-
clear_env_vars();
206-
207-
unsafe {
208-
std::env::set_var("PGPORT", "not_a_number");
209-
}
210-
211-
// PGPORT is set but invalid — parse fails so it becomes None.
212-
// No other vars are set, so has_any is false.
213-
assert!(PartialDatabaseConfiguration::from_env().is_none());
214-
215-
clear_env_vars();
216-
}
217-
}

0 commit comments

Comments
 (0)