What is Nostr?
Kind 1617
git patch: Fix tests for NostrUrlParsed async parsing.
Author Public Key
npub1elta7cneng3w8p9y4dw633qzdjr4kyvaparuyuttyrx6e8xp7xnq32cume
Published at
2024-12-09 22:07:57
Kind type
1617
Event JSON
{ "id": "0aeaf35ec91c2cb47ae49bb9ca277b1a2cc8e46637c170cee9628bdb3446fc1b", "pubkey": "cfd7df62799a22e384a4ab5da8c4026c875b119d0f47c2716b20cdac9cc1f1a6", "created_at": 1733782077, "kind": 1617, "tags": [ [ "a", "30617:a008def15796fba9a0d6fab04e8fd57089285d9fd505da5a83fe8aad57a3564d:ngit" ], [ "r", "26689f97810fc656c7134c76e2a37d33b2e40ce7" ], [ "r", "c052af3eda2fc848d5321c3aa048b881353b5855" ], [ "alt", "git patch: Fix tests for NostrUrlParsed async parsing." ], [ "e", "ff1845c0d52fc6e177767aa2b111b3130c06e2faf57d614080043a135ecb8079", "wss://relay.damus.io", "root" ], [ "e", "ff1845c0d52fc6e177767aa2b111b3130c06e2faf57d614080043a135ecb8079", "wss://relay.damus.io", "reply" ], [ "p", "a008def15796fba9a0d6fab04e8fd57089285d9fd505da5a83fe8aad57a3564d" ], [ "commit", "c052af3eda2fc848d5321c3aa048b881353b5855" ], [ "parent-commit", "b73f311b6eb52f3221b0f0bff9bc31dd17483f3a" ], [ "commit-pgp-sig", "" ], [ "description", "Fix tests for NostrUrlParsed async parsing.\n\nI found no better solution to async testing than actix_rt.\n" ], [ "author", "Laszlo Megyer", "lez@github.com", "1733781983", "60" ], [ "committer", "Laszlo Megyer", "lez@github.com", "1733781983", "60" ] ], "content": "From c052af3eda2fc848d5321c3aa048b881353b5855 Mon Sep 17 00:00:00 2001\nFrom: Laszlo Megyer \u003clez@github.com\u003e\nDate: Mon, 9 Dec 2024 23:06:23 +0100\nSubject: [PATCH 2/2] Fix tests for NostrUrlParsed async parsing.\n\nI found no better solution to async testing than actix_rt.\n---\n Cargo.lock | 24 +++++++++++++++++++++++-\n Cargo.toml | 1 +\n src/lib/git/nostr_url.rs | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------\n 3 files changed, 76 insertions(+), 38 deletions(-)\n\ndiff --git a/Cargo.lock b/Cargo.lock\nindex 819a249..ed123ad 100644\n--- a/Cargo.lock\n+++ b/Cargo.lock\n@@ -3,6 +3,27 @@\n version = 3\n \n [[package]]\n+name = \"actix-macros\"\n+version = \"0.2.4\"\n+source = \"registry+https://github.com/rust-lang/crates.io-index\"\n+checksum = \"e01ed3140b2f8d422c68afa1ed2e85d996ea619c988ac834d255db32138655cb\"\n+dependencies = [\n+ \"quote\",\n+ \"syn 2.0.89\",\n+]\n+\n+[[package]]\n+name = \"actix-rt\"\n+version = \"2.10.0\"\n+source = \"registry+https://github.com/rust-lang/crates.io-index\"\n+checksum = \"24eda4e2a6e042aa4e55ac438a2ae052d3b5da0ecf83d7411e1a368946925208\"\n+dependencies = [\n+ \"actix-macros\",\n+ \"futures-core\",\n+ \"tokio\",\n+]\n+\n+[[package]]\n name = \"addr2line\"\n version = \"0.24.2\"\n source = \"registry+https://github.com/rust-lang/crates.io-index\"\n@@ -1929,6 +1950,7 @@ checksum = \"43a88da9dd148bbcdce323dd6ac47d369b4769d4a3b78c6c52389b9269f77932\"\n name = \"ngit\"\n version = \"1.5.3\"\n dependencies = [\n+ \"actix-rt\",\n \"anyhow\",\n \"assert_cmd\",\n \"async-trait\",\n@@ -2601,7 +2623,7 @@ dependencies = [\n \"once_cell\",\n \"socket2 0.5.7\",\n \"tracing\",\n- \"windows-sys 0.52.0\",\n+ \"windows-sys 0.59.0\",\n ]\n \n [[package]]\ndiff --git a/Cargo.toml b/Cargo.toml\nindex 4af74d0..2606098 100644\n--- a/Cargo.toml\n+++ b/Cargo.toml\n@@ -40,6 +40,7 @@ urlencoding = \"2.1.3\"\n zeroize = \"1.6.0\"\n \n [dev-dependencies]\n+actix-rt = \"2.10.0\"\n assert_cmd = \"2.0.12\"\n duplicate = \"1.0.0\"\n mockall = \"0.11.4\"\ndiff --git a/src/lib/git/nostr_url.rs b/src/lib/git/nostr_url.rs\nindex ac57538..888cc29 100644\n--- a/src/lib/git/nostr_url.rs\n+++ b/src/lib/git/nostr_url.rs\n@@ -950,6 +950,7 @@ mod tests {\n },\n protocol: None,\n user: None,\n+ nip05: None,\n }\n ),\n \"nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/nos.lol/ngit\",\n@@ -975,6 +976,7 @@ mod tests {\n },\n protocol: None,\n user: None,\n+ nip05: None,\n }\n ),\n \"nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit\",\n@@ -1000,6 +1002,7 @@ mod tests {\n },\n protocol: Some(ServerProtocol::Ssh),\n user: None,\n+ nip05: None,\n }\n ),\n \"nostr://ssh/npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/nos.lol/ngit\",\n@@ -1025,6 +1028,7 @@ mod tests {\n },\n protocol: Some(ServerProtocol::Ssh),\n user: Some(\"bla\".to_string()),\n+ nip05: None,\n }\n ),\n \"nostr://bla@ssh/npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/nos.lol/ngit\",\n@@ -1034,8 +1038,6 @@ mod tests {\n }\n \n mod nostr_url_decoded_paramemters_from_str {\n- use std::str::FromStr;\n-\n use super::*;\n \n fn get_model_coordinate(relays: bool) -\u003e Coordinate {\n@@ -1054,11 +1056,11 @@ mod tests {\n }\n }\n \n- #[test]\n- fn from_naddr() -\u003e Result\u003c()\u003e {\n+ #[actix_rt::test]\n+ async fn from_naddr() -\u003e Result\u003c()\u003e {\n let url = \"nostr://naddr1qqzxuemfwsqs6amnwvaz7tmwdaejumr0dspzpgqgmmc409hm4xsdd74sf68a2uyf9pwel4g9mfdg8l5244t6x4jdqvzqqqrhnym0k2qj\".to_string();\n assert_eq!(\n- NostrUrlDecoded::from_str(\u0026url)?,\n+ NostrUrlDecoded::parse_and_resolve(\u0026url, \u0026None).await?,\n NostrUrlDecoded {\n original_string: url.clone(),\n coordinate: Coordinate {\n@@ -1073,6 +1075,7 @@ mod tests {\n },\n protocol: None,\n user: None,\n+ nip05: None,\n },\n );\n Ok(())\n@@ -1081,18 +1084,19 @@ mod tests {\n mod from_npub_slash_identifier {\n use super::*;\n \n- #[test]\n- fn without_relay() -\u003e Result\u003c()\u003e {\n+ #[actix_rt::test]\n+ async fn without_relay() -\u003e Result\u003c()\u003e {\n let url =\n \"nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit\"\n .to_string();\n assert_eq!(\n- NostrUrlDecoded::from_str(\u0026url)?,\n+ NostrUrlDecoded::parse_and_resolve(\u0026url, \u0026None).await?,\n NostrUrlDecoded {\n original_string: url.clone(),\n coordinate: get_model_coordinate(false),\n protocol: None,\n user: None,\n+ nip05: None,\n },\n );\n Ok(())\n@@ -1101,48 +1105,50 @@ mod tests {\n mod with_url_parameters {\n use super::*;\n \n- #[test]\n- fn with_relay_without_scheme_defaults_to_wss() -\u003e Result\u003c()\u003e {\n+ #[actix_rt::test]\n+ async fn with_relay_without_scheme_defaults_to_wss() -\u003e Result\u003c()\u003e {\n let url = \"nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit?relay=nos.lol\".to_string();\n assert_eq!(\n- NostrUrlDecoded::from_str(\u0026url)?,\n+ NostrUrlDecoded::parse_and_resolve(\u0026url, \u0026None).await?,\n NostrUrlDecoded {\n original_string: url.clone(),\n coordinate: get_model_coordinate(true),\n protocol: None,\n user: None,\n+ nip05: None,\n },\n );\n Ok(())\n }\n \n- #[test]\n- fn with_encoded_relay() -\u003e Result\u003c()\u003e {\n+ #[actix_rt::test]\n+ async fn with_encoded_relay() -\u003e Result\u003c()\u003e {\n let url = format!(\n \"nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit?relay={}\",\n urlencoding::encode(\"wss://nos.lol\")\n );\n assert_eq!(\n- NostrUrlDecoded::from_str(\u0026url)?,\n+ NostrUrlDecoded::parse_and_resolve(\u0026url, \u0026None).await?,\n NostrUrlDecoded {\n original_string: url.clone(),\n coordinate: get_model_coordinate(true),\n protocol: None,\n user: None,\n+ nip05: None,\n },\n );\n Ok(())\n }\n \n- #[test]\n- fn with_multiple_encoded_relays() -\u003e Result\u003c()\u003e {\n+ #[actix_rt::test]\n+ async fn with_multiple_encoded_relays() -\u003e Result\u003c()\u003e {\n let url = format!(\n \"nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit?relay={}\u0026relay1={}\",\n urlencoding::encode(\"wss://nos.lol/\"),\n urlencoding::encode(\"wss://relay.damus.io/\"),\n );\n assert_eq!(\n- NostrUrlDecoded::from_str(\u0026url)?,\n+ NostrUrlDecoded::parse_and_resolve(\u0026url, \u0026None).await?,\n NostrUrlDecoded {\n original_string: url.clone(),\n coordinate: Coordinate {\n@@ -1159,36 +1165,40 @@ mod tests {\n },\n protocol: None,\n user: None,\n+ nip05: None,\n },\n );\n Ok(())\n }\n \n- #[test]\n- fn with_server_protocol() -\u003e Result\u003c()\u003e {\n+ #[actix_rt::test]\n+ async fn with_server_protocol() -\u003e Result\u003c()\u003e {\n let url = \"nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit?protocol=ssh\".to_string();\n assert_eq!(\n- NostrUrlDecoded::from_str(\u0026url)?,\n+ NostrUrlDecoded::parse_and_resolve(\u0026url, \u0026None).await?,\n NostrUrlDecoded {\n original_string: url.clone(),\n coordinate: get_model_coordinate(false),\n protocol: Some(ServerProtocol::Ssh),\n user: None,\n+ nip05: None,\n },\n );\n Ok(())\n }\n \n+ #[actix_rt::test]\n #[test]\n- fn with_server_protocol_and_user() -\u003e Result\u003c()\u003e {\n+ async fn with_server_protocol_and_user() -\u003e Result\u003c()\u003e {\n let url = \"nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit?protocol=ssh\u0026user=fred\".to_string();\n assert_eq!(\n- NostrUrlDecoded::from_str(\u0026url)?,\n+ NostrUrlDecoded::parse_and_resolve(\u0026url, \u0026None).await?,\n NostrUrlDecoded {\n original_string: url.clone(),\n coordinate: get_model_coordinate(false),\n protocol: Some(ServerProtocol::Ssh),\n user: Some(\"fred\".to_string()),\n+ nip05: None,\n },\n );\n Ok(())\n@@ -1198,48 +1208,50 @@ mod tests {\n mod with_parameters_embedded_with_slashes {\n use super::*;\n \n- #[test]\n- fn with_relay_without_scheme_defaults_to_wss() -\u003e Result\u003c()\u003e {\n+ #[actix_rt::test]\n+ async fn with_relay_without_scheme_defaults_to_wss() -\u003e Result\u003c()\u003e {\n let url = \"nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/nos.lol/ngit\".to_string();\n assert_eq!(\n- NostrUrlDecoded::from_str(\u0026url)?,\n+ NostrUrlDecoded::parse_and_resolve(\u0026url, \u0026None).await?,\n NostrUrlDecoded {\n original_string: url.clone(),\n coordinate: get_model_coordinate(true),\n protocol: None,\n user: None,\n+ nip05: None,\n },\n );\n Ok(())\n }\n \n- #[test]\n- fn with_encoded_relay() -\u003e Result\u003c()\u003e {\n+ #[actix_rt::test]\n+ async fn with_encoded_relay() -\u003e Result\u003c()\u003e {\n let url = format!(\n \"nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/{}/ngit\",\n urlencoding::encode(\"wss://nos.lol\")\n );\n assert_eq!(\n- NostrUrlDecoded::from_str(\u0026url)?,\n+ NostrUrlDecoded::parse_and_resolve(\u0026url, \u0026None).await?,\n NostrUrlDecoded {\n original_string: url.clone(),\n coordinate: get_model_coordinate(true),\n protocol: None,\n user: None,\n+ nip05: None,\n },\n );\n Ok(())\n }\n \n- #[test]\n- fn with_multiple_encoded_relays() -\u003e Result\u003c()\u003e {\n+ #[actix_rt::test]\n+ async fn with_multiple_encoded_relays() -\u003e Result\u003c()\u003e {\n let url = format!(\n \"nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/{}/{}/ngit\",\n urlencoding::encode(\"wss://nos.lol/\"),\n urlencoding::encode(\"wss://relay.damus.io/\"),\n );\n assert_eq!(\n- NostrUrlDecoded::from_str(\u0026url)?,\n+ NostrUrlDecoded::parse_and_resolve(\u0026url, \u0026None).await?,\n NostrUrlDecoded {\n original_string: url.clone(),\n coordinate: Coordinate {\n@@ -1256,36 +1268,39 @@ mod tests {\n },\n protocol: None,\n user: None,\n+ nip05: None,\n },\n );\n Ok(())\n }\n \n- #[test]\n- fn with_server_protocol() -\u003e Result\u003c()\u003e {\n+ #[actix_rt::test]\n+ async fn with_server_protocol() -\u003e Result\u003c()\u003e {\n let url = \"nostr://ssh/npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit\".to_string();\n assert_eq!(\n- NostrUrlDecoded::from_str(\u0026url)?,\n+ NostrUrlDecoded::parse_and_resolve(\u0026url, \u0026None).await?,\n NostrUrlDecoded {\n original_string: url.clone(),\n coordinate: get_model_coordinate(false),\n protocol: Some(ServerProtocol::Ssh),\n user: None,\n+ nip05: None,\n },\n );\n Ok(())\n }\n \n- #[test]\n- fn with_server_protocol_and_user() -\u003e Result\u003c()\u003e {\n+ #[actix_rt::test]\n+ async fn with_server_protocol_and_user() -\u003e Result\u003c()\u003e {\n let url = \"nostr://fred@ssh/npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit\".to_string();\n assert_eq!(\n- NostrUrlDecoded::from_str(\u0026url)?,\n+ NostrUrlDecoded::parse_and_resolve(\u0026url, \u0026None).await?,\n NostrUrlDecoded {\n original_string: url.clone(),\n coordinate: get_model_coordinate(false),\n protocol: Some(ServerProtocol::Ssh),\n user: Some(\"fred\".to_string()),\n+ nip05: None,\n },\n );\n Ok(())\n--\nlibgit2 1.8.1\n\n", "sig": "c9b6648665bfe486c403f3a872657b7a1372fda3237065ab8a63b7158f60b155cdaef059f5604aeb77ac6e6efadd8169a68db9ee09e7bdf71ba02270f60aa493" }