From 209786c9caf18506239bb9833e21a466cc2bf54d Mon Sep 17 00:00:00 2001 From: David Lutterkort Date: Thu, 4 Aug 2022 12:14:33 -0700 Subject: [PATCH] node: Make sure Config.node is set correctly --- node/src/config.rs | 10 ++++++---- tests/src/fixture.rs | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/node/src/config.rs b/node/src/config.rs index 1eb8ae91fd2..4c5a9d9353e 100644 --- a/node/src/config.rs +++ b/node/src/config.rs @@ -150,7 +150,7 @@ impl Config { /// a config from the command line arguments in `opt` pub fn load(logger: &Logger, opt: &Opt) -> Result { if let Some(config) = &opt.config { - Self::from_file(logger, config) + Self::from_file(logger, config, &opt.node_id) } else { info!( logger, @@ -160,13 +160,15 @@ impl Config { } } - pub fn from_file(logger: &Logger, path: &str) -> Result { + pub fn from_file(logger: &Logger, path: &str, node: &str) -> Result { info!(logger, "Reading configuration file `{}`", path); - Self::from_str(&read_to_string(path)?) + Self::from_str(&read_to_string(path)?, node) } - pub fn from_str(config: &str) -> Result { + pub fn from_str(config: &str, node: &str) -> Result { let mut config: Config = toml::from_str(&config)?; + config.node = + NodeId::new(node.clone()).map_err(|()| anyhow!("invalid node id {}", node))?; config.validate()?; Ok(config) } diff --git a/tests/src/fixture.rs b/tests/src/fixture.rs index b8be34364ca..b35c19bea3a 100644 --- a/tests/src/fixture.rs +++ b/tests/src/fixture.rs @@ -126,7 +126,7 @@ pub async fn stores(store_config_path: &str) -> Stores { Err(e) => panic!("{}", e.to_string()), }; let config = config.replace("$THEGRAPH_STORE_POSTGRES_DIESEL_URL", &db_url); - Config::from_str(&config).expect("failed to create configuration") + Config::from_str(&config, "default").expect("failed to create configuration") }; let logger = graph::log::logger(true);