From 1794b8b409d4723805239919c70c7a78b12138a5 Mon Sep 17 00:00:00 2001 From: qwjyh Date: Mon, 18 Mar 2024 08:37:00 +0900 Subject: [PATCH] add test for backup add/done with single device This works on Windows. It still needs git config to perform commit. --- README.md | 6 ++-- tests/cli.rs | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 81 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2b0c3c4..dc0ca53 100644 --- a/README.md +++ b/README.md @@ -28,9 +28,9 @@ to manage backups on several storages mounted on multiple devices with a single - [x] reorganize cmd option for storage - [x] use subcommand - [ ] backup subcommands - - [ ] backup add - - [ ] test for backup add - - [ ] backup list + - [x] backup add + - [x] test for backup add + - [x] backup list - [x] status printing - [x] backup done - [ ] fancy display diff --git a/tests/cli.rs b/tests/cli.rs index 23bad22..f27e1bd 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -1,4 +1,4 @@ -mod cmd_init { +mod integrated_test { use std::fs::DirBuilder; use anyhow::{Ok, Result}; @@ -8,8 +8,9 @@ mod cmd_init { use predicates::prelude::predicate; #[test] - fn init_with_tmpdir() -> Result<()> { + fn single_device() -> Result<()> { let config_dir = assert_fs::TempDir::new()?; + // init let mut cmd = Command::cargo_bin("xdbm")?; cmd.arg("-c") .arg(config_dir.path()) @@ -20,6 +21,81 @@ mod cmd_init { std::fs::read_to_string(config_dir.path().join("devname"))?, "testdev\n" ); + + // storage add + let storage = assert_fs::TempDir::new()?; + Command::cargo_bin("xdbm")? + .arg("-c") + .arg(config_dir.path()) + .arg("storage") + .arg("add") + .arg("online") + .arg("--provider") + .arg("sample_provider") + .arg("--capacity") + .arg("1000000000000") + .arg("--alias") + .arg("alias") + .arg("online_storage") + .arg(storage.path()) + .assert() + .success(); + + // storage list + Command::cargo_bin("xdbm")? + .arg("-c") + .arg(config_dir.path()) + .arg("storage") + .arg("list") + .assert() + .success() + .stdout(predicate::str::contains("online_storage")); + + // backup add + let target_from = storage.join("foo/bar"); + let target_to = storage.join("aaa/bbb/ccc"); + DirBuilder::new() + .recursive(true) + .create(target_from.clone())?; + DirBuilder::new() + .recursive(true) + .create(target_to.clone())?; + Command::cargo_bin("xdbm")? + .arg("-c") + .arg(config_dir.path()) + .arg("backup") + .arg("add") + .arg("--src") + .arg(target_from) + .arg("--dest") + .arg(target_to) + .arg("sample_backup") + .arg("external") + .arg("rsync") + .arg("with some note") + .assert() + .success(); + + // backup list + Command::cargo_bin("xdbm")? + .arg("-c") + .arg(config_dir.path()) + .arg("backup") + .arg("list") + .assert() + .success() + .stdout(predicate::str::contains("sample_backup")); + + Command::cargo_bin("xdbm")? + .arg("-c") + .arg(config_dir.path()) + .arg("backup") + .arg("done") + .arg("sample_backup") + .arg("0") + .assert() + .success(); + Ok(()) }