use anyhow::Result; use meridian::context::{web::WebContext, ContextSession}; use reqwest::Url; const WEB_URLS: &[&str] = &[ "https://docs.getmoose.dev", "https://docs.awesomeapi.com.br/api-de-moedas", ]; const API_URLS: &[&str] = &["https://economia.awesomeapi.com.br/"]; #[test] fn test_web_scrape() -> Result<()> { let mut web_context = WebContext::new(); for url in WEB_URLS { web_context.add_content_from_static_site_url(&Url::parse(url)?)?; } println!("{:?}", web_context.get_sites_content()); Ok(()) } #[test] fn test_web_scrape_into_context_items() -> Result<()> { let mut web_context = WebContext::new(); for url in WEB_URLS { web_context.add_content_from_static_site_url(&Url::parse(url)?)?; } let mut session = ContextSession::new()?; session.add_web_context_to_session(web_context)?; assert_eq!(session.get_context().get_items().len(), 2); Ok(()) } #[test] fn test_web_scrape_into_context_items_and_save() -> Result<()> { let mut web_context = WebContext::new(); for url in WEB_URLS { web_context.add_content_from_static_site_url(&Url::parse(url)?)?; } let mut session = ContextSession::new()?; session.add_web_context_to_session(web_context)?; session.save_context()?; Ok(()) } #[test] fn test_api_scrape_into_context_items_and_save() { let mut web_context = WebContext::new(); for url in API_URLS { web_context .add_content_from_api_url(&Url::parse(url).unwrap()) .unwrap(); } let mut session = ContextSession::try_resume().unwrap(); session.add_web_context_to_session(web_context).unwrap(); session.save_context().unwrap(); }