i3-cli-download-dir #12
3 changed files with 0 additions and 12 deletions
|
@ -18,14 +18,11 @@ impl FileEnv {
|
||||||
Self {
|
Self {
|
||||||
open: Box::new(move |file_name| {
|
open: Box::new(move |file_name| {
|
||||||
let path = format!("{}/{}", &open_dir, file_name);
|
let path = format!("{}/{}", &open_dir, file_name);
|
||||||
println!("opening {}", path);
|
|
||||||
let file = File::open(&path)?;
|
let file = File::open(&path)?;
|
||||||
println!("opened {}", path);
|
|
||||||
Ok(file)
|
Ok(file)
|
||||||
}),
|
}),
|
||||||
append_line: Box::new(move |file_name, line| {
|
append_line: Box::new(move |file_name, line| {
|
||||||
let path = format!("{}/{}", &append_dir, file_name);
|
let path = format!("{}/{}", &append_dir, file_name);
|
||||||
println!("appending to {}", path);
|
|
||||||
let mut file = OpenOptions::new()
|
let mut file = OpenOptions::new()
|
||||||
.write(true)
|
.write(true)
|
||||||
.append(true)
|
.append(true)
|
||||||
|
@ -33,7 +30,6 @@ impl FileEnv {
|
||||||
.open(&path)
|
.open(&path)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
writeln!(file, "{}", line)?;
|
writeln!(file, "{}", line)?;
|
||||||
println!("appended to {}", path);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ use crate::prelude::*;
|
||||||
use super::Link;
|
use super::Link;
|
||||||
|
|
||||||
pub fn add(link: &Link, file_name: &str, e: &FileEnv) -> Result<()> {
|
pub fn add(link: &Link, file_name: &str, e: &FileEnv) -> Result<()> {
|
||||||
println!("history::append::to {}", file_name);
|
|
||||||
(e.append_line)(file_name, &link.href)?;
|
(e.append_line)(file_name, &link.href)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -25,7 +24,6 @@ mod tests {
|
||||||
let file_name = "download.txt";
|
let file_name = "download.txt";
|
||||||
let dir = create_text_file(file_name, include_bytes!("../../test/data/empty.txt"))?;
|
let dir = create_text_file(file_name, include_bytes!("../../test/data/empty.txt"))?;
|
||||||
let path = format!("{}/{}", dir.path().to_string_lossy(), file_name);
|
let path = format!("{}/{}", dir.path().to_string_lossy(), file_name);
|
||||||
println!("removing file {}", path);
|
|
||||||
std::fs::remove_file(path)?;
|
std::fs::remove_file(path)?;
|
||||||
|
|
||||||
let link = Link {
|
let link = Link {
|
||||||
|
@ -37,18 +35,14 @@ mod tests {
|
||||||
length: None,
|
length: None,
|
||||||
};
|
};
|
||||||
//when
|
//when
|
||||||
println!("about to add");
|
|
||||||
add(
|
add(
|
||||||
&link,
|
&link,
|
||||||
file_name,
|
file_name,
|
||||||
&FileEnv::create(dir.path().to_string_lossy().to_string()),
|
&FileEnv::create(dir.path().to_string_lossy().to_string()),
|
||||||
)?;
|
)?;
|
||||||
println!("called add");
|
|
||||||
|
|
||||||
//then
|
//then
|
||||||
println!("about to read file contents");
|
|
||||||
let content: Vec<String> = read_text_file(dir.path(), file_name)?;
|
let content: Vec<String> = read_text_file(dir.path(), file_name)?;
|
||||||
println!("read file contents");
|
|
||||||
drop(dir);
|
drop(dir);
|
||||||
|
|
||||||
let expected = vec!["foo".to_string()];
|
let expected = vec!["foo".to_string()];
|
||||||
|
|
|
@ -27,7 +27,6 @@ pub fn create_text_file(name: &str, data: &[u8]) -> Result<TempDir> {
|
||||||
|
|
||||||
pub fn read_text_file(path: &Path, file_name: &str) -> Result<Vec<String>> {
|
pub fn read_text_file(path: &Path, file_name: &str) -> Result<Vec<String>> {
|
||||||
let file_name = format!("{}/{}", path.to_str().unwrap(), file_name);
|
let file_name = format!("{}/{}", path.to_str().unwrap(), file_name);
|
||||||
println!("test_utils::read_text_file: {}", file_name);
|
|
||||||
Ok(read_to_string(file_name)?
|
Ok(read_to_string(file_name)?
|
||||||
.lines()
|
.lines()
|
||||||
.map(String::from)
|
.map(String::from)
|
||||||
|
@ -64,7 +63,6 @@ pub fn mock_network_fetch_as_bytes_with_rss_entries(
|
||||||
pub fn mock_file_open(real_paths: HashMap<String, String>) -> FileOpenFn {
|
pub fn mock_file_open(real_paths: HashMap<String, String>) -> FileOpenFn {
|
||||||
Box::new(move |path: &str| {
|
Box::new(move |path: &str| {
|
||||||
if let Some(real_path) = real_paths.get(&path.to_string()) {
|
if let Some(real_path) = real_paths.get(&path.to_string()) {
|
||||||
println!("opening {}", real_path);
|
|
||||||
Ok(File::open(real_path)?)
|
Ok(File::open(real_path)?)
|
||||||
} else {
|
} else {
|
||||||
Err(Error::message(
|
Err(Error::message(
|
||||||
|
|
Loading…
Add table
Reference in a new issue