diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-07-23 16:36:06 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-07-23 16:36:06 +0100 |
| commit | b67376ff54abeab31422921ba5f4883d5d3dccdb (patch) | |
| tree | d4f4194fdf2d285332dd7aacea31678042389b00 /test_utils | |
| parent | 643fa17fde858c2d6f934dcc435eb84843cc172e (diff) | |
feat(list): unique proposal branch names
to prevent accidental name conflicts. also moved to prs/* namespace
`pull` and `push` integration tests are intermitantly failing to end
at least for `push` they work when run individually but not
when run together
Diffstat (limited to 'test_utils')
| -rw-r--r-- | test_utils/Cargo.toml | 3 | ||||
| -rw-r--r-- | test_utils/src/lib.rs | 60 |
2 files changed, 62 insertions, 1 deletions
diff --git a/test_utils/Cargo.toml b/test_utils/Cargo.toml index b7010c9..2e4c012 100644 --- a/test_utils/Cargo.toml +++ b/test_utils/Cargo.toml | |||
| @@ -8,9 +8,12 @@ anyhow = "1.0.75" | |||
| 8 | assert_cmd = "2.0.12" | 8 | assert_cmd = "2.0.12" |
| 9 | dialoguer = "0.10.4" | 9 | dialoguer = "0.10.4" |
| 10 | directories = "5.0.1" | 10 | directories = "5.0.1" |
| 11 | futures = "0.3.28" | ||
| 11 | git2 = "0.18.1" | 12 | git2 = "0.18.1" |
| 12 | nostr = "0.33.0" | 13 | nostr = "0.33.0" |
| 14 | nostr-database = "0.33.0" | ||
| 13 | nostr-sdk = "0.33.0" | 15 | nostr-sdk = "0.33.0" |
| 16 | nostr-sqlite = "0.33.0" | ||
| 14 | once_cell = "1.18.0" | 17 | once_cell = "1.18.0" |
| 15 | rand = "0.8" | 18 | rand = "0.8" |
| 16 | rexpect = { git = "https://github.com/rust-cli/rexpect.git", rev = "9eb61dd" } | 19 | rexpect = { git = "https://github.com/rust-cli/rexpect.git", rev = "9eb61dd" } |
diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs index a2ed5f2..de7aee5 100644 --- a/test_utils/src/lib.rs +++ b/test_utils/src/lib.rs | |||
| @@ -1,9 +1,17 @@ | |||
| 1 | use std::{ffi::OsStr, path::PathBuf, str::FromStr}; | 1 | use std::{ |
| 2 | ffi::OsStr, | ||
| 3 | path::{Path, PathBuf}, | ||
| 4 | str::FromStr, | ||
| 5 | }; | ||
| 2 | 6 | ||
| 3 | use anyhow::{bail, ensure, Context, Result}; | 7 | use anyhow::{bail, ensure, Context, Result}; |
| 4 | use dialoguer::theme::{ColorfulTheme, Theme}; | 8 | use dialoguer::theme::{ColorfulTheme, Theme}; |
| 9 | use futures::executor::block_on; | ||
| 10 | use git::GitTestRepo; | ||
| 5 | use nostr::{self, nips::nip65::RelayMetadata, Kind, Tag}; | 11 | use nostr::{self, nips::nip65::RelayMetadata, Kind, Tag}; |
| 12 | use nostr_database::{NostrDatabase, Order}; | ||
| 6 | use nostr_sdk::{serde_json, NostrSigner, TagStandard}; | 13 | use nostr_sdk::{serde_json, NostrSigner, TagStandard}; |
| 14 | use nostr_sqlite::SQLiteDatabase; | ||
| 7 | use once_cell::sync::Lazy; | 15 | use once_cell::sync::Lazy; |
| 8 | use rexpect::session::{Options, PtySession}; | 16 | use rexpect::session::{Options, PtySession}; |
| 9 | use strip_ansi_escapes::strip_str; | 17 | use strip_ansi_escapes::strip_str; |
| @@ -935,3 +943,53 @@ where | |||
| 935 | }, | 943 | }, |
| 936 | ) | 944 | ) |
| 937 | } | 945 | } |
| 946 | |||
| 947 | /** copied from client.rs */ | ||
| 948 | async fn get_local_cache_database(git_repo_path: &Path) -> Result<SQLiteDatabase> { | ||
| 949 | SQLiteDatabase::open(git_repo_path.join(".git/nostr-cache.sqlite")) | ||
| 950 | .await | ||
| 951 | .context("cannot open or create nostr cache database at .git/nostr-cache.sqlite") | ||
| 952 | } | ||
| 953 | |||
| 954 | /** copied from client.rs */ | ||
| 955 | pub async fn get_events_from_cache( | ||
| 956 | git_repo_path: &Path, | ||
| 957 | filters: Vec<nostr::Filter>, | ||
| 958 | ) -> Result<Vec<nostr::Event>> { | ||
| 959 | get_local_cache_database(git_repo_path) | ||
| 960 | .await? | ||
| 961 | .query(filters.clone(), Order::Asc) | ||
| 962 | .await | ||
| 963 | .context( | ||
| 964 | "cannot execute query on opened git repo nostr cache database .git/nostr-cache.sqlite", | ||
| 965 | ) | ||
| 966 | } | ||
| 967 | |||
| 968 | pub fn get_proposal_branch_name( | ||
| 969 | test_repo: &GitTestRepo, | ||
| 970 | branch_name_in_event: &str, | ||
| 971 | ) -> Result<String> { | ||
| 972 | let events = block_on(get_events_from_cache( | ||
| 973 | &test_repo.dir, | ||
| 974 | vec![ | ||
| 975 | nostr::Filter::default() | ||
| 976 | .kind(nostr_sdk::Kind::GitPatch) | ||
| 977 | .hashtag("root"), | ||
| 978 | ], | ||
| 979 | ))?; | ||
| 980 | for event in events { | ||
| 981 | if event.iter_tags().any(|t| { | ||
| 982 | !t.as_vec()[1].eq("revision-root") | ||
| 983 | && event.iter_tags().any(|t| { | ||
| 984 | t.as_vec()[0].eq("branch-name") && t.as_vec()[1].eq(branch_name_in_event) | ||
| 985 | }) | ||
| 986 | }) { | ||
| 987 | return Ok(format!( | ||
| 988 | "prs/{}({})", | ||
| 989 | branch_name_in_event, | ||
| 990 | &event.id.to_hex().as_str()[..8], | ||
| 991 | )); | ||
| 992 | } | ||
| 993 | } | ||
| 994 | bail!("cannot find proposal root with branch-name tag matching title") | ||
| 995 | } | ||