summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-10-13 10:04:29 +0200
committerMatthias Beyer <mail@beyermatthias.de>2019-11-02 18:19:30 +0100
commitceabde799b07cb2bd375519e91819b3d762f88eb (patch)
tree6afe9a1e334afffa5a8232a8cc475041e3eb806f /tests
parent4c67450b0c05eec5ce091b11575ad9b422848306 (diff)
Add test: check whether imag-create works as expected
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/Cargo.toml1
-rw-r--r--tests/ui/src/imag_create.rs64
-rw-r--r--tests/ui/src/lib.rs1
3 files changed, 66 insertions, 0 deletions
diff --git a/tests/ui/Cargo.toml b/tests/ui/Cargo.toml
index 44f2d8d7..1fef31ac 100644
--- a/tests/ui/Cargo.toml
+++ b/tests/ui/Cargo.toml
@@ -17,3 +17,4 @@ env_logger = "0.7"
log = "0.4"
predicates = "1"
pretty_assertions = "0.6"
+semver = "0.9"
diff --git a/tests/ui/src/imag_create.rs b/tests/ui/src/imag_create.rs
index 987eadc5..4e6719f3 100644
--- a/tests/ui/src/imag_create.rs
+++ b/tests/ui/src/imag_create.rs
@@ -17,3 +17,67 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
+use std::process::Command;
+
+use assert_cmd::prelude::*;
+use assert_fs::fixture::TempDir;
+
+/// Helper to call imag-create
+pub fn call(tempdir: &TempDir, targets: &[&str]) {
+ let mut bin = binary(tempdir);
+
+ // ensure that stdin is not used by the child process
+ bin.stdin(std::process::Stdio::inherit());
+
+ for target in targets.iter() {
+ bin.arg(target);
+ }
+ debug!("Command = {:?}", bin);
+
+ bin.assert().success();
+}
+
+pub fn binary(tempdir: &TempDir) -> Command {
+ crate::imag::binary(tempdir, "imag-create")
+}
+
+
+#[test]
+fn test_creating_works() {
+ crate::setup_logging();
+ let imag_home = crate::imag::make_temphome();
+ crate::imag_init::call(&imag_home);
+
+ call(&imag_home, &["test"]);
+
+ let entry_path = {
+ let mut path = imag_home.path().to_path_buf();
+ path.push("store");
+ path.push("test");
+ path
+ };
+
+ debug!("Calculated path = {:?}", entry_path);
+
+ assert!(entry_path.exists(), "Entry was not created: {:?}", entry_path);
+ assert!(entry_path.is_file() , "Entry is not a file: {:?}", entry_path);
+
+ let contents = std::fs::read_to_string(entry_path).unwrap();
+ let mut lines = contents.lines();
+
+ assert_eq!(lines.next(), Some("---"));
+ assert_eq!(lines.next(), Some("[imag]"));
+ {
+ let version_line = lines.next().unwrap();
+ assert!(version_line.starts_with("version = '"));
+ assert!(version_line.ends_with("'"));
+ let version = version_line.replace("version = '", "").replace("'", "");
+ let semver = semver::Version::parse(&version);
+ assert!(semver.is_ok());
+ assert!(!semver.unwrap().is_prerelease()); // we only want full versions in the header
+
+ }
+ assert_eq!(lines.next(), Some("---"));
+ assert_eq!(lines.next(), None);
+}
+
diff --git a/tests/ui/src/lib.rs b/tests/ui/src/lib.rs
index 827f8505..56009df6 100644
--- a/tests/ui/src/lib.rs
+++ b/tests/ui/src/lib.rs
@@ -21,6 +21,7 @@ extern crate assert_cmd;
extern crate assert_fs;
extern crate env_logger;
extern crate predicates;
+extern crate semver;
#[macro_use] extern crate log;
#[macro_use] extern crate pretty_assertions;