Skip to content

Commit

Permalink
Fixup Macro to allow user to only write toml in string form
Browse files Browse the repository at this point in the history
  • Loading branch information
euamcg committed Jan 17, 2024
1 parent f5ea55c commit f0958d7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
17 changes: 7 additions & 10 deletions homestar-runtime/tests/network/gossip.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::make_config;
use crate::utils::{
check_for_line_with, kill_homestar, retrieve_output, wait_for_socket_connection, ChildGuard,
FileGuard, TimeoutFutureExt, BIN_NAME, TestConfig
FileGuard, TestConfig, TimeoutFutureExt, BIN_NAME,
};
use ::function_name::named;
use anyhow::Result;
Expand Down Expand Up @@ -35,7 +35,7 @@ fn test_libp2p_receipt_gossip_integration() -> Result<()> {
let _db_guard1 = FileGuard::new(DB1);
let _db_guard2 = FileGuard::new(DB2);

let toml_val = toml::toml! {
let toml = r#"
[node]
[node.monitoring]
Expand Down Expand Up @@ -65,10 +65,9 @@ fn test_libp2p_receipt_gossip_integration() -> Result<()> {
[node.network.webserver]
port = 7990
};
"#;

let test_config = make_config!(function_name!(), toml_val);
let _ = test_config.create_fixture();
let test_config = make_config!(toml);

let homestar_proc1 = Command::new(BIN.as_os_str())
.env(
Expand Down Expand Up @@ -106,7 +105,7 @@ fn test_libp2p_receipt_gossip_integration() -> Result<()> {
.await
.unwrap();

let toml_val_2 = toml::toml! {
let toml_val_2 = r#"
[node]
[node.monitoring]
Expand Down Expand Up @@ -136,11 +135,9 @@ fn test_libp2p_receipt_gossip_integration() -> Result<()> {
[node.network.webserver]
port = 7991
};
"#;

// Should probably figure out how to deal with tests with two configs
// currently generates the same name.
let test_config_2 = make_config!(concat!(function_name!(), "2"), toml_val_2);
let test_config_2 = make_config!("gossip_2", toml_val_2);
let _ = test_config_2.create_fixture();

let homestar_proc2 = Command::new(BIN.as_os_str())
Expand Down
26 changes: 12 additions & 14 deletions homestar-runtime/tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,26 +348,24 @@ impl Drop for TestConfig {
}
#[macro_export]
macro_rules! make_config {
// No args just generates the default config for homestar
() => {{
let name = concat!("tests/fixtures/", function_name!(), ".toml");
TestConfig {
name: name.to_string(),
toml_config: "".to_string(),
}
}};
// For tests where all you want to do is write toml.
($toml:expr) => {{
let name = concat!("tests/fixtures/", function_name!(), ".toml");
TestConfig {
name: name.to_string();
toml_config: $toml
}
let toml = $toml.parse::<toml::Table>().unwrap();
let test_config = TestConfig {
name: name.to_string(),
toml_config: toml,
};
test_config.create_fixture();
test_config
}};
// For some finer control over the config
($name:expr, $toml:expr) => {{
let name = concat!("tests/fixtures/", $name, ".toml");
let name = concat!("tests/fixtures/", function_name!(), $name, ".toml");
let toml = $toml.parse::<toml::Table>().unwrap();
TestConfig {
name: name.to_string(),
toml_config: $toml,
toml_config: toml,
}
}};
}

0 comments on commit f0958d7

Please sign in to comment.