mirror of
https://github.com/qwjyh/xdbm
synced 2025-04-21 04:05:49 +09:00
Compare commits
No commits in common. "6f8a71fe8d29b8e3abb1ba3e0f904377de8fbd7c" and "6bb1893fa2f42611dca0e05883ae14bd064f5992" have entirely different histories.
6f8a71fe8d
...
6bb1893fa2
2 changed files with 6 additions and 65 deletions
22
.github/workflows/rust.yml
vendored
22
.github/workflows/rust.yml
vendored
|
@ -1,22 +0,0 @@
|
||||||
name: Rust
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ "main" ]
|
|
||||||
pull_request:
|
|
||||||
branches: [ "main" ]
|
|
||||||
|
|
||||||
env:
|
|
||||||
CARGO_TERM_COLOR: always
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- name: Build
|
|
||||||
run: cargo build --verbose
|
|
||||||
- name: Run tests
|
|
||||||
run: cargo test --verbose
|
|
49
tests/cli.rs
49
tests/cli.rs
|
@ -1,47 +1,15 @@
|
||||||
mod integrated_test {
|
mod integrated_test {
|
||||||
use std::{
|
use std::fs::DirBuilder;
|
||||||
fs::{DirBuilder, File},
|
|
||||||
io::{self, BufWriter, Write},
|
|
||||||
};
|
|
||||||
|
|
||||||
use anyhow::{Context, Ok, Result};
|
use anyhow::{Ok, Result};
|
||||||
use assert_cmd::{assert::OutputAssertExt, Command};
|
use assert_cmd::{assert::OutputAssertExt, Command};
|
||||||
use dirs::home_dir;
|
|
||||||
use git2::Repository;
|
use git2::Repository;
|
||||||
use log::trace;
|
use log::trace;
|
||||||
use predicates::prelude::predicate;
|
use predicates::prelude::predicate;
|
||||||
|
|
||||||
/// Setup global gitconfig if it doesn't exist.
|
|
||||||
///
|
|
||||||
/// # Errors
|
|
||||||
///
|
|
||||||
/// This function will return an error if it failed to get home directory.
|
|
||||||
fn setup_gitconfig() -> Result<()> {
|
|
||||||
let f = match File::create_new(
|
|
||||||
home_dir()
|
|
||||||
.context("Failed to find home directory")?
|
|
||||||
.join(".gitconfig"),
|
|
||||||
) {
|
|
||||||
io::Result::Ok(f) => f,
|
|
||||||
io::Result::Err(_err) => return Ok(()),
|
|
||||||
};
|
|
||||||
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()?;
|
|
||||||
// init
|
// init
|
||||||
let mut cmd = Command::cargo_bin("xdbm")?;
|
let mut cmd = Command::cargo_bin("xdbm")?;
|
||||||
cmd.arg("-c")
|
cmd.arg("-c")
|
||||||
|
@ -135,7 +103,6 @@ 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()?;
|
|
||||||
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())
|
||||||
|
@ -151,17 +118,15 @@ mod integrated_test {
|
||||||
let upstream_name = "remote";
|
let upstream_name = "remote";
|
||||||
let mut repo_1_remote =
|
let mut repo_1_remote =
|
||||||
repo_1.remote(upstream_name, bare_repo_dir.path().to_str().unwrap())?;
|
repo_1.remote(upstream_name, bare_repo_dir.path().to_str().unwrap())?;
|
||||||
repo_1_remote.push(&[repo_1.head().unwrap().name().unwrap()], None)?;
|
repo_1_remote.push(&["refs/heads/main"], None)?;
|
||||||
trace!("bare repo {:?}", bare_repo_dir.display());
|
trace!("bare repo {:?}", bare_repo_dir.display());
|
||||||
println!("{:?}", bare_repo_dir.read_dir()?);
|
println!("{:?}", bare_repo_dir.read_dir()?);
|
||||||
// set up upstream branch
|
// set up upstream branch
|
||||||
let (mut repo_1_branch, _branch_type) = repo_1.branches(None)?.next().unwrap()?;
|
let (mut repo_1_branch, _branch_type) = repo_1.branches(None)?.next().unwrap()?;
|
||||||
println!("head {}", repo_1.head().unwrap().name().unwrap());
|
repo_1_branch.set_upstream(Some(format!("{}/{}", upstream_name, "main").as_str()))?;
|
||||||
repo_1_branch.set_upstream(Some(format!("{}/{}", upstream_name, repo_1_branch.name().unwrap().unwrap()).as_str()))?;
|
|
||||||
|
|
||||||
// 2nd device
|
// 2nd device
|
||||||
let config_dir_2 = assert_fs::TempDir::new()?;
|
let config_dir_2 = assert_fs::TempDir::new()?;
|
||||||
setup_gitconfig()?;
|
|
||||||
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())
|
||||||
|
@ -177,7 +142,6 @@ 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()?;
|
|
||||||
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())
|
||||||
|
@ -210,7 +174,6 @@ 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()?;
|
|
||||||
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())
|
||||||
|
@ -226,12 +189,12 @@ mod integrated_test {
|
||||||
let upstream_name = "remote";
|
let upstream_name = "remote";
|
||||||
let mut repo_1_remote =
|
let mut repo_1_remote =
|
||||||
repo_1.remote(upstream_name, bare_repo_dir.path().to_str().unwrap())?;
|
repo_1.remote(upstream_name, bare_repo_dir.path().to_str().unwrap())?;
|
||||||
repo_1_remote.push(&[repo_1.head().unwrap().name().unwrap()], None)?;
|
repo_1_remote.push(&["refs/heads/main"], None)?;
|
||||||
trace!("bare repo {:?}", bare_repo_dir.display());
|
trace!("bare repo {:?}", bare_repo_dir.display());
|
||||||
println!("{:?}", bare_repo_dir.read_dir()?);
|
println!("{:?}", bare_repo_dir.read_dir()?);
|
||||||
// set up upstream branch
|
// set up upstream branch
|
||||||
let (mut repo_1_branch, _branch_type) = repo_1.branches(None)?.next().unwrap()?;
|
let (mut repo_1_branch, _branch_type) = repo_1.branches(None)?.next().unwrap()?;
|
||||||
repo_1_branch.set_upstream(Some(format!("{}/{}", upstream_name, repo_1_branch.name().unwrap().unwrap()).as_str()))?;
|
repo_1_branch.set_upstream(Some(format!("{}/{}", upstream_name, "main").as_str()))?;
|
||||||
|
|
||||||
// 2nd device
|
// 2nd device
|
||||||
let config_dir_2 = assert_fs::TempDir::new()?;
|
let config_dir_2 = assert_fs::TempDir::new()?;
|
||||||
|
|
Loading…
Add table
Reference in a new issue