summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-06-29 16:58:26 +0200
committerMatthias Beyer <mail@beyermatthias.de>2019-06-29 21:36:59 +0200
commitae9fbe866f8dec1de33b2329aeba30c84415aeae (patch)
tree0cd9b5e06d1477778ff6aee4d3b0c8b5dfb40284
parentc5519da01159023c236c3bc1db64141738ea3b20 (diff)
downloadimag-ae9fbe866f8dec1de33b2329aeba30c84415aeae.zip
imag-ae9fbe866f8dec1de33b2329aeba30c84415aeae.tar.gz
Add test whether setting tags works
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--lib/entry/libimagentrytag/Cargo.toml3
-rw-r--r--lib/entry/libimagentrytag/src/lib.rs2
-rw-r--r--lib/entry/libimagentrytag/src/tagable.rs40
3 files changed, 45 insertions, 0 deletions
diff --git a/lib/entry/libimagentrytag/Cargo.toml b/lib/entry/libimagentrytag/Cargo.toml
index 4cd6395..5517581 100644
--- a/lib/entry/libimagentrytag/Cargo.toml
+++ b/lib/entry/libimagentrytag/Cargo.toml
@@ -42,3 +42,6 @@ version = "^2.29"
default-features = false
features = ["color", "suggestions", "wrap_help"]
+[dev-dependencies]
+env_logger = "0.5"
+
diff --git a/lib/entry/libimagentrytag/src/lib.rs b/lib/entry/libimagentrytag/src/lib.rs
index efe48b7..c036fca 100644
--- a/lib/entry/libimagentrytag/src/lib.rs
+++ b/lib/entry/libimagentrytag/src/lib.rs
@@ -48,6 +48,8 @@ extern crate serde;
extern crate filters;
#[macro_use] extern crate failure;
+#[cfg(test)] extern crate env_logger;
+
extern crate libimagstore;
extern crate libimagerror;
diff --git a/lib/entry/libimagentrytag/src/tagable.rs b/lib/entry/libimagentrytag/src/tagable.rs
index c76d651..2be4ddd 100644
--- a/lib/entry/libimagentrytag/src/tagable.rs
+++ b/lib/entry/libimagentrytag/src/tagable.rs
@@ -116,3 +116,43 @@ impl Tagable for Entry {
}
+#[cfg(test)]
+mod tests {
+ use std::path::PathBuf;
+
+ use toml_query::read::TomlValueReadTypeExt;
+
+ use libimagstore::store::Store;
+
+ use super::*;
+
+ fn setup_logging() {
+ let _ = ::env_logger::try_init();
+ }
+
+ fn get_store() -> Store {
+ Store::new_inmemory(PathBuf::from("/"), &None).unwrap()
+ }
+
+ #[test]
+ fn test_tag_set_sets_tag() {
+ setup_logging();
+ let store = get_store();
+ let name = "test-tag-set-sets-tags";
+
+ debug!("Creating default entry");
+ let id = PathBuf::from(String::from(name));
+ let mut entry = store.create(id).unwrap();
+
+ let tags = vec![String::from("testtag")];
+ entry.set_tags(&tags).unwrap();
+
+ let v = entry.get_header().read_string("tags.values.[0]").unwrap();
+
+ assert!(v.is_some());
+ let v = v.unwrap();
+
+ assert_eq!(v, "testtag");
+ }
+
+}