steid

@jamesgill /

Rust1.5 KBCode·Blame·History·Raw
1//! Fixtures the adapters' own tests share.
2//!
3//! `handle`, `repo_name` and `git_says` are used by every file in this module, and
4//! `storage` by three of them, so they sit here rather than being copied five times.
5//! Test-only: the module is `#[cfg(test)]` at its declaration.
6
7use std::path::Path;
8
9use tempfile::TempDir;
10
11use crate::domain::{OrgName, RepoName};
12
13use super::storage::DiskGitStorage;
14
15/// The `TempDir` is returned alongside the storage because dropping it deletes the
16/// data directory — binding it to `_` would remove the fixture mid-test.
17pub(crate) fn storage() -> (TempDir, DiskGitStorage) {
18 let dir = TempDir::new().expect("temp dir");
19 let storage = DiskGitStorage::new(dir.path());
20 (dir, storage)
21}
22
23pub(crate) fn handle() -> OrgName {
24 OrgName::new("jamesgill").expect("valid handle")
25}
26
27pub(crate) fn repo_name(value: &str) -> RepoName {
28 RepoName::new(value).expect("valid repository name")
29}
30
31/// Asks git about a repository, so assertions test what git believes rather than
32/// what the directory looks like.
33pub(crate) fn git_says(path: &Path, args: &[&str]) -> String {
34 let output = std::process::Command::new("git")
35 .arg("-C")
36 .arg(path)
37 .args(args)
38 .output()
39 .expect("git should be on PATH");
40
41 assert!(
42 output.status.success(),
43 "git {args:?} failed: {}",
44 String::from_utf8_lossy(&output.stderr)
45 );
46
47 String::from_utf8_lossy(&output.stdout).trim().to_owned()
48}