From bd564ad209008181dd6b7f6567d60dd5e997d7ff Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 29 Jun 2019 19:59:26 +0200 Subject: [PATCH] Add tests Signed-off-by: Matthias Beyer --- lib/entry/libimagentrytag/src/tagable.rs | 65 ++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/lib/entry/libimagentrytag/src/tagable.rs b/lib/entry/libimagentrytag/src/tagable.rs index 2be4ddda..32be5b11 100644 --- a/lib/entry/libimagentrytag/src/tagable.rs +++ b/lib/entry/libimagentrytag/src/tagable.rs @@ -134,6 +134,71 @@ mod tests { Store::new_inmemory(PathBuf::from("/"), &None).unwrap() } + #[test] + fn test_tag_get_tag() { + setup_logging(); + let store = get_store(); + let name = "test-tag-get-tags"; + + debug!("Creating default entry"); + let id = PathBuf::from(String::from(name)); + let mut entry = store.create(id).unwrap(); + + let tags = vec![String::from("a")]; + entry.set_tags(&tags).unwrap(); + + let v = entry.get_tags(); + + assert!(v.is_ok()); + let v = v.unwrap(); + + assert_eq!(v, vec!["a"]); + } + + #[test] + fn test_tag_add_adds_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(); + + entry.add_tag(String::from("test")).unwrap(); + + let v = entry.get_header().read_string("tags.values.[0]").unwrap(); + + assert!(v.is_some()); + let v = v.unwrap(); + + assert_eq!(v, "test"); + } + + #[test] + fn test_tag_remove_removes_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(); + + entry.add_tag(String::from("test")).unwrap(); + + let v = entry.get_header().read_string("tags.values.[0]").unwrap(); + assert!(v.is_some()); + + entry.remove_tag(String::from("test")).unwrap(); + + assert!(entry.get_header().read_string("tags.values.[0]").is_err()); + let tags = entry.get_tags(); + assert!(tags.is_ok()); + let tags = tags.unwrap(); + assert!(tags.is_empty()); + } + #[test] fn test_tag_set_sets_tag() { setup_logging();