add test for checking the example.toml

This commit is contained in:
Bryan Stitt 2022-11-11 21:16:32 +00:00
parent 22fa5136a8
commit 8e3547bbd0
3 changed files with 43 additions and 3 deletions

View File

@ -232,9 +232,9 @@ These are roughly in order of completition
- [x] nullable rpc_key_id on revert log
- [x] attach origin to revert_log
- opt-in origin logging
- [x] test that runs check_config against example.toml
- [-] add configurable size limits to all the Caches
- instead of configuring each cache with MB sizes, have one value for total memory footprint and then percentages for each cache
- [ ] test that runs check_config against example.toml
- [ ] improve sorting servers by weight
- if the utilization is > 100%, increase weight by 1? maybe just add utilization to the weight?
- if utilization is > hard limit, add a lot to the weight

View File

@ -13,7 +13,7 @@ volatile_redis_max_connections = 300
volatile_redis_url = "redis://REDIS_DOMAIN:REDIS_PORT/"
redirect_public_url = "https://llamanodes.com/public-rpc"
redirect_user_url = "https://llamanodes.com/dashboard/keys?key={rpc_key_id}"
redirect_rpc_key_url = "https://llamanodes.com/dashboard/keys?key={rpc_key_id}"
sentry_url = "https://SENTRY_KEY_A.ingest.sentry.io/SENTRY_KEY_B"

View File

@ -14,6 +14,8 @@ pub struct CheckConfigSubCommand {
impl CheckConfigSubCommand {
pub async fn main(self) -> anyhow::Result<()> {
let mut num_errors = 0;
info!("Loading config @ {}", self.path);
let top_config: String = fs::read_to_string(self.path)?;
let top_config: TopConfig = toml::from_str(&top_config)?;
@ -72,11 +74,49 @@ impl CheckConfigSubCommand {
}
Some(x) => {
if !x.contains("{rpc_key_id}") {
num_errors += 1;
error!("redirect_user_url user url must contain \"{{rpc_key_id}}\"")
}
}
}
Ok(())
// TODO: print num warnings and have a flag to fail even on warnings
if num_errors == 0 {
Ok(())
} else {
Err(anyhow::anyhow!(format!(
"there were {} errors!",
num_errors
)))
}
}
}
#[cfg(test)]
mod tests {
use std::env;
use super::*;
#[tokio::test]
async fn check_example_toml() {
let path = env::current_dir().expect("path");
let parent = path.parent().expect("always a parent");
let config_path = parent.join("config").join("example.toml");
let config_path_str = config_path.to_str().expect("always a valid path");
let check_config_command =
CheckConfigSubCommand::from_args(&["check_config"], &[config_path_str])
.expect("the command should have run");
let check_config_result = check_config_command.main().await;
println!("{:?}", check_config_result);
check_config_result.expect("the config should pass all checks");
}
}