upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/tests/common
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-12-01 14:31:32 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-12-01 15:22:38 +0000
commitd2ac69816567f092fe0d4661723bc43778cb481b (patch)
treee8b51b61a6a7b0ab1a214adebe4e237143b01f0b /tests/common
parent7a78815e29b01c83f3d0ec195ba717a2eba8cd37 (diff)
fix cargo clippy and fmt warnings
Diffstat (limited to 'tests/common')
-rw-r--r--tests/common/relay.rs45
1 files changed, 6 insertions, 39 deletions
diff --git a/tests/common/relay.rs b/tests/common/relay.rs
index 6b512cd..449b4cb 100644
--- a/tests/common/relay.rs
+++ b/tests/common/relay.rs
@@ -3,7 +3,6 @@
3//! Provides automatic relay lifecycle management for integration tests. 3//! Provides automatic relay lifecycle management for integration tests.
4 4
5use nostr_sdk::ToBech32; 5use nostr_sdk::ToBech32;
6use std::path::PathBuf;
7use std::process::{Child, Command, Stdio}; 6use std::process::{Child, Command, Stdio};
8use std::time::Duration; 7use std::time::Duration;
9use tokio::time::sleep; 8use tokio::time::sleep;
@@ -16,7 +15,6 @@ pub struct TestRelay {
16 process: Child, 15 process: Child,
17 url: String, 16 url: String,
18 port: u16, 17 port: u16,
19 git_data_dir: tempfile::TempDir,
20} 18}
21 19
22impl TestRelay { 20impl TestRelay {
@@ -44,8 +42,8 @@ impl TestRelay {
44 let url = format!("ws://127.0.0.1:{}", port); 42 let url = format!("ws://127.0.0.1:{}", port);
45 43
46 // Create temporary directory for git repositories 44 // Create temporary directory for git repositories
47 let git_data_dir = tempfile::tempdir() 45 let git_data_dir =
48 .expect("Failed to create temporary git data directory"); 46 tempfile::tempdir().expect("Failed to create temporary git data directory");
49 47
50 // Use the built binary directly (faster than cargo run) 48 // Use the built binary directly (faster than cargo run)
51 let binary_path = std::env::current_exe() 49 let binary_path = std::env::current_exe()
@@ -58,7 +56,9 @@ impl TestRelay {
58 56
59 // Generate a test owner npub (using a random keypair) 57 // Generate a test owner npub (using a random keypair)
60 let test_keys = nostr_sdk::Keys::generate(); 58 let test_keys = nostr_sdk::Keys::generate();
61 let test_npub = test_keys.public_key().to_bech32() 59 let test_npub = test_keys
60 .public_key()
61 .to_bech32()
62 .expect("Failed to generate test npub"); 62 .expect("Failed to generate test npub");
63 63
64 // Start the relay process 64 // Start the relay process
@@ -73,12 +73,7 @@ impl TestRelay {
73 .spawn() 73 .spawn()
74 .expect("Failed to start relay process"); 74 .expect("Failed to start relay process");
75 75
76 let relay = Self { 76 let relay = Self { process, url, port };
77 process,
78 url,
79 port,
80 git_data_dir,
81 };
82 77
83 // Wait for relay to be ready 78 // Wait for relay to be ready
84 relay.wait_for_ready().await; 79 relay.wait_for_ready().await;
@@ -91,30 +86,11 @@ impl TestRelay {
91 &self.url 86 &self.url
92 } 87 }
93 88
94 /// Get the relay port
95 pub fn port(&self) -> u16 {
96 self.port
97 }
98
99 /// Get the relay domain (host:port) 89 /// Get the relay domain (host:port)
100 pub fn domain(&self) -> String { 90 pub fn domain(&self) -> String {
101 format!("127.0.0.1:{}", self.port) 91 format!("127.0.0.1:{}", self.port)
102 } 92 }
103 93
104 /// Get the git data directory path
105 pub fn git_data_dir(&self) -> &std::path::Path {
106 self.git_data_dir.path()
107 }
108
109 /// Get the expected repository path for a given npub and repo identifier
110 ///
111 /// Repositories are stored at: <git_data_dir>/<npub>/<identifier>.git
112 pub fn repo_path(&self, npub: &str, identifier: &str) -> PathBuf {
113 self.git_data_dir.path()
114 .join(npub)
115 .join(format!("{}.git", identifier))
116 }
117
118 /// Wait for the relay to be ready to accept connections 94 /// Wait for the relay to be ready to accept connections
119 async fn wait_for_ready(&self) { 95 async fn wait_for_ready(&self) {
120 let max_attempts = 50; // 5 seconds total 96 let max_attempts = 50; // 5 seconds total
@@ -183,15 +159,6 @@ impl Drop for TestRelay {
183mod tests { 159mod tests {
184 use super::*; 160 use super::*;
185 161
186 #[tokio::test]
187 #[ignore] // Requires relay binary to be built
188 async fn test_relay_lifecycle() {
189 let relay = TestRelay::start().await;
190 assert!(relay.url().starts_with("ws://127.0.0.1:"));
191 assert!(relay.port() > 0);
192 relay.stop().await;
193 }
194
195 #[test] 162 #[test]
196 fn test_find_free_port() { 163 fn test_find_free_port() {
197 let port = TestRelay::find_free_port(); 164 let port = TestRelay::find_free_port();