Merge pull request #1051 from matthiasbeyer/imag-store/tests

Imag store/tests
This commit is contained in:
Matthias Beyer 2017-09-04 17:07:46 +02:00 committed by GitHub
commit f025416cf7
4 changed files with 93 additions and 1 deletions

View file

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

View file

@ -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);
}
}

View file

@ -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());
}
}

View file

@ -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;