Skip to content

Commit

Permalink
[E2E] fix flaky config tests with temp_env (#2105)
Browse files Browse the repository at this point in the history
  • Loading branch information
ascjones authored Feb 8, 2024
1 parent 7525d40 commit ae81655
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crates/e2e/macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@ syn = { workspace = true }
proc-macro2 = { workspace = true }
quote = { workspace = true }

[dev-dependencies]
temp-env = "0.3.6"

[features]
drink = []
36 changes: 26 additions & 10 deletions crates/e2e/macro/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,19 @@ mod tests {
Backend::Node(node_config) => {
assert_eq!(node_config, Node::Auto);

std::env::remove_var("CONTRACTS_NODE_URL");
assert_eq!(node_config.url(), None);

std::env::set_var("CONTRACTS_NODE_URL", "ws://127.0.0.1:9000");
assert_eq!(node_config.url(), Some(String::from("ws://127.0.0.1:9000")));
temp_env::with_vars([("CONTRACTS_NODE_URL", None::<&str>)], || {
assert_eq!(node_config.url(), None);
});

temp_env::with_vars(
[("CONTRACTS_NODE_URL", Some("ws://127.0.0.1:9000"))],
|| {
assert_eq!(
node_config.url(),
Some(String::from("ws://127.0.0.1:9000"))
);
},
);
}
_ => panic!("Expected Backend::Node"),
}
Expand All @@ -195,11 +203,19 @@ mod tests {
Backend::Node(node_config) => {
assert_eq!(node_config, Node::Url("ws://0.0.0.0:9999".to_owned()));

std::env::remove_var("CONTRACTS_NODE_URL");
assert_eq!(node_config.url(), Some("ws://0.0.0.0:9999".to_owned()));

std::env::set_var("CONTRACTS_NODE_URL", "ws://127.0.0.1:9000");
assert_eq!(node_config.url(), Some(String::from("ws://127.0.0.1:9000")));
temp_env::with_vars([("CONTRACTS_NODE_URL", None::<&str>)], || {
assert_eq!(node_config.url(), Some("ws://0.0.0.0:9999".to_owned()));
});

temp_env::with_vars(
[("CONTRACTS_NODE_URL", Some("ws://127.0.0.1:9000"))],
|| {
assert_eq!(
node_config.url(),
Some(String::from("ws://127.0.0.1:9000"))
);
},
);
}
_ => panic!("Expected Backend::Node"),
}
Expand Down

0 comments on commit ae81655

Please sign in to comment.