Compare commits
No commits in common. "1a1e1e4c5ad5339bb7448b6145b2874ccc5f2eac" and "644d2bab23381d5bcdb8c48480dce8f12ccda65e" have entirely different histories.
1a1e1e4c5a
...
644d2bab23
@ -1,7 +1,7 @@
|
|||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
use std::{error, fmt};
|
use std::{error, fmt};
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone)]
|
||||||
/// Error is a String which implements the Error trait. It is intended to be used in
|
/// Error is a String which implements the Error trait. It is intended to be used in
|
||||||
/// situations where the caller is being given an error they can't really handle, except to pass it
|
/// situations where the caller is being given an error they can't really handle, except to pass it
|
||||||
/// along or log it.
|
/// along or log it.
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#![feature(result_option_inspect)]
|
#![feature(result_option_inspect)]
|
||||||
#![feature(iterator_try_collect)]
|
#![feature(iterator_try_collect)]
|
||||||
#![feature(iter_collect_into)]
|
|
||||||
|
|
||||||
pub mod domain;
|
pub mod domain;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
|
@ -3,14 +3,13 @@ use crate::origin;
|
|||||||
use std::sync;
|
use std::sync;
|
||||||
|
|
||||||
pub mod git;
|
pub mod git;
|
||||||
pub mod mux;
|
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub struct Limits {
|
pub struct Limits {
|
||||||
// TODO storage limits
|
// TODO storage limits
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(thiserror::Error, Clone, Debug, PartialEq)]
|
#[derive(thiserror::Error, Debug)]
|
||||||
pub enum SyncError {
|
pub enum SyncError {
|
||||||
#[error("invalid url")]
|
#[error("invalid url")]
|
||||||
InvalidURL,
|
InvalidURL,
|
||||||
@ -25,7 +24,7 @@ pub enum SyncError {
|
|||||||
Unexpected(#[from] unexpected::Error),
|
Unexpected(#[from] unexpected::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(thiserror::Error, Clone, Debug, PartialEq)]
|
#[derive(thiserror::Error, Debug)]
|
||||||
pub enum GetError {
|
pub enum GetError {
|
||||||
#[error("not found")]
|
#[error("not found")]
|
||||||
NotFound,
|
NotFound,
|
||||||
@ -34,7 +33,7 @@ pub enum GetError {
|
|||||||
Unexpected(#[from] unexpected::Error),
|
Unexpected(#[from] unexpected::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(thiserror::Error, Clone, Debug, PartialEq)]
|
#[derive(thiserror::Error, Debug)]
|
||||||
pub enum AllDescrsError {
|
pub enum AllDescrsError {
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
Unexpected(#[from] unexpected::Error),
|
Unexpected(#[from] unexpected::Error),
|
||||||
|
@ -323,7 +323,9 @@ impl super::Store for Store {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::origin::{self, store};
|
use crate::origin::store;
|
||||||
|
use crate::origin::store::Store;
|
||||||
|
use crate::origin::{self, Origin};
|
||||||
use tempdir::TempDir;
|
use tempdir::TempDir;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -381,9 +383,13 @@ mod tests {
|
|||||||
));
|
));
|
||||||
assert_eq!(into.len(), 0);
|
assert_eq!(into.len(), 0);
|
||||||
|
|
||||||
let descrs = store.all_descrs().expect("all_descrs called");
|
let descrs = store
|
||||||
|
.all_descrs()
|
||||||
|
.expect("all_descrs called")
|
||||||
|
.into_iter()
|
||||||
|
.collect::<Vec<Result<origin::Descr, store::AllDescrsError>>>();
|
||||||
|
|
||||||
assert_eq!(1, descrs.len());
|
assert_eq!(1, descrs.len());
|
||||||
assert_eq!(descr, descrs[0]);
|
assert_eq!(&descr, descrs[0].as_ref().unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,94 +0,0 @@
|
|||||||
use crate::error::unexpected::Mappable;
|
|
||||||
use crate::origin::{self, store};
|
|
||||||
use std::sync;
|
|
||||||
|
|
||||||
struct Store<F, S>
|
|
||||||
where
|
|
||||||
S: store::Store,
|
|
||||||
F: Fn(&origin::Descr) -> Option<S> + Sync + Send,
|
|
||||||
{
|
|
||||||
mapping_fn: F,
|
|
||||||
//stores: Vec<S>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new<F, S>(mapping_fn: F) -> Box<dyn store::Store>
|
|
||||||
where
|
|
||||||
S: store::Store + 'static,
|
|
||||||
F: Fn(&origin::Descr) -> Option<S> + Sync + Send + 'static,
|
|
||||||
{
|
|
||||||
Box::new(Store { mapping_fn })
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<F, S> store::Store for Store<F, S>
|
|
||||||
where
|
|
||||||
S: store::Store,
|
|
||||||
F: Fn(&origin::Descr) -> Option<S> + Sync + Send,
|
|
||||||
{
|
|
||||||
fn sync(&self, descr: origin::Descr, limits: store::Limits) -> Result<(), store::SyncError> {
|
|
||||||
(self.mapping_fn)(&descr)
|
|
||||||
.or_unexpected_while(format!("fetching store for {:?}", &descr))?
|
|
||||||
.sync(descr, limits)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get(&self, descr: origin::Descr) -> Result<sync::Arc<dyn origin::Origin>, store::GetError> {
|
|
||||||
(self.mapping_fn)(&descr)
|
|
||||||
.or_unexpected_while(format!("fetching store for {:?}", &descr))?
|
|
||||||
.get(descr)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn all_descrs(&self) -> Result<Vec<origin::Descr>, store::AllDescrsError> {
|
|
||||||
let mut res = Vec::<origin::Descr>::new();
|
|
||||||
|
|
||||||
//for store in self.stores.iter() {
|
|
||||||
// store.all_descrs()?.into_iter().collect_into(&mut res);
|
|
||||||
//}
|
|
||||||
|
|
||||||
Ok(res)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use crate::origin::{self, store};
|
|
||||||
use mockall::predicate;
|
|
||||||
use std::{cell, rc};
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn basic() {
|
|
||||||
let descrA = origin::Descr::Git {
|
|
||||||
url: "A".to_string(),
|
|
||||||
branch_name: "A".to_string(),
|
|
||||||
};
|
|
||||||
|
|
||||||
//let descrB = origin::Descr::Git {
|
|
||||||
// url: "B".to_string(),
|
|
||||||
// branch_name: "B".to_string(),
|
|
||||||
//};
|
|
||||||
|
|
||||||
let sA_mock = rc::Rc::new(store::MockStore::new());
|
|
||||||
|
|
||||||
//let mut sB = store::MockStore::new();
|
|
||||||
|
|
||||||
let s = {
|
|
||||||
let sA: rc::Rc<dyn store::Store> = sA_mock.clone();
|
|
||||||
let sA = sA.as_ref();
|
|
||||||
|
|
||||||
super::new(
|
|
||||||
|descr| match descr {
|
|
||||||
&origin::Descr::Git { ref url, .. } if url == "A" => Some(sA),
|
|
||||||
//&origin::Descr::Git { ref url, .. } if url == "B" => Some(sB),
|
|
||||||
_ => None,
|
|
||||||
},
|
|
||||||
//vec![sA],
|
|
||||||
)
|
|
||||||
};
|
|
||||||
|
|
||||||
sA_mock
|
|
||||||
.expect_sync()
|
|
||||||
.with(predicate::eq(descrA.clone()), predicate::always())
|
|
||||||
.times(1)
|
|
||||||
.return_const(Ok::<(), store::SyncError>(()));
|
|
||||||
|
|
||||||
assert_eq!(Ok(()), s.sync(descrA, store::Limits {}))
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user