Forge-git integration tests build as one binary
Browse files at this commitc885553c3e0f59aead62ff5d61a2db222b0e1bf2Parent: 74e2f80- refactor
- forge-git integration tests build as one binary
6 changed files +40 -32
- crates/forge-git/tests/browse.rs → crates/forge-git/tests/integration/browse.rs +0 -0
- crates/forge-git/tests/browse_tools.rs → crates/forge-git/tests/integration/browse_tools.rs +3 -12
- crates/forge-git/tests/integration/common.rs +20 -0
- crates/forge-git/tests/forge_git.rs → crates/forge-git/tests/integration/forge_git.rs +6 -11
- crates/forge-git/tests/history.rs → crates/forge-git/tests/integration/history.rs +2 -9
- crates/forge-git/tests/integration/main.rs +9 -0
crates/forge-git/tests/browse.rs → crates/forge-git/tests/integration/browse.rsrenamed+0 -0
crates/forge-git/tests/browse_tools.rs → crates/forge-git/tests/integration/browse_tools.rsrenamed+3 -12
| @@ -8,15 +8,9 @@ use forge_git::GitEnv; | |||
| 8 | use forge_git::blame::blame; | 8 | use forge_git::blame::blame; |
| 9 | use forge_git::branches::{ahead_behind, create_branch, delete_branch}; | 9 | use forge_git::branches::{ahead_behind, create_branch, delete_branch}; |
| 10 | use forge_git::command::ObjectSource; | 10 | use forge_git::command::ObjectSource; |
| 11 | -use forge_git::history::{ | 11 | +use forge_git::history::{commit_diff_ws, commit_patch, commit_raw_diff, list_files, range_patch}; |
| 12 | - DiffLimits, commit_diff_ws, commit_patch, commit_raw_diff, list_files, range_patch, | ||
| 13 | -}; | ||
| 14 | 12 | ||
| 15 | -const BIG: DiffLimits = DiffLimits { | 13 | +use crate::common::{BIG, git_env}; |
| 16 | - max_files: 1000, | ||
| 17 | - max_lines_per_file: 10_000, | ||
| 18 | - max_total_lines: 100_000, | ||
| 19 | -}; | ||
| 20 | 14 | ||
| 21 | struct Fixture { | 15 | struct Fixture { |
| 22 | _dir: tempfile::TempDir, | 16 | _dir: tempfile::TempDir, |
| @@ -58,10 +52,7 @@ fn fixture() -> Fixture { | |||
| 58 | let work = dir.path().join("work"); | 52 | let work = dir.path().join("work"); |
| 59 | std::fs::create_dir(&work).unwrap(); | 53 | std::fs::create_dir(&work).unwrap(); |
| 60 | run(&work, dir.path(), &["init", "-q", "-b", "main"]); | 54 | run(&work, dir.path(), &["init", "-q", "-b", "main"]); |
| 61 | - let env = GitEnv { | 55 | + let env = git_env(dir.path()); |
| 62 | - git_bin: PathBuf::from("/usr/bin/git"), | ||
| 63 | - data_dir: dir.path().to_path_buf(), | ||
| 64 | - }; | ||
| 65 | let git_dir = work.join(".git"); | 56 | let git_dir = work.join(".git"); |
| 66 | Fixture { | 57 | Fixture { |
| 67 | _dir: dir, | 58 | _dir: dir, |
crates/forge-git/tests/integration/common.rsadded+20 -0
| @@ -0,0 +1,20 @@ | |||
| 1 | +//! Support shared by the integration test modules. | ||
| 2 | + | ||
| 3 | +use std::path::Path; | ||
| 4 | +use std::path::PathBuf; | ||
| 5 | + | ||
| 6 | +use forge_git::GitEnv; | ||
| 7 | +use forge_git::history::DiffLimits; | ||
| 8 | + | ||
| 9 | +pub const BIG: DiffLimits = DiffLimits { | ||
| 10 | + max_files: 1000, | ||
| 11 | + max_lines_per_file: 10_000, | ||
| 12 | + max_total_lines: 100_000, | ||
| 13 | +}; | ||
| 14 | + | ||
| 15 | +pub fn git_env(data_dir: &Path) -> GitEnv { | ||
| 16 | + GitEnv { | ||
| 17 | + git_bin: PathBuf::from("/usr/bin/git"), | ||
| 18 | + data_dir: data_dir.to_path_buf(), | ||
| 19 | + } | ||
| 20 | +} | ||
crates/forge-git/tests/forge_git.rs → crates/forge-git/tests/integration/forge_git.rsrenamed+6 -11
| @@ -1,19 +1,14 @@ | |||
| 1 | use std::path::{Path, PathBuf}; | 1 | use std::path::{Path, PathBuf}; |
| 2 | use std::process::Command; | 2 | use std::process::Command; |
| 3 | 3 | ||
| 4 | -use forge_git::command::{GitCommand, GitEnv}; | 4 | +use forge_git::command::GitCommand; |
| 5 | use forge_git::pktline::{FLUSH_PKT, pkt_line, service_advertisement_header}; | 5 | use forge_git::pktline::{FLUSH_PKT, pkt_line, service_advertisement_header}; |
| 6 | use forge_git::repo::{init_bare, list_branches, repo_path}; | 6 | use forge_git::repo::{init_bare, list_branches, repo_path}; |
| 7 | use forge_git::service::{GitService, service_command}; | 7 | use forge_git::service::{GitService, service_command}; |
| 8 | use forge_git::setup::{write_hook_shims, write_managed_gitconfig}; | 8 | use forge_git::setup::{write_hook_shims, write_managed_gitconfig}; |
| 9 | use forge_git::version::parse_git_version; | 9 | use forge_git::version::parse_git_version; |
| 10 | 10 | ||
| 11 | -fn env_for(data_dir: &Path) -> GitEnv { | 11 | +use crate::common::git_env; |
| 12 | - GitEnv { | ||
| 13 | - git_bin: PathBuf::from("/usr/bin/git"), | ||
| 14 | - data_dir: data_dir.to_path_buf(), | ||
| 15 | - } | ||
| 16 | -} | ||
| 17 | 12 | ||
| 18 | const ULID: &str = "01arz3ndektsv4rrffq69g5fav"; | 13 | const ULID: &str = "01arz3ndektsv4rrffq69g5fav"; |
| 19 | 14 | ||
| @@ -53,7 +48,7 @@ fn repo_path_layout() { | |||
| 53 | #[tokio::test] | 48 | #[tokio::test] |
| 54 | async fn init_bare_and_list_branches_empty() { | 49 | async fn init_bare_and_list_branches_empty() { |
| 55 | let dir = tempfile::tempdir().unwrap(); | 50 | let dir = tempfile::tempdir().unwrap(); |
| 56 | - let env = env_for(dir.path()); | 51 | + let env = git_env(dir.path()); |
| 57 | let repo = repo_path(dir.path(), ULID).unwrap(); | 52 | let repo = repo_path(dir.path(), ULID).unwrap(); |
| 58 | init_bare(&env, &repo, "trunk").await.unwrap(); | 53 | init_bare(&env, &repo, "trunk").await.unwrap(); |
| 59 | assert!(repo.join("HEAD").exists()); | 54 | assert!(repo.join("HEAD").exists()); |
| @@ -64,7 +59,7 @@ async fn init_bare_and_list_branches_empty() { | |||
| 64 | #[tokio::test] | 59 | #[tokio::test] |
| 65 | async fn init_bare_rejects_bad_branch() { | 60 | async fn init_bare_rejects_bad_branch() { |
| 66 | let dir = tempfile::tempdir().unwrap(); | 61 | let dir = tempfile::tempdir().unwrap(); |
| 67 | - let env = env_for(dir.path()); | 62 | + let env = git_env(dir.path()); |
| 68 | let repo = dir.path().join("x.git"); | 63 | let repo = dir.path().join("x.git"); |
| 69 | assert!(init_bare(&env, &repo, "-x").await.is_err()); | 64 | assert!(init_bare(&env, &repo, "-x").await.is_err()); |
| 70 | assert!(init_bare(&env, &repo, "a..b").await.is_err()); | 65 | assert!(init_bare(&env, &repo, "a..b").await.is_err()); |
| @@ -74,7 +69,7 @@ async fn init_bare_rejects_bad_branch() { | |||
| 74 | #[test] | 69 | #[test] |
| 75 | fn user_revs_rejects_option_like_values() { | 70 | fn user_revs_rejects_option_like_values() { |
| 76 | let dir = tempfile::tempdir().unwrap(); | 71 | let dir = tempfile::tempdir().unwrap(); |
| 77 | - let env = env_for(dir.path()); | 72 | + let env = git_env(dir.path()); |
| 78 | assert!(GitCommand::new(&env, "log").user_revs(&["-x"]).is_err()); | 73 | assert!(GitCommand::new(&env, "log").user_revs(&["-x"]).is_err()); |
| 79 | assert!(GitCommand::new(&env, "log").user_revs(&[""]).is_err()); | 74 | assert!(GitCommand::new(&env, "log").user_revs(&[""]).is_err()); |
| 80 | assert!(GitCommand::new(&env, "log").user_revs(&["main"]).is_ok()); | 75 | assert!(GitCommand::new(&env, "log").user_revs(&["main"]).is_ok()); |
| @@ -126,7 +121,7 @@ fn hook_shims_are_executable() { | |||
| 126 | #[tokio::test] | 121 | #[tokio::test] |
| 127 | async fn upload_pack_advertise_exits_zero() { | 122 | async fn upload_pack_advertise_exits_zero() { |
| 128 | let dir = tempfile::tempdir().unwrap(); | 123 | let dir = tempfile::tempdir().unwrap(); |
| 129 | - let env = env_for(dir.path()); | 124 | + let env = git_env(dir.path()); |
| 130 | let repo = repo_path(dir.path(), ULID).unwrap(); | 125 | let repo = repo_path(dir.path(), ULID).unwrap(); |
| 131 | init_bare(&env, &repo, "main").await.unwrap(); | 126 | init_bare(&env, &repo, "main").await.unwrap(); |
| 132 | service_command(&env, GitService::UploadPack, &repo, true, true, None) | 127 | service_command(&env, GitService::UploadPack, &repo, true, true, None) |
crates/forge-git/tests/history.rs → crates/forge-git/tests/integration/history.rsrenamed+2 -9
| @@ -8,11 +8,7 @@ use forge_git::history::{ | |||
| 8 | }; | 8 | }; |
| 9 | use forge_git::{Error, GitEnv}; | 9 | use forge_git::{Error, GitEnv}; |
| 10 | 10 | ||
| 11 | -const BIG: DiffLimits = DiffLimits { | 11 | +use crate::common::{BIG, git_env}; |
| 12 | - max_files: 1000, | ||
| 13 | - max_lines_per_file: 10_000, | ||
| 14 | - max_total_lines: 100_000, | ||
| 15 | -}; | ||
| 16 | 12 | ||
| 17 | struct Fixture { | 13 | struct Fixture { |
| 18 | _dir: tempfile::TempDir, | 14 | _dir: tempfile::TempDir, |
| @@ -54,10 +50,7 @@ fn fixture() -> Fixture { | |||
| 54 | let work = dir.path().join("work"); | 50 | let work = dir.path().join("work"); |
| 55 | std::fs::create_dir(&work).unwrap(); | 51 | std::fs::create_dir(&work).unwrap(); |
| 56 | git_in(&work, dir.path(), &["init", "-q", "-b", "main"]); | 52 | git_in(&work, dir.path(), &["init", "-q", "-b", "main"]); |
| 57 | - let env = GitEnv { | 53 | + let env = git_env(dir.path()); |
| 58 | - git_bin: PathBuf::from("/usr/bin/git"), | ||
| 59 | - data_dir: dir.path().to_path_buf(), | ||
| 60 | - }; | ||
| 61 | let git_dir = work.join(".git"); | 54 | let git_dir = work.join(".git"); |
| 62 | Fixture { | 55 | Fixture { |
| 63 | _dir: dir, | 56 | _dir: dir, |
crates/forge-git/tests/integration/main.rsadded+9 -0
| @@ -0,0 +1,9 @@ | |||
| 1 | +//! forge-git integration tests. All modules compile into this single test binary. | ||
| 2 | + | ||
| 3 | +#[allow(dead_code)] | ||
| 4 | +mod common; | ||
| 5 | + | ||
| 6 | +mod browse; | ||
| 7 | +mod browse_tools; | ||
| 8 | +mod forge_git; | ||
| 9 | +mod history; | ||