diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-11 16:53:03 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-11 16:53:03 +0000 |
| commit | 2a9160836bb87fdea3ae891563b0169c68d1c2ab (patch) | |
| tree | 583c890687beaf7f380fc0be131bdf17485f06fa /tests/common/sync_helpers.rs | |
| parent | 52489d3b1a7d79e164b4cc901b53fd06c05ce1b1 (diff) | |
fix: resolve all fmt and clippy warnings
Main lib (src/):
- Add #[allow(dead_code)] for build_info field (stored to prevent Prometheus unregistration)
- Add #[allow(dead_code)] for first_seen field (reserved for future rate limiting)
- Replace .or_insert_with(RelaySyncNeeds::default) with .or_default()
- Replace manual div_ceil implementations with .div_ceil(100)
Test code (tests/):
- Replace .expect(&format!(...)) with .unwrap_or_else(|_| panic!(...))
- Remove needless borrows in fetch_metrics() calls
- Add #[allow(dead_code)] and #[allow(unused_imports)] to test helpers module
grasp-audit:
- Apply cargo fmt to fix formatting
Diffstat (limited to 'tests/common/sync_helpers.rs')
| -rw-r--r-- | tests/common/sync_helpers.rs | 54 |
1 files changed, 25 insertions, 29 deletions
diff --git a/tests/common/sync_helpers.rs b/tests/common/sync_helpers.rs index 531ebe1..7fa0393 100644 --- a/tests/common/sync_helpers.rs +++ b/tests/common/sync_helpers.rs | |||
| @@ -173,7 +173,11 @@ impl TestClient { | |||
| 173 | /// # Returns | 173 | /// # Returns |
| 174 | /// * `Ok(Event)` - Signed event ready to send | 174 | /// * `Ok(Event)` - Signed event ready to send |
| 175 | /// * `Err(String)` - If signing fails | 175 | /// * `Err(String)` - If signing fails |
| 176 | pub fn build_layer2_issue_event(keys: &Keys, repo_coord: &str, title: &str) -> Result<Event, String> { | 176 | pub fn build_layer2_issue_event( |
| 177 | keys: &Keys, | ||
| 178 | repo_coord: &str, | ||
| 179 | title: &str, | ||
| 180 | ) -> Result<Event, String> { | ||
| 177 | build_layer2_issue_with_tag(keys, repo_coord, title, TagVariant::LowercaseA) | 181 | build_layer2_issue_with_tag(keys, repo_coord, title, TagVariant::LowercaseA) |
| 178 | } | 182 | } |
| 179 | 183 | ||
| @@ -256,10 +260,7 @@ pub fn build_layer3_comment_event( | |||
| 256 | // Choose tag based on kind (NIP-22 uses E, NIP-10 style uses e) | 260 | // Choose tag based on kind (NIP-22 uses E, NIP-10 style uses e) |
| 257 | let tag = if kind_num == KIND_COMMENT { | 261 | let tag = if kind_num == KIND_COMMENT { |
| 258 | // NIP-22 comment: uppercase 'E' tag | 262 | // NIP-22 comment: uppercase 'E' tag |
| 259 | Tag::custom( | 263 | Tag::custom(TagKind::custom("E"), vec![parent_event_id.to_hex()]) |
| 260 | TagKind::custom("E"), | ||
| 261 | vec![parent_event_id.to_hex()], | ||
| 262 | ) | ||
| 263 | } else { | 264 | } else { |
| 264 | // Kind 1 reply: lowercase 'e' tag with root marker (NIP-10) | 265 | // Kind 1 reply: lowercase 'e' tag with root marker (NIP-10) |
| 265 | Tag::custom( | 266 | Tag::custom( |
| @@ -299,10 +300,7 @@ pub fn build_layer3_comment_with_uppercase_e_tag( | |||
| 299 | parent_event_id: &EventId, | 300 | parent_event_id: &EventId, |
| 300 | content: &str, | 301 | content: &str, |
| 301 | ) -> Result<Event, String> { | 302 | ) -> Result<Event, String> { |
| 302 | let tag = Tag::custom( | 303 | let tag = Tag::custom(TagKind::custom("E"), vec![parent_event_id.to_hex()]); |
| 303 | TagKind::custom("E"), | ||
| 304 | vec![parent_event_id.to_hex()], | ||
| 305 | ); | ||
| 306 | 304 | ||
| 307 | EventBuilder::new(Kind::Custom(KIND_COMMENT), content) | 305 | EventBuilder::new(Kind::Custom(KIND_COMMENT), content) |
| 308 | .tags(vec![tag]) | 306 | .tags(vec![tag]) |
| @@ -316,10 +314,7 @@ pub fn build_layer3_quote_with_q_tag( | |||
| 316 | parent_event_id: &EventId, | 314 | parent_event_id: &EventId, |
| 317 | content: &str, | 315 | content: &str, |
| 318 | ) -> Result<Event, String> { | 316 | ) -> Result<Event, String> { |
| 319 | let tag = Tag::custom( | 317 | let tag = Tag::custom(TagKind::custom("q"), vec![parent_event_id.to_hex()]); |
| 320 | TagKind::custom("q"), | ||
| 321 | vec![parent_event_id.to_hex()], | ||
| 322 | ); | ||
| 323 | 318 | ||
| 324 | EventBuilder::new(Kind::Custom(1), content) | 319 | EventBuilder::new(Kind::Custom(1), content) |
| 325 | .tags(vec![tag]) | 320 | .tags(vec![tag]) |
| @@ -587,10 +582,7 @@ pub fn repo_coord(keys: &Keys, identifier: &str) -> String { | |||
| 587 | /// ``` | 582 | /// ``` |
| 588 | pub async fn fetch_metrics(relay_url: &str) -> Result<String, reqwest::Error> { | 583 | pub async fn fetch_metrics(relay_url: &str) -> Result<String, reqwest::Error> { |
| 589 | // Convert ws:// URL to http:// for metrics endpoint | 584 | // Convert ws:// URL to http:// for metrics endpoint |
| 590 | let http_url = relay_url | 585 | let http_url = relay_url.replace("ws://", "http://").replace("/", "") + "/metrics"; |
| 591 | .replace("ws://", "http://") | ||
| 592 | .replace("/", "") | ||
| 593 | + "/metrics"; | ||
| 594 | 586 | ||
| 595 | reqwest::get(&http_url).await?.text().await | 587 | reqwest::get(&http_url).await?.text().await |
| 596 | } | 588 | } |
| @@ -888,8 +880,8 @@ mod tests { | |||
| 888 | let keys = Keys::generate(); | 880 | let keys = Keys::generate(); |
| 889 | let coord = repo_coord(&keys, "my-repo"); | 881 | let coord = repo_coord(&keys, "my-repo"); |
| 890 | 882 | ||
| 891 | let event = build_layer2_issue_event(&keys, &coord, "Test Issue") | 883 | let event = |
| 892 | .expect("Should create event"); | 884 | build_layer2_issue_event(&keys, &coord, "Test Issue").expect("Should create event"); |
| 893 | 885 | ||
| 894 | // nostr-sdk 0.43: use field access | 886 | // nostr-sdk 0.43: use field access |
| 895 | assert_eq!(event.kind.as_u16(), KIND_ISSUE); | 887 | assert_eq!(event.kind.as_u16(), KIND_ISSUE); |
| @@ -937,8 +929,13 @@ mod tests { | |||
| 937 | let keys = Keys::generate(); | 929 | let keys = Keys::generate(); |
| 938 | let parent_id = EventId::all_zeros(); | 930 | let parent_id = EventId::all_zeros(); |
| 939 | 931 | ||
| 940 | let event = build_layer3_comment_event(&keys, &parent_id, "Test comment", Kind::Custom(KIND_COMMENT)) | 932 | let event = build_layer3_comment_event( |
| 941 | .expect("Should create event"); | 933 | &keys, |
| 934 | &parent_id, | ||
| 935 | "Test comment", | ||
| 936 | Kind::Custom(KIND_COMMENT), | ||
| 937 | ) | ||
| 938 | .expect("Should create event"); | ||
| 942 | 939 | ||
| 943 | assert_eq!(event.kind.as_u16(), KIND_COMMENT); | 940 | assert_eq!(event.kind.as_u16(), KIND_COMMENT); |
| 944 | 941 | ||
| @@ -980,8 +977,7 @@ mod tests { | |||
| 980 | 977 | ||
| 981 | let has_e_tag = event.tags.iter().any(|tag| { | 978 | let has_e_tag = event.tags.iter().any(|tag| { |
| 982 | let slice = tag.as_slice(); | 979 | let slice = tag.as_slice(); |
| 983 | slice.first().is_some_and(|t| t == "e") && | 980 | slice.first().is_some_and(|t| t == "e") && slice.get(3).is_some_and(|m| m == "root") |
| 984 | slice.get(3).is_some_and(|m| m == "root") | ||
| 985 | }); | 981 | }); |
| 986 | assert!(has_e_tag, "Should have 'e' tag with root marker"); | 982 | assert!(has_e_tag, "Should have 'e' tag with root marker"); |
| 987 | } | 983 | } |
| @@ -1038,7 +1034,10 @@ mod tests { | |||
| 1038 | fn test_parse_gauge_without_labels() { | 1034 | fn test_parse_gauge_without_labels() { |
| 1039 | let text = r#"ngit_sync_relays_tracked_total 3"#; | 1035 | let text = r#"ngit_sync_relays_tracked_total 3"#; |
| 1040 | let metrics = ParsedMetrics::parse(text); | 1036 | let metrics = ParsedMetrics::parse(text); |
| 1041 | assert_eq!(metrics.gauge("ngit_sync_relays_tracked_total", &[]), Some(3)); | 1037 | assert_eq!( |
| 1038 | metrics.gauge("ngit_sync_relays_tracked_total", &[]), | ||
| 1039 | Some(3) | ||
| 1040 | ); | ||
| 1042 | } | 1041 | } |
| 1043 | 1042 | ||
| 1044 | #[test] | 1043 | #[test] |
| @@ -1051,9 +1050,6 @@ mod tests { | |||
| 1051 | fn test_parse_metric_with_relay_url_label() { | 1050 | fn test_parse_metric_with_relay_url_label() { |
| 1052 | let text = r#"ngit_sync_relay_connected{relay="ws://127.0.0.1:12345"} 1"#; | 1051 | let text = r#"ngit_sync_relay_connected{relay="ws://127.0.0.1:12345"} 1"#; |
| 1053 | let metrics = ParsedMetrics::parse(text); | 1052 | let metrics = ParsedMetrics::parse(text); |
| 1054 | assert_eq!( | 1053 | assert_eq!(metrics.relay_connected("ws://127.0.0.1:12345"), Some(true)); |
| 1055 | metrics.relay_connected("ws://127.0.0.1:12345"), | ||
| 1056 | Some(true) | ||
| 1057 | ); | ||
| 1058 | } | 1054 | } |
| 1059 | } \ No newline at end of file | 1055 | } |