mirror of
https://github.com/qwjyh/xdbm
synced 2024-11-22 06:40:12 +09:00
[fix] test: setup gitconfig at repo init
This commit is contained in:
parent
00f2057ae4
commit
462c34cf96
1 changed files with 26 additions and 1 deletions
27
tests/cli.rs
27
tests/cli.rs
|
@ -1,5 +1,8 @@
|
||||||
mod integrated_test {
|
mod integrated_test {
|
||||||
use std::fs::DirBuilder;
|
use std::{
|
||||||
|
fs::{DirBuilder, File},
|
||||||
|
io::{BufWriter, Write}, path::Path,
|
||||||
|
};
|
||||||
|
|
||||||
use anyhow::{Ok, Result};
|
use anyhow::{Ok, Result};
|
||||||
use assert_cmd::{assert::OutputAssertExt, Command};
|
use assert_cmd::{assert::OutputAssertExt, Command};
|
||||||
|
@ -7,9 +10,27 @@ mod integrated_test {
|
||||||
use log::trace;
|
use log::trace;
|
||||||
use predicates::prelude::predicate;
|
use predicates::prelude::predicate;
|
||||||
|
|
||||||
|
fn setup_gitconfig(dir_path: &Path) -> Result<()> {
|
||||||
|
DirBuilder::new().create(dir_path.join(".git"))?;
|
||||||
|
{
|
||||||
|
let f = File::create(dir_path.join(".git/config"))?;
|
||||||
|
let mut buf = BufWriter::new(f);
|
||||||
|
buf.write_all(
|
||||||
|
r#"
|
||||||
|
[user]
|
||||||
|
email = "test@example.com"
|
||||||
|
name = "testuser"
|
||||||
|
"#
|
||||||
|
.as_bytes(),
|
||||||
|
)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn single_device() -> Result<()> {
|
fn single_device() -> Result<()> {
|
||||||
let config_dir = assert_fs::TempDir::new()?;
|
let config_dir = assert_fs::TempDir::new()?;
|
||||||
|
setup_gitconfig(&config_dir)?;
|
||||||
// init
|
// init
|
||||||
let mut cmd = Command::cargo_bin("xdbm")?;
|
let mut cmd = Command::cargo_bin("xdbm")?;
|
||||||
cmd.arg("-c")
|
cmd.arg("-c")
|
||||||
|
@ -103,6 +124,7 @@ mod integrated_test {
|
||||||
fn two_devices_with_same_name() -> Result<()> {
|
fn two_devices_with_same_name() -> Result<()> {
|
||||||
// 1st device
|
// 1st device
|
||||||
let config_dir_1 = assert_fs::TempDir::new()?;
|
let config_dir_1 = assert_fs::TempDir::new()?;
|
||||||
|
setup_gitconfig(&config_dir_1)?;
|
||||||
let mut cmd1 = Command::cargo_bin("xdbm")?;
|
let mut cmd1 = Command::cargo_bin("xdbm")?;
|
||||||
cmd1.arg("-c")
|
cmd1.arg("-c")
|
||||||
.arg(config_dir_1.path())
|
.arg(config_dir_1.path())
|
||||||
|
@ -127,6 +149,7 @@ mod integrated_test {
|
||||||
|
|
||||||
// 2nd device
|
// 2nd device
|
||||||
let config_dir_2 = assert_fs::TempDir::new()?;
|
let config_dir_2 = assert_fs::TempDir::new()?;
|
||||||
|
setup_gitconfig(&config_dir_2)?;
|
||||||
let mut cmd2 = Command::cargo_bin("xdbm")?;
|
let mut cmd2 = Command::cargo_bin("xdbm")?;
|
||||||
cmd2.arg("-c")
|
cmd2.arg("-c")
|
||||||
.arg(config_dir_2.path())
|
.arg(config_dir_2.path())
|
||||||
|
@ -142,6 +165,7 @@ mod integrated_test {
|
||||||
fn directory_without_parent() -> Result<()> {
|
fn directory_without_parent() -> Result<()> {
|
||||||
// 1st device
|
// 1st device
|
||||||
let config_dir_1 = assert_fs::TempDir::new()?;
|
let config_dir_1 = assert_fs::TempDir::new()?;
|
||||||
|
setup_gitconfig(&config_dir_1)?;
|
||||||
let mut cmd1 = Command::cargo_bin("xdbm")?;
|
let mut cmd1 = Command::cargo_bin("xdbm")?;
|
||||||
cmd1.arg("-c")
|
cmd1.arg("-c")
|
||||||
.arg(config_dir_1.path())
|
.arg(config_dir_1.path())
|
||||||
|
@ -174,6 +198,7 @@ mod integrated_test {
|
||||||
fn two_devices() -> Result<()> {
|
fn two_devices() -> Result<()> {
|
||||||
// 1st device
|
// 1st device
|
||||||
let config_dir_1 = assert_fs::TempDir::new()?;
|
let config_dir_1 = assert_fs::TempDir::new()?;
|
||||||
|
setup_gitconfig(&config_dir_1)?;
|
||||||
let mut cmd1 = Command::cargo_bin("xdbm")?;
|
let mut cmd1 = Command::cargo_bin("xdbm")?;
|
||||||
cmd1.arg("-c")
|
cmd1.arg("-c")
|
||||||
.arg(config_dir_1.path())
|
.arg(config_dir_1.path())
|
||||||
|
|
Loading…
Reference in a new issue