use git_url::Url; use crate::crypto::Verified; use crate::git; use crate::identity::{ProjId, Project, UserId}; use crate::storage::refs; use crate::storage::{ Error, Inventory, ReadRepository, ReadStorage, Remote, RemoteId, WriteRepository, WriteStorage, }; #[derive(Clone, Debug)] pub struct MockStorage { pub inventory: Vec, } impl MockStorage { pub fn new(inventory: Vec) -> Self { Self { inventory } } pub fn empty() -> Self { Self { inventory: Vec::new(), } } } impl ReadStorage for MockStorage { fn user_id(&self) -> &UserId { todo!() } fn url(&self) -> Url { Url { scheme: git_url::Scheme::Radicle, host: Some("mock".to_string()), ..Url::default() } } fn get(&self, proj: &ProjId) -> Result, Error> { if let Some(proj) = self.inventory.iter().find(|p| p.id == *proj) { return Ok(Some(proj.clone())); } Ok(None) } fn inventory(&self) -> Result { let inventory = self .inventory .iter() .map(|proj| proj.id.clone()) .collect::>(); Ok(inventory) } } impl WriteStorage<'_> for MockStorage { type Repository = MockRepository; fn repository(&self, _proj: &ProjId) -> Result { Ok(MockRepository {}) } fn sign_refs( &self, _repository: &Self::Repository, ) -> Result, Error> { todo!() } } pub struct MockRepository {} impl ReadRepository<'_> for MockRepository { type Remotes = std::iter::Empty), refs::Error>>; fn is_empty(&self) -> Result { Ok(true) } fn path(&self) -> &std::path::Path { todo!() } fn remote(&self, _user: &UserId) -> Result, refs::Error> { todo!() } fn remotes(&self) -> Result { todo!() } fn blob_at<'a>( &'a self, _oid: radicle_git_ext::Oid, _path: &'a std::path::Path, ) -> Result, radicle_git_ext::Error> { todo!() } fn reference( &self, _user: &UserId, _reference: &git::RefStr, ) -> Result, git2::Error> { todo!() } fn reference_oid( &self, _user: &UserId, _reference: &git::RefStr, ) -> Result, git2::Error> { todo!() } fn references(&self, _user: &UserId) -> Result { todo!() } } impl WriteRepository<'_> for MockRepository { fn fetch(&mut self, _url: &Url) -> Result<(), git2::Error> { Ok(()) } fn raw(&self) -> &git2::Repository { todo!() } }