This commit is contained in:
qwjyh 2024-04-25 15:21:49 +00:00 committed by GitHub
commit 2b0c689d73
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 57 additions and 1 deletions

22
.github/workflows/rust.yml vendored Normal file
View file

@ -0,0 +1,22 @@
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

View file

@ -1,5 +1,11 @@
mod integrated_test {
use std::fs::DirBuilder;
use std::{
fs::{DirBuilder, File},
io::{BufWriter, Write},
path::Path,
thread,
time::Duration,
};
use anyhow::{Ok, Result};
use assert_cmd::{assert::OutputAssertExt, Command};
@ -7,9 +13,27 @@ mod integrated_test {
use log::trace;
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]
fn single_device() -> Result<()> {
let config_dir = assert_fs::TempDir::new()?;
setup_gitconfig(&config_dir)?;
// init
let mut cmd = Command::cargo_bin("xdbm")?;
cmd.arg("-c")
@ -96,6 +120,12 @@ mod integrated_test {
.assert()
.success();
let out = std::process::Command::new("git")
.arg("config")
.arg("--get")
.arg("user.email")
.output()?;
panic!("{}", String::from_utf8_lossy(&out.stdout));
Ok(())
}
@ -103,6 +133,7 @@ mod integrated_test {
fn two_devices_with_same_name() -> Result<()> {
// 1st device
let config_dir_1 = assert_fs::TempDir::new()?;
setup_gitconfig(&config_dir_1)?;
let mut cmd1 = Command::cargo_bin("xdbm")?;
cmd1.arg("-c")
.arg(config_dir_1.path())
@ -127,6 +158,7 @@ mod integrated_test {
// 2nd device
let config_dir_2 = assert_fs::TempDir::new()?;
setup_gitconfig(&config_dir_2)?;
let mut cmd2 = Command::cargo_bin("xdbm")?;
cmd2.arg("-c")
.arg(config_dir_2.path())
@ -142,6 +174,7 @@ mod integrated_test {
fn directory_without_parent() -> Result<()> {
// 1st device
let config_dir_1 = assert_fs::TempDir::new()?;
setup_gitconfig(&config_dir_1)?;
let mut cmd1 = Command::cargo_bin("xdbm")?;
cmd1.arg("-c")
.arg(config_dir_1.path())
@ -174,6 +207,7 @@ mod integrated_test {
fn two_devices() -> Result<()> {
// 1st device
let config_dir_1 = assert_fs::TempDir::new()?;
setup_gitconfig(&config_dir_1)?;
let mut cmd1 = Command::cargo_bin("xdbm")?;
cmd1.arg("-c")
.arg(config_dir_1.path())