Skip to content

Commit 2839ba7

Browse files
committed
Revert "test_config_loading_from_multiple_sources fixed"
This reverts commit 01b8809.
1 parent 01b8809 commit 2839ba7

1 file changed

Lines changed: 15 additions & 27 deletions

File tree

src/config.rs

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,6 @@ mod test {
184184
use std::io::Write;
185185
use tempfile::Builder;
186186

187-
use std::sync::Mutex;
188-
189-
static ENV_LOCK: Mutex<()> = Mutex::new(());
190-
191187
const CONFIG_STR1: &str = "
192188
datasource:
193189
url: 'https:/a.b'
@@ -279,7 +275,6 @@ mod test {
279275
/// Test merging config with env vars
280276
#[test]
281277
fn test_merge_env() {
282-
let _lock = ENV_LOCK.lock().unwrap();
283278
// Create a file inside of `std::env::temp_dir()`.
284279
let mut config_file = Builder::new().suffix(".yaml").tempfile().unwrap();
285280

@@ -288,7 +283,7 @@ mod test {
288283
env::set_var("MP_STATUS_DASHBOARD__SECRET", "val");
289284
let _config = config::Config::new(config_file.path().to_str().unwrap()).unwrap();
290285
assert_eq!(_config.status_dashboard.unwrap().secret.unwrap(), "val");
291-
286+
292287
// Clean up to avoid affecting other tests
293288
env::remove_var("MP_STATUS_DASHBOARD__SECRET");
294289
}
@@ -364,13 +359,13 @@ mod test {
364359
health_metrics: {}
365360
";
366361
let config = config::Config::from_config_str(minimal_config);
367-
362+
368363
// Verify default server address
369364
assert_eq!("0.0.0.0", config.server.address);
370-
365+
371366
// Verify default server port
372367
assert_eq!(3000, config.server.port);
373-
368+
374369
// Verify default datasource timeout
375370
assert_eq!(10, config.datasource.timeout);
376371
}
@@ -390,7 +385,7 @@ mod test {
390385
health_metrics: {}
391386
";
392387
let config = config::Config::from_config_str(config_str);
393-
388+
394389
let socket_addr = config.get_socket_addr();
395390
assert_eq!("127.0.0.1:8080", socket_addr.to_string());
396391
}
@@ -400,16 +395,15 @@ mod test {
400395
/// but we add an explicit comprehensive test
401396
#[test]
402397
fn test_config_loading_from_multiple_sources() {
403-
let _lock = ENV_LOCK.lock().unwrap();
404398
// Create temporary directory structure
405399
let dir = Builder::new().tempdir().unwrap();
406400
let main_config_path = dir.path().join("config.yaml");
407401
let mut main_config = File::create(&main_config_path).unwrap();
408-
402+
409403
// Create conf.d directory
410404
let confd_path = dir.path().join("conf.d");
411405
create_dir(&confd_path).expect("Cannot create conf.d");
412-
406+
413407
// Write main config with all required fields
414408
let main_config_content = "
415409
datasource:
@@ -427,10 +421,7 @@ mod test {
427421
- name: prod
428422
health_metrics: {}
429423
";
430-
main_config
431-
.write_all(main_config_content.as_bytes())
432-
.unwrap();
433-
main_config.sync_all().unwrap();
424+
main_config.write_all(main_config_content.as_bytes()).unwrap();
434425
// Ensure file is flushed and closed before reading
435426
drop(main_config);
436427

@@ -445,36 +436,33 @@ mod test {
445436
- name: prod
446437
";
447438
let mut flags_config = File::create(confd_path.join("flags.yaml")).unwrap();
448-
flags_config
449-
.write_all(flags_config_content.as_bytes())
450-
.unwrap();
451-
flags_config.sync_all().unwrap();
439+
flags_config.write_all(flags_config_content.as_bytes()).unwrap();
452440
// Ensure file is flushed and closed before reading
453441
drop(flags_config);
454442

455443
// Set environment variables to ensure required fields are present
456444
// This makes the test independent of any pre-existing env vars
457445
env::set_var("MP_DATASOURCE__URL", "https://graphite.example.com");
458446
env::set_var("MP_SERVER__PORT", "8080");
459-
447+
460448
// Load config from all sources
461449
let config = config::Config::new(main_config_path.to_str().unwrap()).unwrap();
462-
450+
463451
// Verify datasource config (env var ensures this is set)
464452
assert_eq!("https://graphite.example.com", config.datasource.url);
465453
assert_eq!(10, config.datasource.timeout);
466-
454+
467455
// Verify conf.d part merged
468456
assert_eq!(1, config.flag_metrics.len());
469457
assert_eq!("test-metric", config.flag_metrics[0].name);
470-
458+
471459
// Verify environment variable merged (overrides main config)
472460
assert_eq!(8080, config.server.port);
473-
461+
474462
// Clean up environment variables
475463
env::remove_var("MP_DATASOURCE__URL");
476464
env::remove_var("MP_SERVER__PORT");
477-
465+
478466
// Cleanup
479467
dir.close().unwrap();
480468
}

0 commit comments

Comments
 (0)