From db8e31ddc60fdeb5cdd67a39ec805a7239044d89 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 7 Dec 2020 13:31:40 +0100 Subject: Fix: Add unchecked variants of constructors for tests Because the constructors now have side-effects (accessing the filesystem), this patch adds unchecked variants of the constructors, so that tests can be implemented with pathes that do not point to valid filesystem items. Signed-off-by: Matthias Beyer --- src/filestore/path.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/filestore/path.rs') diff --git a/src/filestore/path.rs b/src/filestore/path.rs index c691cdb..c9f0c13 100644 --- a/src/filestore/path.rs +++ b/src/filestore/path.rs @@ -25,6 +25,16 @@ impl StoreRoot { } } + /// Unchecked variant of StoreRoot::new() + /// + /// Because StoreRoot::new() accesses the filesystem, this method is necessary to construct an + /// object of StoreRoot for a non-existing path, so that we can test its implementation without + /// the need to create objects on the filesystem. + #[cfg(test)] + pub fn new_unchecked(root: PathBuf) -> Self { + StoreRoot(root) + } + pub fn join<'a>(&'a self, ap: &'a ArtifactPath) -> Result> { let join = self.0.join(&ap.0); @@ -39,6 +49,16 @@ impl StoreRoot { } } + /// Unchecked variant of StoreRoot::join() + /// + /// This function is needed (like StoreRoot::new_unchecked()) to perform a construction of + /// FullArtifactPath like StoreRoot::join() in without its side effects (accessing the + /// filesystem) for testing purposes + #[cfg(test)] + pub fn join_unchecked<'a>(&'a self, ap: &'a ArtifactPath) -> FullArtifactPath<'a> { + FullArtifactPath(self, ap) + } + pub fn is_file(&self, subpath: &Path) -> bool { self.0.join(subpath).is_file() } @@ -82,6 +102,16 @@ impl ArtifactPath { } } + /// Unchecked variant of ArtifactPath::new() + /// + /// Because ArtifactPath::new() accesses the filesystem, this method is necessary to construct an + /// object of ArtifactPath for a non-existing path, so that we can test its implementation without + /// the need to create objects on the filesystem. + #[cfg(test)] + pub fn new_unchecked(root: PathBuf) -> Self { + ArtifactPath(root) + } + pub fn display(&self) -> std::path::Display { self.0.display() } -- cgit v1.2.3