use std::collections::HashMap; use std::path::{Path, PathBuf}; use git_ref_format as fmt; use radicle_git_ext as git_ext; use crate::crypto::{Signer, Verified}; use crate::identity::doc::{Doc, Id}; pub use crate::storage::*; #[derive(Clone, Debug)] pub struct MockStorage { pub path: PathBuf, pub inventory: HashMap>, } impl MockStorage { pub fn new(inventory: Vec<(Id, Doc)>) -> Self { Self { path: PathBuf::default(), inventory: inventory.into_iter().collect(), } } pub fn empty() -> Self { Self { path: PathBuf::default(), inventory: HashMap::new(), } } } impl ReadStorage for MockStorage { type Repository = MockRepository; fn path(&self) -> &Path { self.path.as_path() } fn path_of(&self, rid: &Id) -> PathBuf { self.path().join(rid.canonical()) } fn contains(&self, rid: &Id) -> Result { Ok(self.inventory.contains_key(rid)) } fn get( &self, _remote: &RemoteId, proj: Id, ) -> Result>, git::ProjectError> { Ok(self.inventory.get(&proj).cloned()) } fn inventory(&self) -> Result { Ok(self.inventory.keys().cloned().collect::>()) } fn repository(&self, _proj: Id) -> Result { Ok(MockRepository {}) } } impl WriteStorage for MockStorage { type RepositoryMut = MockRepository; fn repository_mut(&self, _rid: Id) -> Result { Ok(MockRepository {}) } fn create(&self, _rid: Id) -> Result { Ok(MockRepository {}) } } pub struct MockRepository {} impl ReadRepository for MockRepository { fn id(&self) -> Id { todo!() } fn is_empty(&self) -> Result { Ok(true) } fn head(&self) -> Result<(fmt::Qualified, Oid), ProjectError> { todo!() } fn canonical_head(&self) -> Result<(fmt::Qualified, Oid), ProjectError> { todo!() } fn verify(&self) -> Result<(), VerifyError> { Ok(()) } fn path(&self) -> &std::path::Path { todo!() } fn remote(&self, _remote: &RemoteId) -> Result, refs::Error> { todo!() } fn remotes(&self) -> Result, refs::Error> { todo!() } fn commit(&self, _oid: Oid) -> Result { todo!() } fn revwalk(&self, _head: Oid) -> Result { todo!() } fn blob_at<'a>( &'a self, _oid: git_ext::Oid, _path: &'a std::path::Path, ) -> Result, git_ext::Error> { todo!() } fn reference( &self, _remote: &RemoteId, _reference: &git::Qualified, ) -> Result { todo!() } fn reference_oid( &self, _remote: &RemoteId, _reference: &git::Qualified, ) -> Result { todo!() } fn references_of(&self, _remote: &RemoteId) -> Result { todo!() } fn identity_doc( &self, ) -> Result<(Oid, crate::identity::Doc), git::ProjectError> { todo!() } } impl WriteRepository for MockRepository { fn raw(&self) -> &git2::Repository { todo!() } fn set_head(&self) -> Result { todo!() } fn sign_refs( &self, _signer: &G, ) -> Result, Error> { todo!() } }