From d2ac69816567f092fe0d4661723bc43778cb481b Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Mon, 1 Dec 2025 14:31:32 +0000 Subject: fix cargo clippy and fmt warnings --- tests/common/relay.rs | 45 ++++++-------------------------------------- tests/cors.rs | 31 +----------------------------- tests/git_clone.rs | 8 ++------ tests/nip11_document.rs | 2 +- tests/nip34_announcements.rs | 2 +- tests/push_authorization.rs | 7 ++----- 6 files changed, 13 insertions(+), 82 deletions(-) (limited to 'tests') 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 @@ //! Provides automatic relay lifecycle management for integration tests. use nostr_sdk::ToBech32; -use std::path::PathBuf; use std::process::{Child, Command, Stdio}; use std::time::Duration; use tokio::time::sleep; @@ -16,7 +15,6 @@ pub struct TestRelay { process: Child, url: String, port: u16, - git_data_dir: tempfile::TempDir, } impl TestRelay { @@ -44,8 +42,8 @@ impl TestRelay { let url = format!("ws://127.0.0.1:{}", port); // Create temporary directory for git repositories - let git_data_dir = tempfile::tempdir() - .expect("Failed to create temporary git data directory"); + let git_data_dir = + tempfile::tempdir().expect("Failed to create temporary git data directory"); // Use the built binary directly (faster than cargo run) let binary_path = std::env::current_exe() @@ -58,7 +56,9 @@ impl TestRelay { // Generate a test owner npub (using a random keypair) let test_keys = nostr_sdk::Keys::generate(); - let test_npub = test_keys.public_key().to_bech32() + let test_npub = test_keys + .public_key() + .to_bech32() .expect("Failed to generate test npub"); // Start the relay process @@ -73,12 +73,7 @@ impl TestRelay { .spawn() .expect("Failed to start relay process"); - let relay = Self { - process, - url, - port, - git_data_dir, - }; + let relay = Self { process, url, port }; // Wait for relay to be ready relay.wait_for_ready().await; @@ -91,30 +86,11 @@ impl TestRelay { &self.url } - /// Get the relay port - pub fn port(&self) -> u16 { - self.port - } - /// Get the relay domain (host:port) pub fn domain(&self) -> String { format!("127.0.0.1:{}", self.port) } - /// Get the git data directory path - pub fn git_data_dir(&self) -> &std::path::Path { - self.git_data_dir.path() - } - - /// Get the expected repository path for a given npub and repo identifier - /// - /// Repositories are stored at: //.git - pub fn repo_path(&self, npub: &str, identifier: &str) -> PathBuf { - self.git_data_dir.path() - .join(npub) - .join(format!("{}.git", identifier)) - } - /// Wait for the relay to be ready to accept connections async fn wait_for_ready(&self) { let max_attempts = 50; // 5 seconds total @@ -183,15 +159,6 @@ impl Drop for TestRelay { mod tests { use super::*; - #[tokio::test] - #[ignore] // Requires relay binary to be built - async fn test_relay_lifecycle() { - let relay = TestRelay::start().await; - assert!(relay.url().starts_with("ws://127.0.0.1:")); - assert!(relay.port() > 0); - relay.stop().await; - } - #[test] fn test_find_free_port() { 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 { }; } -/// Macro for CORS tests that need git_data_dir (the full integration test) -macro_rules! isolated_cors_test_with_repo { - ($test_name:ident) => { - #[tokio::test] - async fn $test_name() { - let relay = TestRelay::start().await; - let config = AuditConfig::ci(); - let client = AuditClient::new(relay.url(), config) - .await - .expect("Failed to create audit client"); - - let result = CorsTests::$test_name( - &client, - &relay.domain(), - ) - .await; - - relay.stop().await; - - assert!( - result.passed, - "{} failed: {}", - stringify!($test_name), - result.error.as_deref().unwrap_or("unknown error") - ); - } - }; -} - // Generate isolated tests for all CORS tests isolated_cors_test!(test_cors_allow_origin); isolated_cors_test!(test_cors_allow_methods); isolated_cors_test!(test_cors_allow_headers); isolated_cors_test!(test_cors_options_preflight); -isolated_cors_test!(test_cors_on_real_repo); \ No newline at end of file +isolated_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 { .await .expect("Failed to create audit client"); - let result = GitCloneTests::$test_name( - &client, - &relay.domain(), - ) - .await; + let result = GitCloneTests::$test_name(&client, &relay.domain()).await; relay.stop().await; @@ -63,4 +59,4 @@ macro_rules! isolated_test { // Generate isolated tests for all git clone tests isolated_test!(test_basic_git_clone); isolated_test!(test_clone_url_format); -isolated_test!(test_sha1_capabilities_advertised); \ No newline at end of file +isolated_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 { isolated_test!(test_nip11_document_exists); isolated_test!(test_nip11_supported_grasps_field); isolated_test!(test_nip11_repo_acceptance_criteria_field); -isolated_test!(test_nip11_curation_field); \ No newline at end of file +isolated_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); isolated_test!(test_accept_kind1_referenced_in_kind1); isolated_test!(test_reject_orphan_issue); isolated_test!(test_reject_orphan_kind1); -isolated_test!(test_reject_comment_quoting_other_repo); \ No newline at end of file +isolated_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 { .await .expect("Failed to create audit client"); - let result = PushAuthorizationTests::$test_name( - &client, - &relay.domain() - ).await; + let result = PushAuthorizationTests::$test_name(&client, &relay.domain()).await; relay.stop().await; @@ -70,4 +67,4 @@ isolated_push_test!(test_push_to_nostr_ref_with_invalid_event_id_rejected); isolated_push_test!(test_pr_push_to_nostr_ref_with_wrong_commit_accepted_before_event_received); isolated_push_test!(test_pr_event_published_removes_nostr_ref_at_incorrect_commit); isolated_push_test!(test_push_to_nostr_ref_with_wrong_commit_after_event_received_rejected); -isolated_push_test!(test_push_to_nostr_ref_with_correct_commit_after_event_received_accepted); \ No newline at end of file +isolated_push_test!(test_push_to_nostr_ref_with_correct_commit_after_event_received_accepted); -- cgit v1.2.3