|
|
|
@ -1,5 +1,5 @@ |
|
|
|
|
use crate::error::unexpected::{self, Intoable, Mappable}; |
|
|
|
|
use crate::origin; |
|
|
|
|
use crate::{origin, util}; |
|
|
|
|
|
|
|
|
|
use std::path::{Path, PathBuf}; |
|
|
|
|
use std::{collections, fs, io, sync}; |
|
|
|
@ -334,12 +334,11 @@ impl super::Store for FSStore { |
|
|
|
|
Ok(()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// TODO test this
|
|
|
|
|
fn get_file<'store>( |
|
|
|
|
&'store self, |
|
|
|
|
descr: &origin::Descr, |
|
|
|
|
path: &str, |
|
|
|
|
) -> Result<stream::BoxStream<'static, io::Result<Vec<u8>>>, origin::GetFileError> { |
|
|
|
|
) -> Result<util::BoxByteStream, origin::GetFileError> { |
|
|
|
|
let repo_snapshot = match self.get_repo_snapshot(descr) { |
|
|
|
|
Ok(Some(repo_snapshot)) => repo_snapshot, |
|
|
|
|
Ok(None) => return Err(origin::GetFileError::DescrNotSynced), |
|
|
|
@ -382,10 +381,11 @@ impl super::Store for FSStore { |
|
|
|
|
#[cfg(test)] |
|
|
|
|
mod tests { |
|
|
|
|
use crate::origin::{self, Store}; |
|
|
|
|
use futures::StreamExt; |
|
|
|
|
use tempdir::TempDir; |
|
|
|
|
|
|
|
|
|
#[test] |
|
|
|
|
fn basic() { |
|
|
|
|
#[tokio::test] |
|
|
|
|
async fn basic() { |
|
|
|
|
let tmp_dir = TempDir::new("origin_store_git").unwrap(); |
|
|
|
|
|
|
|
|
|
let curr_dir = format!("file://{}", std::env::current_dir().unwrap().display()); |
|
|
|
@ -405,31 +405,32 @@ mod tests { |
|
|
|
|
store.sync(&descr).expect("sync should succeed"); |
|
|
|
|
store.sync(&descr).expect("second sync should succeed"); |
|
|
|
|
|
|
|
|
|
let assert_write = |path: &str| { |
|
|
|
|
{ |
|
|
|
|
// RepoSnapshot doesn't exist
|
|
|
|
|
let mut into: Vec<u8> = vec![]; |
|
|
|
|
store |
|
|
|
|
.read_file_into(&descr, path, &mut into) |
|
|
|
|
.expect("write should succeed"); |
|
|
|
|
assert!(into.len() > 0); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
assert_write("src/lib.rs"); |
|
|
|
|
assert_write("/src/lib.rs"); |
|
|
|
|
assert!(matches!( |
|
|
|
|
store.read_file_into(&other_descr, "DNE", &mut into), |
|
|
|
|
Err::<_, origin::ReadFileIntoError>(origin::ReadFileIntoError::DescrNotSynced), |
|
|
|
|
)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let mut into: Vec<u8> = vec![]; |
|
|
|
|
let assert_file_dne = |path: &str| match store.get_file(&descr, path) { |
|
|
|
|
Err(origin::ReadFileIntoError::FileNotFound) => (), |
|
|
|
|
_ => assert!(false, "file should have not been found"), |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// RepoSnapshot doesn't exist
|
|
|
|
|
assert!(matches!( |
|
|
|
|
store.read_file_into(&other_descr, "DNE", &mut into), |
|
|
|
|
Err::<_, origin::ReadFileIntoError>(origin::ReadFileIntoError::DescrNotSynced), |
|
|
|
|
)); |
|
|
|
|
let assert_file_not_empty = |path: &str| { |
|
|
|
|
let f = store.get_file(&descr, path).expect("file not retrieved"); |
|
|
|
|
async move { |
|
|
|
|
let body = f.map(|r| r.unwrap()).concat().await; |
|
|
|
|
assert!(body.len() > 0); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// File doesn't exist
|
|
|
|
|
assert!(matches!( |
|
|
|
|
store.read_file_into(&descr, "DNE", &mut into), |
|
|
|
|
Err::<(), origin::ReadFileIntoError>(origin::ReadFileIntoError::FileNotFound), |
|
|
|
|
)); |
|
|
|
|
assert_eq!(into.len(), 0); |
|
|
|
|
assert_file_not_empty("src/lib.rs").await; |
|
|
|
|
assert_file_not_empty("/src/lib.rs").await; |
|
|
|
|
assert_file_dne("DNE"); |
|
|
|
|
assert_file_dne("src/../src/lib.rs"); |
|
|
|
|
|
|
|
|
|
let descrs = store.all_descrs().expect("all_descrs called"); |
|
|
|
|
|
|
|
|
|