upleb.uk

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

summaryrefslogtreecommitdiff
path: root/tests
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
parent7a78815e29b01c83f3d0ec195ba717a2eba8cd37 (diff)
fix cargo clippy and fmt warnings
Diffstat (limited to 'tests')
-rw-r--r--tests/common/relay.rs45
-rw-r--r--tests/cors.rs31
-rw-r--r--tests/git_clone.rs8
-rw-r--r--tests/nip11_document.rs2
-rw-r--r--tests/nip34_announcements.rs2
-rw-r--r--tests/push_authorization.rs7
6 files changed, 13 insertions, 82 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();
diff --git a/tests/cors.rs b/tests/cors.rs
index a27c145..b5a0a87 100644
--- a/tests/cors.rs
+++ b/tests/cors.rs
@@ -55,39 +55,10 @@ macro_rules! isolated_cors_test {
55 }; 55 };
56} 56}
57 57
58/// Macro for CORS tests that need git_data_dir (the full integration test)
59macro_rules! isolated_cors_test_with_repo {
60 ($test_name:ident) => {
61 #[tokio::test]
62 async fn $test_name() {
63 let relay = TestRelay::start().await;
64 let config = AuditConfig::ci();
65 let client = AuditClient::new(relay.url(), config)
66 .await
67 .expect("Failed to create audit client");
68
69 let result = CorsTests::$test_name(
70 &client,
71 &relay.domain(),
72 )
73 .await;
74
75 relay.stop().await;
76
77 assert!(
78 result.passed,
79 "{} failed: {}",
80 stringify!($test_name),
81 result.error.as_deref().unwrap_or("unknown error")
82 );
83 }
84 };
85}
86
87// Generate isolated tests for all CORS tests 58// Generate isolated tests for all CORS tests
88isolated_cors_test!(test_cors_allow_origin); 59isolated_cors_test!(test_cors_allow_origin);
89isolated_cors_test!(test_cors_allow_methods); 60isolated_cors_test!(test_cors_allow_methods);
90isolated_cors_test!(test_cors_allow_headers); 61isolated_cors_test!(test_cors_allow_headers);
91isolated_cors_test!(test_cors_options_preflight); 62isolated_cors_test!(test_cors_options_preflight);
92 63
93isolated_cors_test!(test_cors_on_real_repo); \ No newline at end of file 64isolated_cors_test!(test_cors_on_real_repo);
diff --git a/tests/git_clone.rs b/tests/git_clone.rs
index ffb04a3..c8a91a2 100644
--- a/tests/git_clone.rs
+++ b/tests/git_clone.rs
@@ -42,11 +42,7 @@ macro_rules! isolated_test {
42 .await 42 .await
43 .expect("Failed to create audit client"); 43 .expect("Failed to create audit client");
44 44
45 let result = GitCloneTests::$test_name( 45 let result = GitCloneTests::$test_name(&client, &relay.domain()).await;
46 &client,
47 &relay.domain(),
48 )
49 .await;
50 46
51 relay.stop().await; 47 relay.stop().await;
52 48
@@ -63,4 +59,4 @@ macro_rules! isolated_test {
63// Generate isolated tests for all git clone tests 59// Generate isolated tests for all git clone tests
64isolated_test!(test_basic_git_clone); 60isolated_test!(test_basic_git_clone);
65isolated_test!(test_clone_url_format); 61isolated_test!(test_clone_url_format);
66isolated_test!(test_sha1_capabilities_advertised); \ No newline at end of file 62isolated_test!(test_sha1_capabilities_advertised);
diff --git a/tests/nip11_document.rs b/tests/nip11_document.rs
index da8e9ce..2104ad0 100644
--- a/tests/nip11_document.rs
+++ b/tests/nip11_document.rs
@@ -59,4 +59,4 @@ macro_rules! isolated_test {
59isolated_test!(test_nip11_document_exists); 59isolated_test!(test_nip11_document_exists);
60isolated_test!(test_nip11_supported_grasps_field); 60isolated_test!(test_nip11_supported_grasps_field);
61isolated_test!(test_nip11_repo_acceptance_criteria_field); 61isolated_test!(test_nip11_repo_acceptance_criteria_field);
62isolated_test!(test_nip11_curation_field); \ No newline at end of file 62isolated_test!(test_nip11_curation_field);
diff --git a/tests/nip34_announcements.rs b/tests/nip34_announcements.rs
index 09d9c8f..2a83886 100644
--- a/tests/nip34_announcements.rs
+++ b/tests/nip34_announcements.rs
@@ -71,4 +71,4 @@ isolated_test!(test_accept_comment_referenced_in_comment);
71isolated_test!(test_accept_kind1_referenced_in_kind1); 71isolated_test!(test_accept_kind1_referenced_in_kind1);
72isolated_test!(test_reject_orphan_issue); 72isolated_test!(test_reject_orphan_issue);
73isolated_test!(test_reject_orphan_kind1); 73isolated_test!(test_reject_orphan_kind1);
74isolated_test!(test_reject_comment_quoting_other_repo); \ No newline at end of file 74isolated_test!(test_reject_comment_quoting_other_repo);
diff --git a/tests/push_authorization.rs b/tests/push_authorization.rs
index 1f8e0ca..357fefb 100644
--- a/tests/push_authorization.rs
+++ b/tests/push_authorization.rs
@@ -43,10 +43,7 @@ macro_rules! isolated_push_test {
43 .await 43 .await
44 .expect("Failed to create audit client"); 44 .expect("Failed to create audit client");
45 45
46 let result = PushAuthorizationTests::$test_name( 46 let result = PushAuthorizationTests::$test_name(&client, &relay.domain()).await;
47 &client,
48 &relay.domain()
49 ).await;
50 47
51 relay.stop().await; 48 relay.stop().await;
52 49
@@ -70,4 +67,4 @@ isolated_push_test!(test_push_to_nostr_ref_with_invalid_event_id_rejected);
70isolated_push_test!(test_pr_push_to_nostr_ref_with_wrong_commit_accepted_before_event_received); 67isolated_push_test!(test_pr_push_to_nostr_ref_with_wrong_commit_accepted_before_event_received);
71isolated_push_test!(test_pr_event_published_removes_nostr_ref_at_incorrect_commit); 68isolated_push_test!(test_pr_event_published_removes_nostr_ref_at_incorrect_commit);
72isolated_push_test!(test_push_to_nostr_ref_with_wrong_commit_after_event_received_rejected); 69isolated_push_test!(test_push_to_nostr_ref_with_wrong_commit_after_event_received_rejected);
73isolated_push_test!(test_push_to_nostr_ref_with_correct_commit_after_event_received_accepted); \ No newline at end of file 70isolated_push_test!(test_push_to_nostr_ref_with_correct_commit_after_event_received_accepted);