use super::Message;
use super::Service;
use std::error::Error;
use std::sync::mpsc::{Receiver, Sender};
#[derive(Default)]
pub struct Scraper {
name: String,
rx: Option<Receiver<Message>>,
tx: Option<Sender<Message>>,
}
impl Scraper {
pub fn new() -> Self {
Scraper {
..Default::default()
}
}
}
impl Service for Scraper {
fn identify(&self) -> String {
"scraper".to_string()
}
fn run(&self) -> Result<(), Box<dyn Error>> {
Ok(())
}
fn send(&self, msg: Message) -> Result<(), Box<dyn Error>> {
Ok(())
}
fn set_comm_pair(&mut self, tx: Sender<Message>, rx: Receiver<Message>) -> () {
self.tx = Some(tx);
self.rx = Some(rx);
}
}
#[cfg(test)]
mod tests {
use super::*;
use std::{fs, path::Path, thread::Scope};
fn clean() -> Result<(), Box<dyn std::error::Error>> {
let log_dir_path = Path::new("logs/tests");
if log_dir_path.exists() {
fs::remove_dir_all(log_dir_path)?;
println!("Successfully removed {}", log_dir_path.display());
} else {
println!("Directory {} does not exist.", log_dir_path.display());
}
Ok(())
}
#[test]
fn test_scraper() {
let s = Scraper::new();
}
}