diff --git a/bin/core/imag-store/Cargo.toml b/bin/core/imag-store/Cargo.toml index a3715a61..c31f629e 100644 --- a/bin/core/imag-store/Cargo.toml +++ b/bin/core/imag-store/Cargo.toml @@ -27,3 +27,18 @@ libimagutil = { version = "0.4.0", path = "../../../lib/etc/libimagutil" } [features] early-panic = [ "libimagstore/early-panic" ] +[dev-dependencies.libimagutil] +version = "0.4.0" +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"] + +[dev-dependencies.toml-query] +version = "0.3" + diff --git a/bin/core/imag-store/src/create.rs b/bin/core/imag-store/src/create.rs index f434ba75..68bb9667 100644 --- a/bin/core/imag-store/src/create.rs +++ b/bin/core/imag-store/src/create.rs @@ -177,3 +177,39 @@ fn string_from_raw_src(raw_src: &str) -> String { } content } + +#[cfg(test)] +mod tests { + use super::create; + + use std::path::PathBuf; + use toml_query::read::TomlValueReadExt; + use toml::Value; + + make_mock_app! { + app "imag-link"; + modulename mock; + version "0.4.0"; + with help "imag-link mocking app"; + } + use self::mock::generate_test_runtime; + + #[test] + fn test_create_simple() { + let test_name = "test_create_simple"; + let rt = generate_test_runtime(vec!["create", "-p", "test_create_simple"]).unwrap(); + + create(&rt); + + let e = rt.store().get(PathBuf::from(test_name)); + assert!(e.is_ok()); + let e = e.unwrap(); + assert!(e.is_some()); + let e = e.unwrap(); + + let version = e.get_header().read("imag.version").map(Option::unwrap).unwrap(); + assert_eq!(Value::String(String::from("0.4.0")), *version); + } + +} + diff --git a/bin/core/imag-store/src/delete.rs b/bin/core/imag-store/src/delete.rs index 1413de77..7b9e56ed 100644 --- a/bin/core/imag-store/src/delete.rs +++ b/bin/core/imag-store/src/delete.rs @@ -46,3 +46,38 @@ pub fn delete(rt: &Runtime) { .or_else(|| warn_exit("No subcommand 'delete'. Will exit now", 1)); } +#[cfg(test)] +mod tests { + use create::create; + use super::delete; + + use std::path::PathBuf; + + make_mock_app! { + app "imag-link"; + modulename mock; + version "0.4.0"; + with help "imag-link mocking app"; + } + use self::mock::generate_test_runtime; + use self::mock::reset_test_runtime; + + #[test] + fn test_create_simple() { + let test_name = "test_create_simple"; + let rt = generate_test_runtime(vec!["create", "-p", "test_create_simple"]).unwrap(); + + create(&rt); + + let rt = reset_test_runtime(vec!["delete", "--id", "test_create_simple"], rt).unwrap(); + + delete(&rt); + + let e = rt.store().get(PathBuf::from(test_name)); + assert!(e.is_ok()); + let e = e.unwrap(); + assert!(e.is_none()); + } + +} + diff --git a/bin/core/imag-store/src/main.rs b/bin/core/imag-store/src/main.rs index 9e5c5267..bb4d2ebc 100644 --- a/bin/core/imag-store/src/main.rs +++ b/bin/core/imag-store/src/main.rs @@ -35,13 +35,19 @@ extern crate clap; #[macro_use] extern crate log; extern crate toml; +#[cfg(test)] extern crate toml_query; #[macro_use] extern crate version; extern crate libimagrt; extern crate libimagstore; -extern crate libimagutil; #[macro_use] extern crate libimagerror; +#[cfg(test)] +#[macro_use] +extern crate libimagutil; +#[cfg(not(test))] +extern crate libimagutil; + use libimagrt::setup::generate_runtime_setup; mod create;