Add a versioned backend catalog and YAML deployment configuration
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use clusters::{Address, Cluster, ConfigError, DeploymentConfig, Driver, Tls};
|
||||
use clusters::{Address, Cluster, ConfigError, DeploymentConfig, SqlDriver, Tls};
|
||||
|
||||
#[test]
|
||||
fn address_debug_formats_the_inner_string() {
|
||||
@@ -15,7 +15,7 @@ fn named_cluster_requires_matching_addresses() {
|
||||
clusters: BTreeMap::from([(
|
||||
"regional".into(),
|
||||
Cluster {
|
||||
driver: Driver::Postgres,
|
||||
driver: SqlDriver::Postgres,
|
||||
primary: "postgres://user:secret@primary/bedrock".into(),
|
||||
replicas: vec!["postgresql://reader:secret@replica/bedrock".into()],
|
||||
tls: Tls::VerifyFull,
|
||||
@@ -25,6 +25,7 @@ fn named_cluster_requires_matching_addresses() {
|
||||
..DeploymentConfig::default()
|
||||
};
|
||||
let resolved = config.resolve().unwrap();
|
||||
let resolved = resolved.documents().unwrap();
|
||||
assert!(
|
||||
resolved
|
||||
.primary
|
||||
@@ -43,3 +44,82 @@ fn named_cluster_requires_matching_addresses() {
|
||||
Err(ConfigError::Url("postgres"))
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resolves_named_connections_and_round_trips_yaml() {
|
||||
use clusters::ConfigFormat;
|
||||
|
||||
let config = DeploymentConfig::parse(
|
||||
include_str!("../../../deploy/multi-storage.yaml"),
|
||||
ConfigFormat::Yaml,
|
||||
)
|
||||
.unwrap();
|
||||
let snapshot = config.resolve().unwrap();
|
||||
assert_eq!(snapshot.config_version, "example-1");
|
||||
assert_eq!(snapshot.documents().unwrap().driver, SqlDriver::Postgres);
|
||||
assert_eq!(snapshot.sql["legacy"].driver, SqlDriver::Mysql);
|
||||
assert_eq!(
|
||||
snapshot.object_storage["attachments"].bucket,
|
||||
"bedrock-attachments"
|
||||
);
|
||||
assert_eq!(snapshot.documents().unwrap().max_connections, 5);
|
||||
|
||||
let serialized = config.to_yaml().unwrap();
|
||||
let roundtrip = DeploymentConfig::parse(&serialized, ConfigFormat::Yaml)
|
||||
.unwrap()
|
||||
.resolve()
|
||||
.unwrap();
|
||||
assert_eq!(roundtrip.sql["legacy"].driver, SqlDriver::Mysql);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn imports_catalog_atomically_and_preserves_role_references() {
|
||||
use clusters::{ConfigFormat, Driver, ImportFormat, ObjectStoreDriver, Resource};
|
||||
|
||||
let mut config =
|
||||
DeploymentConfig::parse("config_version = 'test'", ConfigFormat::Toml).unwrap();
|
||||
config
|
||||
.import_resources(
|
||||
include_str!("../../../deploy/kubernetes-catalog.yaml"),
|
||||
ImportFormat::KubernetesConfigMap,
|
||||
)
|
||||
.unwrap();
|
||||
config.sql.insert("documents".into(), "pg-main".into());
|
||||
|
||||
let before = config.resource("attachments").unwrap().driver();
|
||||
assert_eq!(before, Driver::ObjectStore(ObjectStoreDriver::S3));
|
||||
assert!(matches!(
|
||||
config.remove_resource("pg-main"),
|
||||
Err(ConfigError::ResourceInUse)
|
||||
));
|
||||
|
||||
let inventory = r#"{
|
||||
"bedrock_resources": {
|
||||
"value": {
|
||||
"another-bucket": {"kind":"object_store","driver":"s3","bucket":"other","region":"us-east-1"},
|
||||
"attachments": {"kind":"object_store","driver":"s3","bucket":"duplicate","region":"us-east-1"}
|
||||
}
|
||||
}
|
||||
}"#;
|
||||
assert!(
|
||||
config
|
||||
.import_resources(inventory, ImportFormat::TerraformOutputs)
|
||||
.is_err()
|
||||
);
|
||||
assert!(config.resource("another-bucket").is_none());
|
||||
let Resource::ObjectStore(mut updated) = config.remove_resource("attachments").unwrap() else {
|
||||
panic!("expected S3 configuration");
|
||||
};
|
||||
updated.bucket = "updated".into();
|
||||
config
|
||||
.insert_resource("attachments".into(), Resource::ObjectStore(updated.clone()))
|
||||
.unwrap();
|
||||
updated.bucket = "replaced".into();
|
||||
config
|
||||
.update_resource("attachments", Resource::ObjectStore(updated))
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
config.resolve().unwrap().object_storage["attachments"].bucket,
|
||||
"replaced"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user