summaryrefslogtreecommitdiffstats
path: root/src/filestore/path.rs
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-12-07 13:31:40 +0100
committerMatthias Beyer <mail@beyermatthias.de>2020-12-07 13:31:40 +0100
commitdb8e31ddc60fdeb5cdd67a39ec805a7239044d89 (patch)
tree2808bf97db749660fa3ad3ab646fca4ec7801b06 /src/filestore/path.rs
parentf8b987c9e48a668ed6fdd5201292f9f372f4acbf (diff)
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 <mail@beyermatthias.de>
Diffstat (limited to 'src/filestore/path.rs')
-rw-r--r--src/filestore/path.rs30
1 files changed, 30 insertions, 0 deletions
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<FullArtifactPath<'a>> {
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()
}