upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/test_utils/src
diff options
context:
space:
mode:
Diffstat (limited to 'test_utils/src')
-rw-r--r--test_utils/src/lib.rs69
-rw-r--r--test_utils/src/relay.rs26
2 files changed, 52 insertions, 43 deletions
diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs
index daed8fa..1d881cf 100644
--- a/test_utils/src/lib.rs
+++ b/test_utils/src/lib.rs
@@ -3,8 +3,8 @@ use std::{ffi::OsStr, path::PathBuf, str::FromStr};
3use anyhow::{bail, ensure, Context, Result}; 3use anyhow::{bail, ensure, Context, Result};
4use dialoguer::theme::{ColorfulTheme, Theme}; 4use dialoguer::theme::{ColorfulTheme, Theme};
5use directories::ProjectDirs; 5use directories::ProjectDirs;
6use nostr::{self, Kind, Tag}; 6use nostr::{self, nips::nip65::RelayMetadata, Kind, Tag};
7use nostr_sdk::serde_json; 7use nostr_sdk::{serde_json, TagStandard};
8use once_cell::sync::Lazy; 8use once_cell::sync::Lazy;
9use rexpect::session::{Options, PtySession}; 9use rexpect::session::{Options, PtySession};
10use strip_ansi_escapes::strip_str; 10use strip_ansi_escapes::strip_str;
@@ -12,8 +12,8 @@ use strip_ansi_escapes::strip_str;
12pub mod git; 12pub mod git;
13pub mod relay; 13pub mod relay;
14 14
15pub static PATCH_KIND: u64 = 1617; 15pub static PATCH_KIND: u16 = 1617;
16pub static REPOSITORY_KIND: u64 = 30617; 16pub static REPOSITORY_KIND: u16 = 30617;
17 17
18pub static TEST_KEY_1_NSEC: &str = 18pub static TEST_KEY_1_NSEC: &str =
19 "nsec1ppsg5sm2aexq06juxmu9evtutr6jkwkhp98exxxvwamhru9lyx9s3rwseq"; 19 "nsec1ppsg5sm2aexq06juxmu9evtutr6jkwkhp98exxxvwamhru9lyx9s3rwseq";
@@ -54,15 +54,18 @@ pub fn generate_test_key_1_relay_list_event() -> nostr::Event {
54 nostr::Kind::RelayList, 54 nostr::Kind::RelayList,
55 "", 55 "",
56 [ 56 [
57 nostr::Tag::RelayMetadata( 57 nostr::Tag::from_standardized(nostr::TagStandard::RelayMetadata {
58 "ws://localhost:8053".into(), 58 relay_url: nostr::Url::from_str("ws://localhost:8053").unwrap(),
59 Some(nostr::RelayMetadata::Write), 59 metadata: Some(RelayMetadata::Write),
60 ), 60 }),
61 nostr::Tag::RelayMetadata( 61 nostr::Tag::from_standardized(nostr::TagStandard::RelayMetadata {
62 "ws://localhost:8054".into(), 62 relay_url: nostr::Url::from_str("ws://localhost:8054").unwrap(),
63 Some(nostr::RelayMetadata::Read), 63 metadata: Some(RelayMetadata::Read),
64 ), 64 }),
65 nostr::Tag::RelayMetadata("ws://localhost:8055".into(), None), 65 nostr::Tag::from_standardized(nostr::TagStandard::RelayMetadata {
66 relay_url: nostr::Url::from_str("ws://localhost:8055").unwrap(),
67 metadata: None,
68 }),
66 ], 69 ],
67 ) 70 )
68 .to_event(&TEST_KEY_1_KEYS) 71 .to_event(&TEST_KEY_1_KEYS)
@@ -74,14 +77,14 @@ pub fn generate_test_key_1_relay_list_event_same_as_fallback() -> nostr::Event {
74 nostr::Kind::RelayList, 77 nostr::Kind::RelayList,
75 "", 78 "",
76 [ 79 [
77 nostr::Tag::RelayMetadata( 80 nostr::Tag::from_standardized(nostr::TagStandard::RelayMetadata {
78 "ws://localhost:8051".into(), 81 relay_url: nostr::Url::from_str("ws://localhost:8051").unwrap(),
79 Some(nostr::RelayMetadata::Write), 82 metadata: Some(RelayMetadata::Write),
80 ), 83 }),
81 nostr::Tag::RelayMetadata( 84 nostr::Tag::from_standardized(nostr::TagStandard::RelayMetadata {
82 "ws://localhost:8052".into(), 85 relay_url: nostr::Url::from_str("ws://localhost:8052").unwrap(),
83 Some(nostr::RelayMetadata::Write), 86 metadata: Some(RelayMetadata::Write),
84 ), 87 }),
85 ], 88 ],
86 ) 89 )
87 .to_event(&TEST_KEY_1_KEYS) 90 .to_event(&TEST_KEY_1_KEYS)
@@ -141,33 +144,33 @@ pub fn generate_repo_ref_event() -> nostr::Event {
141 nostr::Kind::Custom(REPOSITORY_KIND), 144 nostr::Kind::Custom(REPOSITORY_KIND),
142 "", 145 "",
143 [ 146 [
144 Tag::Identifier( 147 Tag::identifier(
145 // root_commit.to_string() 148 // root_commit.to_string()
146 format!("{}-consider-it-random", root_commit), 149 format!("{}-consider-it-random", root_commit),
147 ), 150 ),
148 Tag::Reference(root_commit.into()), 151 Tag::from_standardized(TagStandard::Reference(root_commit.to_string())),
149 Tag::Name("example name".into()), 152 Tag::from_standardized(TagStandard::Name("example name".into())),
150 Tag::Description("example description".into()), 153 Tag::from_standardized(TagStandard::Description("example description".into())),
151 Tag::Generic( 154 Tag::custom(
152 nostr::TagKind::Custom("clone".to_string()), 155 nostr::TagKind::Custom(std::borrow::Cow::Borrowed("clone")),
153 vec!["git:://123.gitexample.com/test".to_string()], 156 vec!["git:://123.gitexample.com/test".to_string()],
154 ), 157 ),
155 Tag::Generic( 158 Tag::custom(
156 nostr::TagKind::Custom("web".to_string()), 159 nostr::TagKind::Custom(std::borrow::Cow::Borrowed("web")),
157 vec![ 160 vec![
158 "https://exampleproject.xyz".to_string(), 161 "https://exampleproject.xyz".to_string(),
159 "https://gitworkshop.dev/123".to_string(), 162 "https://gitworkshop.dev/123".to_string(),
160 ], 163 ],
161 ), 164 ),
162 Tag::Generic( 165 Tag::custom(
163 nostr::TagKind::Custom("relays".to_string()), 166 nostr::TagKind::Custom(std::borrow::Cow::Borrowed("relays")),
164 vec![ 167 vec![
165 "ws://localhost:8055".to_string(), 168 "ws://localhost:8055".to_string(),
166 "ws://localhost:8056".to_string(), 169 "ws://localhost:8056".to_string(),
167 ], 170 ],
168 ), 171 ),
169 Tag::Generic( 172 Tag::custom(
170 nostr::TagKind::Custom("maintainers".to_string()), 173 nostr::TagKind::Custom(std::borrow::Cow::Borrowed("maintainers")),
171 vec![ 174 vec![
172 TEST_KEY_1_KEYS.public_key().to_string(), 175 TEST_KEY_1_KEYS.public_key().to_string(),
173 TEST_KEY_2_KEYS.public_key().to_string(), 176 TEST_KEY_2_KEYS.public_key().to_string(),
diff --git a/test_utils/src/relay.rs b/test_utils/src/relay.rs
index e47ab5d..82a8f8d 100644
--- a/test_utils/src/relay.rs
+++ b/test_utils/src/relay.rs
@@ -255,21 +255,27 @@ pub fn expect_send_with_progress(
255 " - {} -------------------- 0/{event_count}", 255 " - {} -------------------- 0/{event_count}",
256 &relays[0].0 256 &relays[0].0
257 ))?; 257 ))?;
258 for relay in &relays { 258 let last_relay_outcome = outcome_message(relays.last().unwrap());
259 // if successful 259 let mut s = String::new();
260 if relay.1 { 260 loop {
261 p.expect_eventually(format!(" y {}", relay.0))?; 261 s.push_str(&p.expect_eventually(&last_relay_outcome)?);
262 } else { 262 s.push_str(&last_relay_outcome);
263 p.expect_eventually(format!(" x {} {}", relay.0, relay.2))?; 263 if relays.iter().all(|r| s.contains(&outcome_message(r))) {
264 // all responses have been received with correct outcome
265 break;
264 } 266 }
265 // could check that before only contains titles:
266 // - # y x n/n and whitespace
267 // let before = p.expect_eventually(format!(" â {title}"))?;
268 // assert_eq!("", before.trim());
269 } 267 }
270 Ok(()) 268 Ok(())
271} 269}
272 270
271fn outcome_message(relay: &(&str, bool, &str)) -> String {
272 if relay.1 {
273 format!(" y {}", relay.0)
274 } else {
275 format!(" x {} {}", relay.0, relay.2)
276 }
277}
278
273pub fn expect_send_with_progress_exact_interaction( 279pub fn expect_send_with_progress_exact_interaction(
274 p: &mut CliTester, 280 p: &mut CliTester,
275 titles: Vec<&str>, 281 titles: Vec<&str>,