config tests

This commit is contained in:
Lev Kokotov
2022-02-10 09:07:10 -08:00
parent 8209633e05
commit c1476d29da
2 changed files with 29 additions and 3 deletions

View File

@@ -77,13 +77,39 @@ pub async fn parse(path: &str) -> Result<Config, Error> {
}
};
// We use addresses as unique identifiers,
// let's make sure they are unique in the config as well.
// Quick config sanity check.
for shard in &config.shards {
// We use addresses as unique identifiers,
// let's make sure they are unique in the config as well.
let mut dup_check = HashSet::new();
let mut primary_count = 0;
for server in &shard.1.servers {
dup_check.insert(server);
// Check that we define only zero or one primary.
match server.2.as_ref() {
"primary" => primary_count += 1,
_ => (),
};
// Check role spelling.
match server.2.as_ref() {
"primary" => (),
"replica" => (),
_ => {
println!(
"> Shard {} server role must be either 'primary' or 'replica', got: '{}'",
shard.0, server.2
);
return Err(Error::BadConfig);
}
};
}
if primary_count > 1 {
println!("> Shard {} has more than on primary configured.", &shard.0);
return Err(Error::BadConfig);
}
if dup_check.len() != shard.1.servers.len() {

View File

@@ -8,7 +8,7 @@ echo "Giving Postgres 5 seconds to start up..."
# sleep 5
psql -f query_routing_setup.sql
# psql -f query_routing_setup.sql
psql -h 127.0.0.1 -p 6432 -f query_routing_test_insert.sql