i5-add-tests (part 3) #9
3 changed files with 18 additions and 11 deletions
|
@ -5,6 +5,9 @@ pub mod history;
|
|||
pub mod prelude;
|
||||
mod subscriptions;
|
||||
|
||||
#[cfg(test)]
|
||||
mod test_utils;
|
||||
|
||||
use feed::FeedEnv;
|
||||
use fetch::FetchEnv;
|
||||
use history::HistoryEnv;
|
||||
|
|
|
@ -17,9 +17,8 @@ pub fn lines_from(file_name: &str) -> Result<Vec<String>> {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::{fs::File, io::Write, str::from_utf8};
|
||||
|
||||
use tempfile::{tempdir, TempDir};
|
||||
use crate::test_utils::create_text_file;
|
||||
|
||||
use super::*;
|
||||
|
||||
|
@ -73,13 +72,4 @@ mod tests {
|
|||
assert_eq!(result, ["@sub1", "@sub3"]);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn create_text_file(name: &str, data: &[u8]) -> Result<(TempDir, String)> {
|
||||
let data = from_utf8(data)?;
|
||||
let dir = tempdir()?;
|
||||
let filename = format!("{}", &dir.path().join(name).display());
|
||||
let file = File::create(&filename)?;
|
||||
write!(&file, "{data}")?;
|
||||
Ok((dir, filename))
|
||||
}
|
||||
}
|
||||
|
|
14
src/test_utils.rs
Normal file
14
src/test_utils.rs
Normal file
|
@ -0,0 +1,14 @@
|
|||
use std::{fs::File, io::Write, str::from_utf8};
|
||||
|
||||
use tempfile::{tempdir, TempDir};
|
||||
|
||||
use crate::prelude::*;
|
||||
|
||||
pub fn create_text_file(name: &str, data: &[u8]) -> Result<(TempDir, String)> {
|
||||
let data = from_utf8(data)?;
|
||||
let dir = tempdir()?;
|
||||
let filename = format!("{}", &dir.path().join(name).display());
|
||||
let file = File::create(&filename)?;
|
||||
write!(&file, "{data}")?;
|
||||
Ok((dir, filename))
|
||||
}
|
Loading…
Add table
Reference in a new issue