Add a few simple integration tests

This commit is contained in:
2021-11-21 22:00:18 +01:00
parent ca1f649ecf
commit 78a957268d
5 changed files with 121 additions and 1 deletions

63
Cargo.lock generated
View File

@@ -169,6 +169,12 @@ dependencies = [
"percent-encoding", "percent-encoding",
] ]
[[package]]
name = "fuchsia-cprng"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba"
[[package]] [[package]]
name = "getrandom" name = "getrandom"
version = "0.2.3" version = "0.2.3"
@@ -191,6 +197,7 @@ dependencies = [
"regex", "regex",
"serde", "serde",
"shellexpand", "shellexpand",
"tempdir",
"toml", "toml",
] ]
@@ -498,6 +505,43 @@ dependencies = [
"proc-macro2", "proc-macro2",
] ]
[[package]]
name = "rand"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293"
dependencies = [
"fuchsia-cprng",
"libc",
"rand_core 0.3.1",
"rdrand",
"winapi",
]
[[package]]
name = "rand_core"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b"
dependencies = [
"rand_core 0.4.2",
]
[[package]]
name = "rand_core"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc"
[[package]]
name = "rdrand"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2"
dependencies = [
"rand_core 0.3.1",
]
[[package]] [[package]]
name = "redox_syscall" name = "redox_syscall"
version = "0.2.10" version = "0.2.10"
@@ -534,6 +578,15 @@ version = "0.6.25"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
[[package]]
name = "remove_dir_all"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
dependencies = [
"winapi",
]
[[package]] [[package]]
name = "scopeguard" name = "scopeguard"
version = "1.1.0" version = "1.1.0"
@@ -640,6 +693,16 @@ dependencies = [
"unicode-xid", "unicode-xid",
] ]
[[package]]
name = "tempdir"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8"
dependencies = [
"rand",
"remove_dir_all",
]
[[package]] [[package]]
name = "termcolor" name = "termcolor"
version = "1.1.2" version = "1.1.2"

View File

@@ -60,3 +60,6 @@ version = "1.5"
[dependencies.comfy-table] [dependencies.comfy-table]
version = "5.0" version = "5.0"
[dev-dependencies.tempdir]
version = "0.3"

View File

@@ -5,7 +5,7 @@ use std::process;
mod cmd; mod cmd;
mod config; mod config;
mod output; mod output;
mod repo; pub mod repo;
use config::{Config, Tree}; use config::{Config, Tree};
use output::*; use output::*;

11
tests/helpers.rs Normal file
View File

@@ -0,0 +1,11 @@
use tempdir::TempDir;
pub fn init_tmpdir() -> TempDir {
let tmp_dir = TempDir::new("grm-test").unwrap();
println!("Temporary directory: {}", tmp_dir.path().display());
tmp_dir
}
pub fn cleanup_tmpdir(tempdir: TempDir) {
tempdir.close().unwrap();
}

43
tests/repo.rs Normal file
View File

@@ -0,0 +1,43 @@
use grm::repo::*;
mod helpers;
use helpers::*;
#[test]
fn open_empty_repo() {
let tmpdir = init_tmpdir();
assert!(matches!(
open_repo(tmpdir.path(), true),
Err(RepoError {
kind: RepoErrorKind::NotFound
})
));
assert!(matches!(
open_repo(tmpdir.path(), false),
Err(RepoError {
kind: RepoErrorKind::NotFound
})
));
cleanup_tmpdir(tmpdir);
}
#[test]
fn create_repo() -> Result<(), Box<dyn std::error::Error>> {
let tmpdir = init_tmpdir();
let repo = init_repo(tmpdir.path(), false)?;
assert!(!repo.is_bare());
assert!(repo.is_empty()?);
cleanup_tmpdir(tmpdir);
Ok(())
}
#[test]
fn create_repo_with_worktree() -> Result<(), Box<dyn std::error::Error>> {
let tmpdir = init_tmpdir();
let repo = init_repo(tmpdir.path(), true)?;
assert!(repo.is_bare());
assert!(repo.is_empty()?);
cleanup_tmpdir(tmpdir);
Ok(())
}