diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2023-10-01 00:00:00 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2023-10-01 00:00:00 +0100 |
| commit | 000901c0cbca8464b5a89bcc93c5474f6564bafd (patch) | |
| tree | 0ae11836c173ec6246e8b1eab7dc1e265e125426 /test_utils/src/lib.rs | |
| parent | b9a88672b8734448615354e3f46748d2fdc2f647 (diff) | |
feat(prs-create) send to multiple relays
add tests but these currently don't work when run together
Diffstat (limited to 'test_utils/src/lib.rs')
| -rw-r--r-- | test_utils/src/lib.rs | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs index 0f870f6..a9d818c 100644 --- a/test_utils/src/lib.rs +++ b/test_utils/src/lib.rs | |||
| @@ -9,6 +9,7 @@ use rexpect::session::{Options, PtySession}; | |||
| 9 | use strip_ansi_escapes::strip_str; | 9 | use strip_ansi_escapes::strip_str; |
| 10 | 10 | ||
| 11 | pub mod git; | 11 | pub mod git; |
| 12 | pub mod relay; | ||
| 12 | 13 | ||
| 13 | pub static TEST_KEY_1_NSEC: &str = | 14 | pub static TEST_KEY_1_NSEC: &str = |
| 14 | "nsec1ppsg5sm2aexq06juxmu9evtutr6jkwkhp98exxxvwamhru9lyx9s3rwseq"; | 15 | "nsec1ppsg5sm2aexq06juxmu9evtutr6jkwkhp98exxxvwamhru9lyx9s3rwseq"; |
| @@ -353,7 +354,12 @@ impl CliTester { | |||
| 353 | } | 354 | } |
| 354 | 355 | ||
| 355 | /// returns what came before expected message | 356 | /// returns what came before expected message |
| 356 | pub fn expect_eventually(&mut self, message: &str) -> Result<String> { | 357 | pub fn expect_eventually<S>(&mut self, message: S) -> Result<String> |
| 358 | where | ||
| 359 | S: Into<String>, | ||
| 360 | { | ||
| 361 | let message_string = message.into(); | ||
| 362 | let message = message_string.as_str(); | ||
| 357 | let before = self | 363 | let before = self |
| 358 | .rexpect_session | 364 | .rexpect_session |
| 359 | .exp_string(message) | 365 | .exp_string(message) |
| @@ -361,8 +367,27 @@ impl CliTester { | |||
| 361 | Ok(before) | 367 | Ok(before) |
| 362 | } | 368 | } |
| 363 | 369 | ||
| 364 | pub fn expect(&mut self, message: &str) -> Result<&mut Self> { | 370 | pub fn expect_after_whitespace<S>(&mut self, message: S) -> Result<&mut Self> |
| 371 | where | ||
| 372 | S: Into<String>, | ||
| 373 | { | ||
| 374 | assert_eq!("", self.expect_eventually(message)?.trim()); | ||
| 375 | Ok(self) | ||
| 376 | } | ||
| 377 | |||
| 378 | pub fn expect<S>(&mut self, message: S) -> Result<&mut Self> | ||
| 379 | where | ||
| 380 | S: Into<String>, | ||
| 381 | { | ||
| 382 | let message_string = message.into(); | ||
| 383 | let message = message_string.as_str(); | ||
| 365 | let before = self.expect_eventually(message)?; | 384 | let before = self.expect_eventually(message)?; |
| 385 | if !before.is_empty() { | ||
| 386 | std::fs::write("aaaaaaaaaaaa.txt", before.clone())?; | ||
| 387 | |||
| 388 | // let mut output = std::fs::File::create("aaaaaaaaaaa.txt")?; | ||
| 389 | // write!(output, "{}", *before); | ||
| 390 | } | ||
| 366 | ensure!( | 391 | ensure!( |
| 367 | before.is_empty(), | 392 | before.is_empty(), |
| 368 | format!( | 393 | format!( |
| @@ -397,6 +422,16 @@ impl CliTester { | |||
| 397 | assert_eq!(before, message); | 422 | assert_eq!(before, message); |
| 398 | Ok(()) | 423 | Ok(()) |
| 399 | } | 424 | } |
| 425 | |||
| 426 | pub fn expect_end_with_whitespace(&mut self) -> Result<()> { | ||
| 427 | let before = self | ||
| 428 | .rexpect_session | ||
| 429 | .exp_eof() | ||
| 430 | .context("expected immediate end but got timed out")?; | ||
| 431 | assert_eq!(before.trim(), ""); | ||
| 432 | Ok(()) | ||
| 433 | } | ||
| 434 | |||
| 400 | pub fn expect_end_eventually(&mut self) -> Result<String> { | 435 | pub fn expect_end_eventually(&mut self) -> Result<String> { |
| 401 | self.rexpect_session | 436 | self.rexpect_session |
| 402 | .exp_eof() | 437 | .exp_eof() |