Add multi-call tests: add-remove

This commit is contained in:
Matthias Beyer 2017-09-02 10:41:21 +02:00
parent e7ecea0065
commit 3a959ddfd1
2 changed files with 64 additions and 0 deletions

View file

@ -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"]

View file

@ -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<OsStr>>(rt: &'a Runtime, name: S) -> StoreResult<StoreId> {
@ -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![]));
}
}