From 91bf47caf00badecd935bb3dd5acded5b770d7d3 Mon Sep 17 00:00:00 2001
From: R0flcopt3r <12752060+R0flcopt3r@users.noreply.github.com>
Date: Sat, 9 Oct 2021 19:31:34 +0200
Subject: using mockito for testing instead of real websites
---
src/hooks/url.rs | 69 ++++++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 55 insertions(+), 14 deletions(-)
(limited to 'src/hooks/url.rs')
diff --git a/src/hooks/url.rs b/src/hooks/url.rs
index 7847969..939dc52 100644
--- a/src/hooks/url.rs
+++ b/src/hooks/url.rs
@@ -89,17 +89,30 @@ mod tests {
use super::url_parser;
use super::url_title;
use anyhow::{Error, Result};
+ use mockito;
#[test]
fn test_url_titel() {
- let title: String =
- tokio_test::block_on(url_title("https://news.ycombinator.com")).unwrap();
- assert_eq!(title.as_str(), "Hacker News");
-
- let title: String = tokio_test::block_on(url_title("https://google.com")).unwrap();
- assert_eq!(title.as_str(), "Google");
-
- assert!(tokio_test::block_on(url_title("random_site")).is_err())
+ assert!(tokio_test::block_on(url_title(&mockito::server_url())).is_err());
+
+ let _m = mockito::mock("GET", "/")
+ .with_body(
+ r#"
+
+
+ This is test site
+
+
+ some heading
+
+
+"#,
+ )
+ .create();
+ mockito::start();
+
+ let title: String = tokio_test::block_on(url_title(&mockito::server_url())).unwrap();
+ assert_eq!(title.as_str(), "This is test site");
}
#[test]
fn test_url_parser() {
@@ -130,21 +143,49 @@ mod tests {
}
#[test]
+ /**
+ Integration test ish. this tries to replicate url_preview, to make sure
+ everything works together.
+ */
fn test_all() {
+ let _urls = [
+ mockito::mock("GET", "/1")
+ .with_body(
+ r#"
+
+
+ test site 1
+
+
+"#,
+ )
+ .create(),
+ mockito::mock("GET", "/2")
+ .with_body(
+ r#"
+
+
+ test site 2
+
+"#,
+ )
+ .create(),
+ ];
+
let mut titles: Vec = Vec::new();
- let text = "https://news.ycombinator.com www.google.com https://youtube.com";
+ let text = format!(
+ "some text {u}/1 other text {u}/2",
+ u = &mockito::server_url()
+ );
let urls = url_parser(&text);
- assert_eq!(urls.len(), 3);
+ assert_eq!(urls.len(), 2);
for url in &urls {
if let Ok(title) = tokio_test::block_on(url_title(&url.as_str())) {
titles.push(title);
}
}
- assert_eq!(
- msg_builder(&titles),
- "Titles: Hacker News --- Google --- YouTube"
- );
+ assert_eq!(msg_builder(&titles), "Titles: test site 1 --- test site 2");
}
}
--
cgit v1.2.3
'> |
|
|
- add twitter cancel
|
|
yeah nitter
|
|
|
|
- fix non-sasl connection registration
|
|
|
|
|
|
|
|
- update dependencies
- add server password
|
|
|
|
|
|
|
|
|
|
|
|
fuck unicode all my homies stan ascii
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this is due to the url shorterner dying randomly and also just generally
bad idea to call external services during unit tests.
|
|
|
|
|
|
|
|
they in nearly all cases aren't critical enough to warrant an actual
error messages
|
|
|
|
This replaces the sedregex crate with our own implementation for
multiple reasons:
1. We required to access the parsed regex, this required a patch to the
sedregex crate which did not get merged due to an inactive dev, blocking
us from publishing on crates.Io
2. We wanted to highlight the changes done in bold
3. We want to add execution of multiple chained sed commands in the
future which would require more modification
|
|
add an impl off the formatting trait on String to format Strings with
the typical irc formatting codes for bold, italic etc
|
|
|