summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2017-05-03 17:47:02 +0200
committerGitHub <noreply@github.com>2017-05-03 17:47:02 +0200
commit878162f263b8d90dccbea8b1b82e96e005e04860 (patch)
tree97a49376297f52cf16e0580117b7a3d6b5a3f91c
parentc74c26ccd143d905c94ecf84ac423293b7170623 (diff)
parentab9967556290026fe6fdd2a82ad7994246ce711b (diff)
downloadimag-878162f263b8d90dccbea8b1b82e96e005e04860.zip
imag-878162f263b8d90dccbea8b1b82e96e005e04860.tar.gz
Merge pull request #926 from matthiasbeyer/libimagstore/store-id-tests
libimagstore: StoreId tests
-rw-r--r--libimagstore/src/storeid.rs96
1 files changed, 95 insertions, 1 deletions
diff --git a/libimagstore/src/storeid.rs b/libimagstore/src/storeid.rs
index 13dfcf1..ab2727f 100644
--- a/libimagstore/src/storeid.rs
+++ b/libimagstore/src/storeid.rs
@@ -234,16 +234,110 @@ impl Iterator for StoreIdIterator {
#[cfg(test)]
mod test {
+ use std::path::PathBuf;
+ use storeid::StoreId;
use storeid::IntoStoreId;
+ use error::StoreErrorKind as SEK;
module_entry_path_mod!("test");
#[test]
- fn correct_path() {
+ fn test_correct_path() {
let p = module_path::ModuleEntryPath::new("test");
assert_eq!(p.into_storeid().unwrap().to_str().unwrap(), "test/test");
}
+ #[test]
+ fn test_baseless_path() {
+ let id = StoreId::new_baseless(PathBuf::from("test"));
+ assert!(id.is_ok());
+ assert_eq!(id.unwrap(), StoreId {
+ base: None,
+ id: PathBuf::from("test")
+ });
+ }
+
+ #[test]
+ fn test_base_path() {
+ let id = StoreId::from_full_path(&PathBuf::from("/tmp/"), PathBuf::from("/tmp/test"));
+ assert!(id.is_ok());
+ assert_eq!(id.unwrap(), StoreId {
+ base: Some(PathBuf::from("/tmp/")),
+ id: PathBuf::from("test")
+ });
+ }
+
+ #[test]
+ fn test_adding_base_to_baseless_path() {
+ let id = StoreId::new_baseless(PathBuf::from("test"));
+
+ assert!(id.is_ok());
+ let id = id.unwrap();
+
+ assert_eq!(id, StoreId { base: None, id: PathBuf::from("test") });
+
+ let id = id.with_base(PathBuf::from("/tmp/"));
+ assert_eq!(id, StoreId {
+ base: Some(PathBuf::from("/tmp/")),
+ id: PathBuf::from("test")
+ });
+ }
+
+ #[test]
+ fn test_removing_base_from_base_path() {
+ let id = StoreId::from_full_path(&PathBuf::from("/tmp/"), PathBuf::from("/tmp/test"));
+
+ assert!(id.is_ok());
+ let id = id.unwrap();
+
+ assert_eq!(id, StoreId {
+ base: Some(PathBuf::from("/tmp/")),
+ id: PathBuf::from("test")
+ });
+
+ let id = id.without_base();
+ assert_eq!(id, StoreId {
+ base: None,
+ id: PathBuf::from("test")
+ });
+ }
+
+ #[test]
+ fn test_baseless_into_pathbuf_is_err() {
+ let id = StoreId::new_baseless(PathBuf::from("test"));
+ assert!(id.is_ok());
+ assert!(id.unwrap().into_pathbuf().is_err());
+ }
+
+ #[test]
+ fn test_baseless_into_pathbuf_is_storeidhasnobaseerror() {
+ let id = StoreId::new_baseless(PathBuf::from("test"));
+ assert!(id.is_ok());
+
+ let pb = id.unwrap().into_pathbuf();
+ assert!(pb.is_err());
+
+ assert_eq!(pb.unwrap_err().err_type(), SEK::StoreIdHasNoBaseError);
+ }
+
+ #[test]
+ fn test_basefull_into_pathbuf_is_ok() {
+ let id = StoreId::from_full_path(&PathBuf::from("/tmp/"), PathBuf::from("/tmp/test"));
+ assert!(id.is_ok());
+ assert!(id.unwrap().into_pathbuf().is_ok());
+ }
+
+ #[test]
+ fn test_basefull_into_pathbuf_is_correct() {
+ let id = StoreId::from_full_path(&PathBuf::from("/tmp/"), PathBuf::from("/tmp/test"));
+ assert!(id.is_ok());
+
+ let pb = id.unwrap().into_pathbuf();
+ assert!(pb.is_ok());
+
+ assert_eq!(pb.unwrap(), PathBuf::from("/tmp/test"));
+ }
+
}