| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | use std::path::Path; |
| 8 | |
| 9 | use tempfile::TempDir; |
| 10 | |
| 11 | use crate::domain::{OrgName, RepoName}; |
| 12 | |
| 13 | use super::storage::DiskGitStorage; |
| 14 | |
| 15 | |
| 16 | |
| 17 | pub(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 | |
| 23 | pub(crate) fn handle() -> OrgName { |
| 24 | OrgName::new("jamesgill").expect("valid handle") |
| 25 | } |
| 26 | |
| 27 | pub(crate) fn repo_name(value: &str) -> RepoName { |
| 28 | RepoName::new(value).expect("valid repository name") |
| 29 | } |
| 30 | |
| 31 | |
| 32 | |
| 33 | pub(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 | } |