i5-add-tests (part 3) #9

Merged
kemitix merged 28 commits from i5-add-tests into main 2023-07-29 20:36:04 +01:00
7 changed files with 10 additions and 37 deletions
Showing only changes of commit 95ed1735e7 - Show all commits

View file

@ -7,12 +7,6 @@ mod find;
pub use find::find;
pub struct FeedEnv {
pub find: FeedFind,
}
pub type FeedFind = fn(&str, &str, &NetworkEnv) -> Result<String>;
pub fn get(url: &str, e: &NetworkEnv) -> Result<Feed> {
let content = (e.fetch_as_bytes)(url)?;
let channel = Feed::read_from(&content[..])?;

View file

@ -1,6 +1,5 @@
use crate::prelude::*;
use crate::{history::Link, prelude::*};
use atom_syndication::Link;
use std::process::Command;
pub struct FetchEnv {

View file

@ -1,9 +1,10 @@
use crate::prelude::*;
use atom_syndication::Link;
use std::fs::OpenOptions;
use std::io::prelude::*;
use super::Link;
pub fn add(link: &Link, file_name: &str) -> Result<()> {
let mut file = OpenOptions::new()
.write(true)

View file

@ -1,8 +1,9 @@
use crate::{file::FileEnv, prelude::*};
use atom_syndication::Link;
use std::io::{BufRead, BufReader};
use super::Link;
pub fn find(link: &Link, file_name: &str, e: &FileEnv) -> Result<bool> {
if let Ok(file) = (e.open)(file_name) {
let reader = BufReader::new(file);

View file

@ -1,17 +1,7 @@
use crate::{file::FileEnv, prelude::*};
mod add;
mod find;
pub use add::add;
pub use find::find;
type Link = atom_syndication::Link;
pub struct HistoryEnv {
pub find: HistoryFind,
pub add: HistoryAdd,
}
pub type HistoryFind = fn(&Link, &str, &FileEnv) -> Result<bool>;
pub type HistoryAdd = fn(&Link, &str) -> Result<()>;
pub type Link = atom_syndication::Link;

View file

@ -9,17 +9,13 @@ pub mod prelude;
#[cfg(test)]
mod test_utils;
use feed::FeedEnv;
use fetch::FetchEnv;
use file::FileEnv;
use history::HistoryEnv;
use network::NetworkEnv;
use prelude::*;
pub struct Env {
pub feed: FeedEnv,
pub network: NetworkEnv,
pub history: HistoryEnv,
pub fetch: FetchEnv,
pub file: FileEnv,
}
@ -27,13 +23,13 @@ pub struct Env {
pub fn run(subscriptions: &str, history: &str, site: &str, e: Env) -> Result<()> {
for channel_name in file::read::lines_from(subscriptions, &e.file)? {
println!("Channel: {}", channel_name);
let feed_url = (e.feed.find)(site, &channel_name, &e.network)?;
let feed_url = feed::find(site, &channel_name, &e.network)?;
for entry in feed::get(&feed_url, &e.network)?.entries() {
if let Some(link) = entry.links().get(0).cloned() {
if !(e.history.find)(&link, history, &e.file)? {
if !history::find(&link, history, &e.file)? {
println!("Downloading {}: {}", &channel_name, entry.title().as_str());
(e.fetch.download)(&link)?;
(e.history.add)(&link, history)?;
history::add(&link, history)?;
}
}
}

View file

@ -2,7 +2,7 @@ use podal::file::FileEnv;
use podal::network::NetworkEnv;
use podal::prelude::*;
use podal::{feed::FeedEnv, fetch::FetchEnv, history::HistoryEnv};
use podal::fetch::FetchEnv;
fn main() -> Result<()> {
println!("Podal");
@ -15,14 +15,6 @@ fn main() -> Result<()> {
history,
site,
podal::Env {
feed: FeedEnv {
find: podal::feed::find,
},
history: HistoryEnv {
find: podal::history::find,
add: podal::history::add,
},
fetch: FetchEnv {
download: podal::fetch::download,
},