Skip to content

Commit

Permalink
node: Make sure Config.node is set correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
lutter committed Aug 4, 2022
1 parent 8a61a0e commit 209786c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl Config {
/// a config from the command line arguments in `opt`
pub fn load(logger: &Logger, opt: &Opt) -> Result<Config> {
if let Some(config) = &opt.config {
Self::from_file(logger, config)
Self::from_file(logger, config, &opt.node_id)
} else {
info!(
logger,
Expand All @@ -160,13 +160,15 @@ impl Config {
}
}

pub fn from_file(logger: &Logger, path: &str) -> Result<Config> {
pub fn from_file(logger: &Logger, path: &str, node: &str) -> Result<Config> {
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<Config> {
pub fn from_str(config: &str, node: &str) -> Result<Config> {
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)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/src/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 209786c

Please sign in to comment.