Move cluster configuration test to integration tests

This commit is contained in:
2026-11-30 00:53:05 +08:00
parent 351cc156dd
commit d31cd5615e
2 changed files with 41 additions and 43 deletions
-43
View File
@@ -227,46 +227,3 @@ fn sqlite_url(path: &str, read_only: bool) -> Result<Address, ConfigError> {
let mode = if read_only { "ro" } else { "rwc" };
Ok(Address(format!("sqlite:{file}?mode={mode}")))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn named_cluster_requires_matching_addresses_and_redacts_credentials() {
let mut config = DeploymentConfig {
cluster: Some("regional".into()),
clusters: BTreeMap::from([(
"regional".into(),
Cluster {
driver: Driver::Postgres,
primary: "postgres://user:secret@primary/bedrock".into(),
replicas: vec!["postgresql://reader:secret@replica/bedrock".into()],
tls: Tls::VerifyFull,
max_connections: 5,
},
)]),
..DeploymentConfig::default()
};
let resolved = config.resolve().unwrap();
assert!(
resolved
.primary
.connection_string()
.ends_with("sslmode=verify-full")
);
assert!(
resolved.replicas[0]
.connection_string()
.ends_with("sslmode=verify-full")
);
assert!(!format!("{resolved:?}").contains("secret"));
config.clusters.get_mut("regional").unwrap().replicas[0] =
"mysql://user:secret@replica/bedrock".into();
assert!(matches!(
config.resolve(),
Err(ConfigError::Url("postgres"))
));
}
}
@@ -0,0 +1,41 @@
use std::collections::BTreeMap;
use clusters::{Cluster, ConfigError, DeploymentConfig, Driver, Tls};
#[test]
fn named_cluster_requires_matching_addresses_and_redacts_credentials() {
let mut config = DeploymentConfig {
cluster: Some("regional".into()),
clusters: BTreeMap::from([(
"regional".into(),
Cluster {
driver: Driver::Postgres,
primary: "postgres://user:secret@primary/bedrock".into(),
replicas: vec!["postgresql://reader:secret@replica/bedrock".into()],
tls: Tls::VerifyFull,
max_connections: 5,
},
)]),
..DeploymentConfig::default()
};
let resolved = config.resolve().unwrap();
assert!(
resolved
.primary
.connection_string()
.ends_with("sslmode=verify-full")
);
assert!(
resolved.replicas[0]
.connection_string()
.ends_with("sslmode=verify-full")
);
assert!(!format!("{resolved:?}").contains("secret"));
config.clusters.get_mut("regional").unwrap().replicas[0] =
"mysql://user:secret@replica/bedrock".into();
assert!(matches!(
config.resolve(),
Err(ConfigError::Url("postgres"))
));
}