From e8ac3b6b49c6ec38cf4694dc4cb08f12c684ed7b Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Tue, 23 Jan 2024 00:00:00 +0000 Subject: build: env specific fallback relays to prevent tests from poluting public relays --- config.toml | 2 ++ src/client.rs | 35 +++++++++++++++++++++++++++++------ test_utils/config.toml | 2 ++ test_utils/src/lib.rs | 2 ++ 4 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 config.toml create mode 100644 test_utils/config.toml diff --git a/config.toml b/config.toml new file mode 100644 index 0000000..519f44f --- /dev/null +++ b/config.toml @@ -0,0 +1,2 @@ +[env] +NGITTEST = true \ No newline at end of file diff --git a/src/client.rs b/src/client.rs index 860562c..7418519 100644 --- a/src/client.rs +++ b/src/client.rs @@ -43,16 +43,39 @@ pub trait Connect { #[async_trait] impl Connect for Client { fn default() -> Self { - Client { - client: nostr_sdk::Client::new(&nostr::Keys::generate()), - fallback_relays: vec![ + let fallback_relays: Vec = if std::env::var("NGITTEST").is_ok() { + vec![ "ws://localhost:8051".to_string(), "ws://localhost:8052".to_string(), - ], - more_fallback_relays: vec![ + ] + } else { + vec![ + "wss://relayable.org".to_string(), + "wss://relay.f7z.io".to_string(), + "wss://relay.damus.io".to_string(), + "wss://relay.snort.social".to_string(), + // "ws://localhost:8080".to_string() + ] + }; + + let more_fallback_relays: Vec = if std::env::var("NGITTEST").is_ok() { + vec![ "ws://localhost:8055".to_string(), "ws://localhost:8056".to_string(), - ], + ] + } else { + vec![ + "wss://nostr.wine/".to_string(), + "wss://eden.nostr.land/".to_string(), + "wss://relay.nostr.band/".to_string(), + // "ws://localhost:8080".to_string() + ] + }; + + Client { + client: nostr_sdk::Client::new(&nostr::Keys::generate()), + fallback_relays, + more_fallback_relays, } } fn new(opts: Params) -> Self { diff --git a/test_utils/config.toml b/test_utils/config.toml new file mode 100644 index 0000000..519f44f --- /dev/null +++ b/test_utils/config.toml @@ -0,0 +1,2 @@ +[env] +NGITTEST = true \ No newline at end of file diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs index d119bd7..f509039 100644 --- a/test_utils/src/lib.rs +++ b/test_utils/src/lib.rs @@ -735,6 +735,7 @@ where S: AsRef, { let mut cmd = std::process::Command::new(assert_cmd::cargo::cargo_bin("ngit")); + cmd.env("NGITTEST", "TRUE"); cmd.args(args); // using branch for PR https://github.com/rust-cli/rexpect/pull/103 to strip ansi escape codes rexpect::session::spawn_with_options( @@ -756,6 +757,7 @@ where S: AsRef, { let mut cmd = std::process::Command::new(assert_cmd::cargo::cargo_bin("ngit")); + cmd.env("NGITTEST", "TRUE"); cmd.current_dir(dir); cmd.args(args); // using branch for PR https://github.com/rust-cli/rexpect/pull/103 to strip ansi escape codes -- cgit v1.2.3