mirror of
https://github.com/qwjyh/xdbm
synced 2024-11-24 23:51:04 +09:00
add test for storage add online
This commit is contained in:
parent
1aa74acf31
commit
d212d32430
2 changed files with 65 additions and 5 deletions
|
@ -6,7 +6,7 @@
|
|||
- [x] ssh-agent
|
||||
- [x] specify key
|
||||
- [ ] write test for storage subcommand
|
||||
- [ ] storage add online
|
||||
- [x] storage add online
|
||||
- [ ] storage add directory
|
||||
- [ ] storage list
|
||||
- [ ] add storage remove command
|
||||
|
|
68
tests/cli.rs
68
tests/cli.rs
|
@ -1,6 +1,3 @@
|
|||
use assert_cmd::prelude::*;
|
||||
use assert_fs::prelude::*;
|
||||
|
||||
mod cmd_init {
|
||||
use anyhow::{Ok, Result};
|
||||
use assert_cmd::Command;
|
||||
|
@ -25,7 +22,7 @@ mod cmd_init {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn init_with_existing_repo() -> Result<()> {
|
||||
fn two_devices_with_same_name() -> Result<()> {
|
||||
// 1st device
|
||||
let config_dir_1 = assert_fs::TempDir::new()?;
|
||||
let mut cmd1 = Command::cargo_bin("xdbm")?;
|
||||
|
@ -38,6 +35,46 @@ mod cmd_init {
|
|||
// bare-repo
|
||||
let bare_repo_dir = assert_fs::TempDir::new()?;
|
||||
let bare_repo = Repository::init_bare(&bare_repo_dir)?;
|
||||
// push to bare repository
|
||||
let repo_1 = Repository::open(&config_dir_1)?;
|
||||
let upstream_name = "remote";
|
||||
let mut repo_1_remote =
|
||||
repo_1.remote(upstream_name, &bare_repo_dir.path().to_str().unwrap())?;
|
||||
repo_1_remote.push(&["refs/heads/main"], None)?;
|
||||
trace!("bare repo {:?}", bare_repo_dir.display());
|
||||
println!("{:?}", bare_repo_dir.read_dir()?);
|
||||
// set up upstream branch
|
||||
let (mut repo_1_branch, _branch_type) = repo_1.branches(None)?.next().unwrap()?;
|
||||
repo_1_branch.set_upstream(Some(format!("{}/{}", upstream_name, "main").as_str()))?;
|
||||
|
||||
// 2nd device
|
||||
let config_dir_2 = assert_fs::TempDir::new()?;
|
||||
let mut cmd2 = Command::cargo_bin("xdbm")?;
|
||||
cmd2.arg("-c")
|
||||
.arg(config_dir_2.path())
|
||||
.arg("init")
|
||||
.arg("first")
|
||||
.arg("-r")
|
||||
.arg(bare_repo_dir.path());
|
||||
cmd2.assert().failure();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn two_devices() -> Result<()> {
|
||||
// 1st device
|
||||
let config_dir_1 = assert_fs::TempDir::new()?;
|
||||
let mut cmd1 = Command::cargo_bin("xdbm")?;
|
||||
cmd1.arg("-c")
|
||||
.arg(config_dir_1.path())
|
||||
.arg("init")
|
||||
.arg("first");
|
||||
cmd1.assert().success().stdout(predicate::str::contains(""));
|
||||
|
||||
// bare-repo
|
||||
let bare_repo_dir = assert_fs::TempDir::new()?;
|
||||
let bare_repo = Repository::init_bare(&bare_repo_dir)?;
|
||||
// push to bare repository
|
||||
let repo_1 = Repository::open(&config_dir_1)?;
|
||||
let upstream_name = "remote";
|
||||
let mut repo_1_remote =
|
||||
|
@ -70,6 +107,29 @@ mod cmd_init {
|
|||
assert!(
|
||||
std::fs::read_to_string(config_dir_2.path().join("devices.yml"))?.contains("second")
|
||||
);
|
||||
|
||||
// Add storage
|
||||
let sample_storage = assert_fs::TempDir::new()?;
|
||||
let mut cmd_add_storage_1 = Command::cargo_bin("xdbm")?;
|
||||
cmd_add_storage_1
|
||||
.arg("-c")
|
||||
.arg(config_dir_1.path())
|
||||
.arg("storage")
|
||||
.arg("add")
|
||||
.arg("online")
|
||||
.arg("--provider")
|
||||
.arg("google")
|
||||
.arg("--capacity")
|
||||
.arg("15000000000")
|
||||
.arg("--alias")
|
||||
.arg("gdrive")
|
||||
.arg("gdrive1")
|
||||
.arg(sample_storage.path());
|
||||
cmd_add_storage_1
|
||||
.assert()
|
||||
.success()
|
||||
.stdout(predicate::str::contains(""));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue