From 3a959ddfd1f14bd71d649f84ba5102ab4ce8760b Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 2 Sep 2017 10:41:21 +0200 Subject: [PATCH] Add multi-call tests: add-remove --- bin/core/imag-link/Cargo.toml | 6 ++++ bin/core/imag-link/src/main.rs | 58 ++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/bin/core/imag-link/Cargo.toml b/bin/core/imag-link/Cargo.toml index ce87acaf..15b7cc0e 100644 --- a/bin/core/imag-link/Cargo.toml +++ b/bin/core/imag-link/Cargo.toml @@ -33,3 +33,9 @@ path = "../../../lib/etc/libimagutil" default-features = false features = ["testing"] +[dev-dependencies.libimagrt] +version = "0.4.0" +path = "../../../lib/core/libimagrt" +default-features = false +features = ["testing"] + diff --git a/bin/core/imag-link/src/main.rs b/bin/core/imag-link/src/main.rs index 9c3f20ab..72b9498c 100644 --- a/bin/core/imag-link/src/main.rs +++ b/bin/core/imag-link/src/main.rs @@ -361,6 +361,7 @@ mod tests { with help "imag-link mocking app"; } use self::mock::generate_test_runtime; + use self::mock::reset_test_runtime; use libimagutil::testing::DEFAULT_ENTRY; fn create_test_default_entry<'a, S: AsRef>(rt: &'a Runtime, name: S) -> StoreResult { @@ -475,4 +476,61 @@ mod tests { assert_eq!(*test_links2, links_toml_value(vec!["test1"])); assert_eq!(*test_links3, links_toml_value(vec!["test1"])); } + + // Remove tests + + #[test] + fn test_linking_links_unlinking_removes_links() { + let rt = generate_test_runtime(vec!["internal", "add", "test1", "test2"]) + .unwrap(); + + let test_id1 = create_test_default_entry(&rt, "test1").unwrap(); + let test_id2 = create_test_default_entry(&rt, "test2").unwrap(); + + handle_internal_linking(&rt); + + let rt = reset_test_runtime(vec!["internal", "remove", "test1", "test2"], rt) + .unwrap(); + + handle_internal_linking(&rt); + + let test_entry1 = rt.store().get(test_id1).unwrap().unwrap(); + let test_links1 = get_entry_links(&test_entry1).unwrap(); + + let test_entry2 = rt.store().get(test_id2).unwrap().unwrap(); + let test_links2 = get_entry_links(&test_entry2).unwrap(); + + assert_eq!(*test_links1, links_toml_value(vec![])); + assert_eq!(*test_links2, links_toml_value(vec![])); + } + + #[test] + fn test_linking_and_unlinking_more_than_two() { + let rt = generate_test_runtime(vec!["internal", "add", "test1", "test2", "test3"]) + .unwrap(); + + let test_id1 = create_test_default_entry(&rt, "test1").unwrap(); + let test_id2 = create_test_default_entry(&rt, "test2").unwrap(); + let test_id3 = create_test_default_entry(&rt, "test3").unwrap(); + + handle_internal_linking(&rt); + + let rt = reset_test_runtime(vec!["internal", "remove", "test1", "test2", "test3"], rt) + .unwrap(); + + handle_internal_linking(&rt); + + let test_entry1 = rt.store().get(test_id1).unwrap().unwrap(); + let test_links1 = get_entry_links(&test_entry1).unwrap(); + + let test_entry2 = rt.store().get(test_id2).unwrap().unwrap(); + let test_links2 = get_entry_links(&test_entry2).unwrap(); + + let test_entry3 = rt.store().get(test_id3).unwrap().unwrap(); + let test_links3 = get_entry_links(&test_entry3).unwrap(); + + assert_eq!(*test_links1, links_toml_value(vec![])); + assert_eq!(*test_links2, links_toml_value(vec![])); + assert_eq!(*test_links3, links_toml_value(vec![])); + } }