Unify backend resources and role bindings in clusters
This commit is contained in:
+13
-21
@@ -1,8 +1,8 @@
|
||||
use std::{collections::BTreeMap, env, time::Duration};
|
||||
|
||||
use db::{
|
||||
Connection, DeploymentConfig, Driver, Mutation, ReadPreference, SqlCluster, StorageError, Tls,
|
||||
connect,
|
||||
Connection, DeploymentConfig, Driver, Mutation, ReadPreference, Resource, SqlCluster,
|
||||
StorageError, Tls, connect,
|
||||
};
|
||||
use serde_json::json;
|
||||
|
||||
@@ -17,16 +17,16 @@ fn change(id: &str, text: &str) -> Mutation {
|
||||
fn sql_config(driver: Driver, url: &str, deployment: &str) -> DeploymentConfig {
|
||||
DeploymentConfig {
|
||||
deployment: deployment.into(),
|
||||
cluster: Some("test".into()),
|
||||
clusters: BTreeMap::from([(
|
||||
bindings: BTreeMap::from([("documents".into(), "test".into())]),
|
||||
resources: BTreeMap::from([(
|
||||
"test".into(),
|
||||
SqlCluster {
|
||||
Resource::Sql(SqlCluster {
|
||||
driver,
|
||||
primary: url.into(),
|
||||
replicas: vec![],
|
||||
tls: Tls::Disabled,
|
||||
max_connections: 4,
|
||||
},
|
||||
}),
|
||||
)]),
|
||||
..DeploymentConfig::default()
|
||||
}
|
||||
@@ -118,10 +118,7 @@ async fn check_document_contract(db: &Connection) {
|
||||
async fn sqlite_persists_across_reopening_and_enforces_read_only() {
|
||||
let folder = tempfile::tempdir().unwrap();
|
||||
let filename = folder.path().join("bedrock +?#%.sqlite");
|
||||
let mut config = DeploymentConfig {
|
||||
sqlite_path: filename.to_str().unwrap().into(),
|
||||
..DeploymentConfig::default()
|
||||
};
|
||||
let mut config = sql_config(Driver::Sqlite, filename.to_str().unwrap(), "default");
|
||||
let db = connect(&config).await.unwrap();
|
||||
assert_eq!(db.driver(), Driver::Sqlite);
|
||||
check_document_contract(&db).await;
|
||||
@@ -140,11 +137,8 @@ async fn sqlite_persists_across_reopening_and_enforces_read_only() {
|
||||
async fn sqlite_read_only_startup_does_not_create_a_database() {
|
||||
let folder = tempfile::tempdir().unwrap();
|
||||
let filename = folder.path().join("missing.sqlite");
|
||||
let config = DeploymentConfig {
|
||||
read_only: true,
|
||||
sqlite_path: filename.to_str().unwrap().into(),
|
||||
..DeploymentConfig::default()
|
||||
};
|
||||
let mut config = sql_config(Driver::Sqlite, filename.to_str().unwrap(), "default");
|
||||
config.read_only = true;
|
||||
assert!(connect(&config).await.is_err());
|
||||
assert!(!filename.exists());
|
||||
}
|
||||
@@ -156,12 +150,10 @@ async fn postgres_reads_replicas_and_falls_back_when_behind() {
|
||||
};
|
||||
let replica_url = test_url("BEDROCK_TEST_POSTGRES_REPLICA").unwrap();
|
||||
let mut config = sql_config(Driver::Postgres, &url, "pg_contract");
|
||||
config
|
||||
.clusters
|
||||
.get_mut("test")
|
||||
.unwrap()
|
||||
.replicas
|
||||
.push(replica_url.clone().into());
|
||||
let Some(Resource::Sql(cluster)) = config.resources.get_mut("test") else {
|
||||
panic!("expected a SQL resource");
|
||||
};
|
||||
cluster.replicas.push(replica_url.clone().into());
|
||||
let replica = connect(&sql_config(Driver::Postgres, &replica_url, "pg_contract"))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
Reference in New Issue
Block a user