diff options
| author | Laszlo Megyer <lez@github.com> | 2024-12-09 23:06:23 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-12-10 11:55:25 +0000 |
| commit | 8bd0f64bfc1d8348aaac11c9882e6211599df320 (patch) | |
| tree | 05703a76dbe942fa0f49c3a6d0e1667684e2b0b8 /src/lib/git/nostr_url.rs | |
| parent | 6d3a4eb870cd344b11ccda13e1339584ed4e4d17 (diff) | |
test(NostrUrlDecoded): use `parse_and_resolve`
update tests to use the async `parse_and_resolve` instead of removed
`from_str` method
Diffstat (limited to 'src/lib/git/nostr_url.rs')
| -rw-r--r-- | src/lib/git/nostr_url.rs | 90 |
1 files changed, 52 insertions, 38 deletions
diff --git a/src/lib/git/nostr_url.rs b/src/lib/git/nostr_url.rs index ac57538..6f418d5 100644 --- a/src/lib/git/nostr_url.rs +++ b/src/lib/git/nostr_url.rs | |||
| @@ -950,6 +950,7 @@ mod tests { | |||
| 950 | }, | 950 | }, |
| 951 | protocol: None, | 951 | protocol: None, |
| 952 | user: None, | 952 | user: None, |
| 953 | nip05: None, | ||
| 953 | } | 954 | } |
| 954 | ), | 955 | ), |
| 955 | "nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/nos.lol/ngit", | 956 | "nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/nos.lol/ngit", |
| @@ -975,6 +976,7 @@ mod tests { | |||
| 975 | }, | 976 | }, |
| 976 | protocol: None, | 977 | protocol: None, |
| 977 | user: None, | 978 | user: None, |
| 979 | nip05: None, | ||
| 978 | } | 980 | } |
| 979 | ), | 981 | ), |
| 980 | "nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit", | 982 | "nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit", |
| @@ -1000,6 +1002,7 @@ mod tests { | |||
| 1000 | }, | 1002 | }, |
| 1001 | protocol: Some(ServerProtocol::Ssh), | 1003 | protocol: Some(ServerProtocol::Ssh), |
| 1002 | user: None, | 1004 | user: None, |
| 1005 | nip05: None, | ||
| 1003 | } | 1006 | } |
| 1004 | ), | 1007 | ), |
| 1005 | "nostr://ssh/npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/nos.lol/ngit", | 1008 | "nostr://ssh/npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/nos.lol/ngit", |
| @@ -1025,6 +1028,7 @@ mod tests { | |||
| 1025 | }, | 1028 | }, |
| 1026 | protocol: Some(ServerProtocol::Ssh), | 1029 | protocol: Some(ServerProtocol::Ssh), |
| 1027 | user: Some("bla".to_string()), | 1030 | user: Some("bla".to_string()), |
| 1031 | nip05: None, | ||
| 1028 | } | 1032 | } |
| 1029 | ), | 1033 | ), |
| 1030 | "nostr://bla@ssh/npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/nos.lol/ngit", | 1034 | "nostr://bla@ssh/npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/nos.lol/ngit", |
| @@ -1034,8 +1038,6 @@ mod tests { | |||
| 1034 | } | 1038 | } |
| 1035 | 1039 | ||
| 1036 | mod nostr_url_decoded_paramemters_from_str { | 1040 | mod nostr_url_decoded_paramemters_from_str { |
| 1037 | use std::str::FromStr; | ||
| 1038 | |||
| 1039 | use super::*; | 1041 | use super::*; |
| 1040 | 1042 | ||
| 1041 | fn get_model_coordinate(relays: bool) -> Coordinate { | 1043 | fn get_model_coordinate(relays: bool) -> Coordinate { |
| @@ -1054,11 +1056,11 @@ mod tests { | |||
| 1054 | } | 1056 | } |
| 1055 | } | 1057 | } |
| 1056 | 1058 | ||
| 1057 | #[test] | 1059 | #[tokio::test] |
| 1058 | fn from_naddr() -> Result<()> { | 1060 | async fn from_naddr() -> Result<()> { |
| 1059 | let url = "nostr://naddr1qqzxuemfwsqs6amnwvaz7tmwdaejumr0dspzpgqgmmc409hm4xsdd74sf68a2uyf9pwel4g9mfdg8l5244t6x4jdqvzqqqrhnym0k2qj".to_string(); | 1061 | let url = "nostr://naddr1qqzxuemfwsqs6amnwvaz7tmwdaejumr0dspzpgqgmmc409hm4xsdd74sf68a2uyf9pwel4g9mfdg8l5244t6x4jdqvzqqqrhnym0k2qj".to_string(); |
| 1060 | assert_eq!( | 1062 | assert_eq!( |
| 1061 | NostrUrlDecoded::from_str(&url)?, | 1063 | NostrUrlDecoded::parse_and_resolve(&url, &None).await?, |
| 1062 | NostrUrlDecoded { | 1064 | NostrUrlDecoded { |
| 1063 | original_string: url.clone(), | 1065 | original_string: url.clone(), |
| 1064 | coordinate: Coordinate { | 1066 | coordinate: Coordinate { |
| @@ -1073,6 +1075,7 @@ mod tests { | |||
| 1073 | }, | 1075 | }, |
| 1074 | protocol: None, | 1076 | protocol: None, |
| 1075 | user: None, | 1077 | user: None, |
| 1078 | nip05: None, | ||
| 1076 | }, | 1079 | }, |
| 1077 | ); | 1080 | ); |
| 1078 | Ok(()) | 1081 | Ok(()) |
| @@ -1081,18 +1084,19 @@ mod tests { | |||
| 1081 | mod from_npub_slash_identifier { | 1084 | mod from_npub_slash_identifier { |
| 1082 | use super::*; | 1085 | use super::*; |
| 1083 | 1086 | ||
| 1084 | #[test] | 1087 | #[tokio::test] |
| 1085 | fn without_relay() -> Result<()> { | 1088 | async fn without_relay() -> Result<()> { |
| 1086 | let url = | 1089 | let url = |
| 1087 | "nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit" | 1090 | "nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit" |
| 1088 | .to_string(); | 1091 | .to_string(); |
| 1089 | assert_eq!( | 1092 | assert_eq!( |
| 1090 | NostrUrlDecoded::from_str(&url)?, | 1093 | NostrUrlDecoded::parse_and_resolve(&url, &None).await?, |
| 1091 | NostrUrlDecoded { | 1094 | NostrUrlDecoded { |
| 1092 | original_string: url.clone(), | 1095 | original_string: url.clone(), |
| 1093 | coordinate: get_model_coordinate(false), | 1096 | coordinate: get_model_coordinate(false), |
| 1094 | protocol: None, | 1097 | protocol: None, |
| 1095 | user: None, | 1098 | user: None, |
| 1099 | nip05: None, | ||
| 1096 | }, | 1100 | }, |
| 1097 | ); | 1101 | ); |
| 1098 | Ok(()) | 1102 | Ok(()) |
| @@ -1101,48 +1105,50 @@ mod tests { | |||
| 1101 | mod with_url_parameters { | 1105 | mod with_url_parameters { |
| 1102 | use super::*; | 1106 | use super::*; |
| 1103 | 1107 | ||
| 1104 | #[test] | 1108 | #[tokio::test] |
| 1105 | fn with_relay_without_scheme_defaults_to_wss() -> Result<()> { | 1109 | async fn with_relay_without_scheme_defaults_to_wss() -> Result<()> { |
| 1106 | let url = "nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit?relay=nos.lol".to_string(); | 1110 | let url = "nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit?relay=nos.lol".to_string(); |
| 1107 | assert_eq!( | 1111 | assert_eq!( |
| 1108 | NostrUrlDecoded::from_str(&url)?, | 1112 | NostrUrlDecoded::parse_and_resolve(&url, &None).await?, |
| 1109 | NostrUrlDecoded { | 1113 | NostrUrlDecoded { |
| 1110 | original_string: url.clone(), | 1114 | original_string: url.clone(), |
| 1111 | coordinate: get_model_coordinate(true), | 1115 | coordinate: get_model_coordinate(true), |
| 1112 | protocol: None, | 1116 | protocol: None, |
| 1113 | user: None, | 1117 | user: None, |
| 1118 | nip05: None, | ||
| 1114 | }, | 1119 | }, |
| 1115 | ); | 1120 | ); |
| 1116 | Ok(()) | 1121 | Ok(()) |
| 1117 | } | 1122 | } |
| 1118 | 1123 | ||
| 1119 | #[test] | 1124 | #[tokio::test] |
| 1120 | fn with_encoded_relay() -> Result<()> { | 1125 | async fn with_encoded_relay() -> Result<()> { |
| 1121 | let url = format!( | 1126 | let url = format!( |
| 1122 | "nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit?relay={}", | 1127 | "nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit?relay={}", |
| 1123 | urlencoding::encode("wss://nos.lol") | 1128 | urlencoding::encode("wss://nos.lol") |
| 1124 | ); | 1129 | ); |
| 1125 | assert_eq!( | 1130 | assert_eq!( |
| 1126 | NostrUrlDecoded::from_str(&url)?, | 1131 | NostrUrlDecoded::parse_and_resolve(&url, &None).await?, |
| 1127 | NostrUrlDecoded { | 1132 | NostrUrlDecoded { |
| 1128 | original_string: url.clone(), | 1133 | original_string: url.clone(), |
| 1129 | coordinate: get_model_coordinate(true), | 1134 | coordinate: get_model_coordinate(true), |
| 1130 | protocol: None, | 1135 | protocol: None, |
| 1131 | user: None, | 1136 | user: None, |
| 1137 | nip05: None, | ||
| 1132 | }, | 1138 | }, |
| 1133 | ); | 1139 | ); |
| 1134 | Ok(()) | 1140 | Ok(()) |
| 1135 | } | 1141 | } |
| 1136 | 1142 | ||
| 1137 | #[test] | 1143 | #[tokio::test] |
| 1138 | fn with_multiple_encoded_relays() -> Result<()> { | 1144 | async fn with_multiple_encoded_relays() -> Result<()> { |
| 1139 | let url = format!( | 1145 | let url = format!( |
| 1140 | "nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit?relay={}&relay1={}", | 1146 | "nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit?relay={}&relay1={}", |
| 1141 | urlencoding::encode("wss://nos.lol/"), | 1147 | urlencoding::encode("wss://nos.lol/"), |
| 1142 | urlencoding::encode("wss://relay.damus.io/"), | 1148 | urlencoding::encode("wss://relay.damus.io/"), |
| 1143 | ); | 1149 | ); |
| 1144 | assert_eq!( | 1150 | assert_eq!( |
| 1145 | NostrUrlDecoded::from_str(&url)?, | 1151 | NostrUrlDecoded::parse_and_resolve(&url, &None).await?, |
| 1146 | NostrUrlDecoded { | 1152 | NostrUrlDecoded { |
| 1147 | original_string: url.clone(), | 1153 | original_string: url.clone(), |
| 1148 | coordinate: Coordinate { | 1154 | coordinate: Coordinate { |
| @@ -1159,36 +1165,39 @@ mod tests { | |||
| 1159 | }, | 1165 | }, |
| 1160 | protocol: None, | 1166 | protocol: None, |
| 1161 | user: None, | 1167 | user: None, |
| 1168 | nip05: None, | ||
| 1162 | }, | 1169 | }, |
| 1163 | ); | 1170 | ); |
| 1164 | Ok(()) | 1171 | Ok(()) |
| 1165 | } | 1172 | } |
| 1166 | 1173 | ||
| 1167 | #[test] | 1174 | #[tokio::test] |
| 1168 | fn with_server_protocol() -> Result<()> { | 1175 | async fn with_server_protocol() -> Result<()> { |
| 1169 | let url = "nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit?protocol=ssh".to_string(); | 1176 | let url = "nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit?protocol=ssh".to_string(); |
| 1170 | assert_eq!( | 1177 | assert_eq!( |
| 1171 | NostrUrlDecoded::from_str(&url)?, | 1178 | NostrUrlDecoded::parse_and_resolve(&url, &None).await?, |
| 1172 | NostrUrlDecoded { | 1179 | NostrUrlDecoded { |
| 1173 | original_string: url.clone(), | 1180 | original_string: url.clone(), |
| 1174 | coordinate: get_model_coordinate(false), | 1181 | coordinate: get_model_coordinate(false), |
| 1175 | protocol: Some(ServerProtocol::Ssh), | 1182 | protocol: Some(ServerProtocol::Ssh), |
| 1176 | user: None, | 1183 | user: None, |
| 1184 | nip05: None, | ||
| 1177 | }, | 1185 | }, |
| 1178 | ); | 1186 | ); |
| 1179 | Ok(()) | 1187 | Ok(()) |
| 1180 | } | 1188 | } |
| 1181 | 1189 | ||
| 1182 | #[test] | 1190 | #[tokio::test] |
| 1183 | fn with_server_protocol_and_user() -> Result<()> { | 1191 | async fn with_server_protocol_and_user() -> Result<()> { |
| 1184 | let url = "nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit?protocol=ssh&user=fred".to_string(); | 1192 | let url = "nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit?protocol=ssh&user=fred".to_string(); |
| 1185 | assert_eq!( | 1193 | assert_eq!( |
| 1186 | NostrUrlDecoded::from_str(&url)?, | 1194 | NostrUrlDecoded::parse_and_resolve(&url, &None).await?, |
| 1187 | NostrUrlDecoded { | 1195 | NostrUrlDecoded { |
| 1188 | original_string: url.clone(), | 1196 | original_string: url.clone(), |
| 1189 | coordinate: get_model_coordinate(false), | 1197 | coordinate: get_model_coordinate(false), |
| 1190 | protocol: Some(ServerProtocol::Ssh), | 1198 | protocol: Some(ServerProtocol::Ssh), |
| 1191 | user: Some("fred".to_string()), | 1199 | user: Some("fred".to_string()), |
| 1200 | nip05: None, | ||
| 1192 | }, | 1201 | }, |
| 1193 | ); | 1202 | ); |
| 1194 | Ok(()) | 1203 | Ok(()) |
| @@ -1198,48 +1207,50 @@ mod tests { | |||
| 1198 | mod with_parameters_embedded_with_slashes { | 1207 | mod with_parameters_embedded_with_slashes { |
| 1199 | use super::*; | 1208 | use super::*; |
| 1200 | 1209 | ||
| 1201 | #[test] | 1210 | #[tokio::test] |
| 1202 | fn with_relay_without_scheme_defaults_to_wss() -> Result<()> { | 1211 | async fn with_relay_without_scheme_defaults_to_wss() -> Result<()> { |
| 1203 | let url = "nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/nos.lol/ngit".to_string(); | 1212 | let url = "nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/nos.lol/ngit".to_string(); |
| 1204 | assert_eq!( | 1213 | assert_eq!( |
| 1205 | NostrUrlDecoded::from_str(&url)?, | 1214 | NostrUrlDecoded::parse_and_resolve(&url, &None).await?, |
| 1206 | NostrUrlDecoded { | 1215 | NostrUrlDecoded { |
| 1207 | original_string: url.clone(), | 1216 | original_string: url.clone(), |
| 1208 | coordinate: get_model_coordinate(true), | 1217 | coordinate: get_model_coordinate(true), |
| 1209 | protocol: None, | 1218 | protocol: None, |
| 1210 | user: None, | 1219 | user: None, |
| 1220 | nip05: None, | ||
| 1211 | }, | 1221 | }, |
| 1212 | ); | 1222 | ); |
| 1213 | Ok(()) | 1223 | Ok(()) |
| 1214 | } | 1224 | } |
| 1215 | 1225 | ||
| 1216 | #[test] | 1226 | #[tokio::test] |
| 1217 | fn with_encoded_relay() -> Result<()> { | 1227 | async fn with_encoded_relay() -> Result<()> { |
| 1218 | let url = format!( | 1228 | let url = format!( |
| 1219 | "nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/{}/ngit", | 1229 | "nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/{}/ngit", |
| 1220 | urlencoding::encode("wss://nos.lol") | 1230 | urlencoding::encode("wss://nos.lol") |
| 1221 | ); | 1231 | ); |
| 1222 | assert_eq!( | 1232 | assert_eq!( |
| 1223 | NostrUrlDecoded::from_str(&url)?, | 1233 | NostrUrlDecoded::parse_and_resolve(&url, &None).await?, |
| 1224 | NostrUrlDecoded { | 1234 | NostrUrlDecoded { |
| 1225 | original_string: url.clone(), | 1235 | original_string: url.clone(), |
| 1226 | coordinate: get_model_coordinate(true), | 1236 | coordinate: get_model_coordinate(true), |
| 1227 | protocol: None, | 1237 | protocol: None, |
| 1228 | user: None, | 1238 | user: None, |
| 1239 | nip05: None, | ||
| 1229 | }, | 1240 | }, |
| 1230 | ); | 1241 | ); |
| 1231 | Ok(()) | 1242 | Ok(()) |
| 1232 | } | 1243 | } |
| 1233 | 1244 | ||
| 1234 | #[test] | 1245 | #[tokio::test] |
| 1235 | fn with_multiple_encoded_relays() -> Result<()> { | 1246 | async fn with_multiple_encoded_relays() -> Result<()> { |
| 1236 | let url = format!( | 1247 | let url = format!( |
| 1237 | "nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/{}/{}/ngit", | 1248 | "nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/{}/{}/ngit", |
| 1238 | urlencoding::encode("wss://nos.lol/"), | 1249 | urlencoding::encode("wss://nos.lol/"), |
| 1239 | urlencoding::encode("wss://relay.damus.io/"), | 1250 | urlencoding::encode("wss://relay.damus.io/"), |
| 1240 | ); | 1251 | ); |
| 1241 | assert_eq!( | 1252 | assert_eq!( |
| 1242 | NostrUrlDecoded::from_str(&url)?, | 1253 | NostrUrlDecoded::parse_and_resolve(&url, &None).await?, |
| 1243 | NostrUrlDecoded { | 1254 | NostrUrlDecoded { |
| 1244 | original_string: url.clone(), | 1255 | original_string: url.clone(), |
| 1245 | coordinate: Coordinate { | 1256 | coordinate: Coordinate { |
| @@ -1256,36 +1267,39 @@ mod tests { | |||
| 1256 | }, | 1267 | }, |
| 1257 | protocol: None, | 1268 | protocol: None, |
| 1258 | user: None, | 1269 | user: None, |
| 1270 | nip05: None, | ||
| 1259 | }, | 1271 | }, |
| 1260 | ); | 1272 | ); |
| 1261 | Ok(()) | 1273 | Ok(()) |
| 1262 | } | 1274 | } |
| 1263 | 1275 | ||
| 1264 | #[test] | 1276 | #[tokio::test] |
| 1265 | fn with_server_protocol() -> Result<()> { | 1277 | async fn with_server_protocol() -> Result<()> { |
| 1266 | let url = "nostr://ssh/npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit".to_string(); | 1278 | let url = "nostr://ssh/npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit".to_string(); |
| 1267 | assert_eq!( | 1279 | assert_eq!( |
| 1268 | NostrUrlDecoded::from_str(&url)?, | 1280 | NostrUrlDecoded::parse_and_resolve(&url, &None).await?, |
| 1269 | NostrUrlDecoded { | 1281 | NostrUrlDecoded { |
| 1270 | original_string: url.clone(), | 1282 | original_string: url.clone(), |
| 1271 | coordinate: get_model_coordinate(false), | 1283 | coordinate: get_model_coordinate(false), |
| 1272 | protocol: Some(ServerProtocol::Ssh), | 1284 | protocol: Some(ServerProtocol::Ssh), |
| 1273 | user: None, | 1285 | user: None, |
| 1286 | nip05: None, | ||
| 1274 | }, | 1287 | }, |
| 1275 | ); | 1288 | ); |
| 1276 | Ok(()) | 1289 | Ok(()) |
| 1277 | } | 1290 | } |
| 1278 | 1291 | ||
| 1279 | #[test] | 1292 | #[tokio::test] |
| 1280 | fn with_server_protocol_and_user() -> Result<()> { | 1293 | async fn with_server_protocol_and_user() -> Result<()> { |
| 1281 | let url = "nostr://fred@ssh/npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit".to_string(); | 1294 | let url = "nostr://fred@ssh/npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit".to_string(); |
| 1282 | assert_eq!( | 1295 | assert_eq!( |
| 1283 | NostrUrlDecoded::from_str(&url)?, | 1296 | NostrUrlDecoded::parse_and_resolve(&url, &None).await?, |
| 1284 | NostrUrlDecoded { | 1297 | NostrUrlDecoded { |
| 1285 | original_string: url.clone(), | 1298 | original_string: url.clone(), |
| 1286 | coordinate: get_model_coordinate(false), | 1299 | coordinate: get_model_coordinate(false), |
| 1287 | protocol: Some(ServerProtocol::Ssh), | 1300 | protocol: Some(ServerProtocol::Ssh), |
| 1288 | user: Some("fred".to_string()), | 1301 | user: Some("fred".to_string()), |
| 1302 | nip05: None, | ||
| 1289 | }, | 1303 | }, |
| 1290 | ); | 1304 | ); |
| 1291 | Ok(()) | 1305 | Ok(()) |