Skip to content

Commit 47211af

Browse files
authored
Move environment parsing tests out of the unit test suite (#1438)
… since they can influence other tests.
2 parents b0a587f + 5b911aa commit 47211af

File tree

2 files changed

+78
-67
lines changed

2 files changed

+78
-67
lines changed

server/svix-server/src/cfg.rs

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ pub fn load() -> Result<Arc<ConfigurationInner>> {
452452

453453
#[cfg(test)]
454454
mod tests {
455-
use std::{sync::Arc, time::Duration};
455+
use std::sync::Arc;
456456

457457
use figment::{
458458
providers::{Format as _, Toml},
@@ -462,74 +462,8 @@ mod tests {
462462
use super::{load, CacheBackend, CacheType, QueueBackend, QueueType};
463463
use crate::core::security::{JWTAlgorithm, JwtSigningConfig};
464464

465-
#[test]
466-
fn test_retry_schedule_parsing() {
467-
figment::Jail::expect_with(|jail| {
468-
jail.set_env("SVIX_JWT_SECRET", "x");
469-
470-
// Multi item
471-
jail.set_env("SVIX_RETRY_SCHEDULE", "[1,2]");
472-
473-
let cfg = load().unwrap();
474-
assert_eq!(
475-
cfg.retry_schedule,
476-
vec![Duration::new(1, 0), Duration::new(2, 0)]
477-
);
478-
479-
// Single item
480-
jail.set_env("SVIX_RETRY_SCHEDULE", "[1]");
481-
482-
let cfg = load().unwrap();
483-
assert_eq!(cfg.retry_schedule, vec![Duration::new(1, 0)]);
484-
485-
// Empty
486-
jail.set_env("SVIX_RETRY_SCHEDULE", "[]");
487-
488-
let cfg = load().unwrap();
489-
assert!(cfg.retry_schedule.is_empty());
490-
491-
Ok(())
492-
});
493-
}
494-
495-
#[test]
496-
fn test_retry_schedule_parsing_legacy() {
497-
figment::Jail::expect_with(|jail| {
498-
jail.set_env("SVIX_JWT_SECRET", "x");
499-
500-
// Multi item
501-
jail.set_env("SVIX_RETRY_SCHEDULE", "1,2");
502-
503-
let cfg = load().unwrap();
504-
assert_eq!(
505-
cfg.retry_schedule,
506-
vec![Duration::new(1, 0), Duration::new(2, 0)]
507-
);
508-
509-
// Single item and empty were failing before so not testing them
510-
511-
Ok(())
512-
});
513-
}
514-
515-
#[test]
516-
fn test_proxy_addr_from_env_parsing() {
517-
figment::Jail::expect_with(|jail| {
518-
jail.set_env("SVIX_QUEUE_TYPE", "memory");
519-
jail.set_env("SVIX_JWT_SECRET", "x");
520-
jail.set_env("SVIX_PROXY_ADDR", "socks5://127.0.0.1");
521-
522-
let cfg = load().unwrap();
523-
assert!(cfg.proxy_config.is_some());
524-
525-
Ok(())
526-
});
527-
}
528-
529465
#[test]
530466
fn test_cache_or_queue_dsn_priority() {
531-
// NOTE: Does not use `figment::Jail` like the above because set env vars will leak into
532-
// other tests overwriting real configurations
533467
let mut cfg = load().unwrap();
534468
let cfg = Arc::make_mut(&mut cfg);
535469

server/svix-server/tests/config.rs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
use std::time::Duration;
2+
3+
use svix_server::cfg::load;
4+
5+
// Using a single test in its own integration test binary such that
6+
// `figment::Jail` can't influence other tests.
7+
//
8+
// The only thing it does is save & restore things, it doesn't actually have any
9+
// protections against `jail.set_env` values being seen by other tests -
10+
// internally it calls `std::env::set_var`.
11+
#[test]
12+
fn test_environment_parsing() {
13+
test_retry_schedule_parsing();
14+
test_retry_schedule_parsing_legacy();
15+
test_proxy_addr_from_env_parsing();
16+
}
17+
18+
fn test_retry_schedule_parsing() {
19+
figment::Jail::expect_with(|jail| {
20+
jail.set_env("SVIX_JWT_SECRET", "x");
21+
22+
// Multi item
23+
jail.set_env("SVIX_RETRY_SCHEDULE", "[1,2]");
24+
25+
let cfg = load().unwrap();
26+
assert_eq!(
27+
cfg.retry_schedule,
28+
vec![Duration::new(1, 0), Duration::new(2, 0)]
29+
);
30+
31+
// Single item
32+
jail.set_env("SVIX_RETRY_SCHEDULE", "[1]");
33+
34+
let cfg = load().unwrap();
35+
assert_eq!(cfg.retry_schedule, vec![Duration::new(1, 0)]);
36+
37+
// Empty
38+
jail.set_env("SVIX_RETRY_SCHEDULE", "[]");
39+
40+
let cfg = load().unwrap();
41+
assert!(cfg.retry_schedule.is_empty());
42+
43+
Ok(())
44+
});
45+
}
46+
47+
fn test_retry_schedule_parsing_legacy() {
48+
figment::Jail::expect_with(|jail| {
49+
jail.set_env("SVIX_JWT_SECRET", "x");
50+
51+
// Multi item
52+
jail.set_env("SVIX_RETRY_SCHEDULE", "1,2");
53+
54+
let cfg = load().unwrap();
55+
assert_eq!(
56+
cfg.retry_schedule,
57+
vec![Duration::new(1, 0), Duration::new(2, 0)]
58+
);
59+
60+
// Single item and empty were failing before so not testing them
61+
62+
Ok(())
63+
});
64+
}
65+
66+
fn test_proxy_addr_from_env_parsing() {
67+
figment::Jail::expect_with(|jail| {
68+
jail.set_env("SVIX_QUEUE_TYPE", "memory");
69+
jail.set_env("SVIX_JWT_SECRET", "x");
70+
jail.set_env("SVIX_PROXY_ADDR", "socks5://127.0.0.1");
71+
72+
let cfg = load().unwrap();
73+
assert!(cfg.proxy_config.is_some());
74+
75+
Ok(())
76+
});
77+
}

0 commit comments

Comments
 (0)