diff options
Diffstat (limited to 'test_utils/src/lib.rs')
| -rw-r--r-- | test_utils/src/lib.rs | 54 |
1 files changed, 32 insertions, 22 deletions
diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs index 5c8d7a5..66d0df5 100644 --- a/test_utils/src/lib.rs +++ b/test_utils/src/lib.rs | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | use std::{ | 1 | use std::{ |
| 2 | collections::HashSet, | ||
| 2 | ffi::OsStr, | 3 | ffi::OsStr, |
| 3 | path::{Path, PathBuf}, | 4 | path::{Path, PathBuf}, |
| 4 | str::FromStr, | 5 | str::FromStr, |
| @@ -8,13 +9,13 @@ use std::{ | |||
| 8 | 9 | ||
| 9 | use anyhow::{Context, Result, bail, ensure}; | 10 | use anyhow::{Context, Result, bail, ensure}; |
| 10 | use dialoguer::theme::{ColorfulTheme, Theme}; | 11 | use dialoguer::theme::{ColorfulTheme, Theme}; |
| 11 | use futures::executor::block_on; | 12 | use futures::{executor::block_on, future::join_all}; |
| 12 | use git::GitTestRepo; | 13 | use git::GitTestRepo; |
| 13 | use git2::{Signature, Time}; | 14 | use git2::{Signature, Time}; |
| 14 | use nostr::{self, Kind, Tag, nips::nip65::RelayMetadata}; | 15 | use nostr::{self, Kind, Tag, nips::nip65::RelayMetadata}; |
| 15 | use nostr_database::NostrEventsDatabase; | 16 | use nostr_database::NostrEventsDatabase; |
| 16 | use nostr_lmdb::NostrLMDB; | 17 | use nostr_lmdb::NostrLMDB; |
| 17 | use nostr_sdk::{Client, NostrSigner, TagStandard, serde_json}; | 18 | use nostr_sdk::{Client, Event, NostrSigner, TagStandard, serde_json}; |
| 18 | use once_cell::sync::Lazy; | 19 | use once_cell::sync::Lazy; |
| 19 | use rexpect::session::{Options, PtySession}; | 20 | use rexpect::session::{Options, PtySession}; |
| 20 | use strip_ansi_escapes::strip_str; | 21 | use strip_ansi_escapes::strip_str; |
| @@ -139,7 +140,7 @@ pub fn make_event_old_or_change_user( | |||
| 139 | &keys.public_key(), | 140 | &keys.public_key(), |
| 140 | &unsigned.created_at, | 141 | &unsigned.created_at, |
| 141 | &unsigned.kind, | 142 | &unsigned.kind, |
| 142 | &unsigned.tags.clone().to_vec(), | 143 | &unsigned.tags.clone(), |
| 143 | &unsigned.content, | 144 | &unsigned.content, |
| 144 | )); | 145 | )); |
| 145 | 146 | ||
| @@ -1107,14 +1108,24 @@ pub async fn get_events_from_cache( | |||
| 1107 | git_repo_path: &Path, | 1108 | git_repo_path: &Path, |
| 1108 | filters: Vec<nostr::Filter>, | 1109 | filters: Vec<nostr::Filter>, |
| 1109 | ) -> Result<Vec<nostr::Event>> { | 1110 | ) -> Result<Vec<nostr::Event>> { |
| 1110 | Ok(get_local_cache_database(git_repo_path) | 1111 | let db = get_local_cache_database(git_repo_path).await?; |
| 1111 | .await? | 1112 | |
| 1112 | .query(filters.clone()) | 1113 | let query_results = join_all(filters.into_iter().map(|filter| async { |
| 1113 | .await | 1114 | db.query(filter).await.context( |
| 1114 | .context( | ||
| 1115 | "failed to execute query on opened git repo nostr cache database .git/nostr-cache.lmdb", | 1115 | "failed to execute query on opened git repo nostr cache database .git/nostr-cache.lmdb", |
| 1116 | )? | 1116 | ) |
| 1117 | .to_vec()) | 1117 | })) |
| 1118 | .await; | ||
| 1119 | |||
| 1120 | // no Event is being mutated, just new items added to the set | ||
| 1121 | #[allow(clippy::mutable_key_type)] | ||
| 1122 | let mut events: HashSet<Event> = HashSet::new(); | ||
| 1123 | |||
| 1124 | for result in query_results { | ||
| 1125 | events.extend(result?); | ||
| 1126 | } | ||
| 1127 | |||
| 1128 | Ok(events.into_iter().collect()) | ||
| 1118 | } | 1129 | } |
| 1119 | 1130 | ||
| 1120 | pub fn get_proposal_branch_name( | 1131 | pub fn get_proposal_branch_name( |
| @@ -1436,19 +1447,18 @@ fn get_first_proposal_event_id() -> Result<nostr::EventId> { | |||
| 1436 | Handle::current().block_on(client.add_relay("ws://localhost:8055"))?; | 1447 | Handle::current().block_on(client.add_relay("ws://localhost:8055"))?; |
| 1437 | Handle::current().block_on(client.connect_relay("ws://localhost:8055"))?; | 1448 | Handle::current().block_on(client.connect_relay("ws://localhost:8055"))?; |
| 1438 | let proposals = Handle::current() | 1449 | let proposals = Handle::current() |
| 1439 | .block_on(client.fetch_events( | 1450 | .block_on( |
| 1440 | vec![ | 1451 | client.fetch_events( |
| 1441 | nostr::Filter::default() | 1452 | nostr::Filter::default() |
| 1442 | .kind(nostr::Kind::GitPatch) | 1453 | .kind(nostr::Kind::GitPatch) |
| 1443 | .custom_tag( | 1454 | .custom_tags(nostr::SingleLetterTag::lowercase(nostr::Alphabet::T), vec![ |
| 1444 | nostr::SingleLetterTag::lowercase(nostr::Alphabet::T), | 1455 | "root", |
| 1445 | vec!["root"], | 1456 | ]), |
| 1446 | ), | 1457 | Duration::from_millis(500), |
| 1447 | ], | 1458 | ), |
| 1448 | Some(Duration::from_millis(500)), | 1459 | )? |
| 1449 | ))? | ||
| 1450 | .to_vec(); | 1460 | .to_vec(); |
| 1451 | Handle::current().block_on(client.disconnect())?; | 1461 | Handle::current().block_on(client.disconnect()); |
| 1452 | 1462 | ||
| 1453 | let proposal_1_id = proposals | 1463 | let proposal_1_id = proposals |
| 1454 | .iter() | 1464 | .iter() |