Skip to content

Commit d8db55f

Browse files
committed
ci: dev
1 parent 65be541 commit d8db55f

File tree

5 files changed

+100
-14
lines changed

5 files changed

+100
-14
lines changed

src/pipeline/vcs_data_to_zerv_vars.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ mod tests {
3232
use crate::test_utils::{get_real_pep440_vcs_data, get_real_semver_vcs_data};
3333

3434
#[test]
35-
#[ignore = "docker"]
3635
fn test_vcs_data_to_zerv_vars_real_semver() {
3736
let vcs_data = get_real_semver_vcs_data().clone();
3837
let vars = vcs_data_to_zerv_vars(vcs_data).unwrap();
@@ -47,7 +46,6 @@ mod tests {
4746
}
4847

4948
#[test]
50-
#[ignore = "docker"]
5149
fn test_vcs_data_to_zerv_vars_real_pep440() {
5250
let vcs_data = get_real_pep440_vcs_data().clone();
5351
let vars = vcs_data_to_zerv_vars(vcs_data).unwrap();

src/test_utils/git.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ impl DockerGit {
2929
}
3030

3131
fn run_docker_command(&self, test_dir: &TestDir, script: &str) -> io::Result<String> {
32+
// Check if Docker is available
33+
if Command::new("docker").arg("--version").output().is_err() {
34+
return Err(io::Error::other(
35+
"Docker not available - use native Git in CI",
36+
));
37+
}
38+
3239
let uid = unsafe { libc::getuid() };
3340
let gid = unsafe { libc::getgid() };
3441

src/test_utils/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@ pub mod vcs_fixtures;
55
pub use dir::TestDir;
66
pub use git::DockerGit;
77
pub use vcs_fixtures::{get_real_pep440_vcs_data, get_real_semver_vcs_data};
8+
9+
/// Check if we should use native Git (CI only) or Docker (local development)
10+
pub fn should_use_native_git() -> bool {
11+
std::env::var("CI").is_ok()
12+
}

src/test_utils/vcs_fixtures.rs

Lines changed: 87 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,107 @@
1-
use super::{DockerGit, TestDir};
1+
use super::{DockerGit, TestDir, should_use_native_git};
22
use crate::vcs::{Vcs, VcsData, git::GitVcs};
3+
use std::fs;
4+
use std::process::Command;
35
use std::sync::OnceLock;
46

57
static SEMVER_VCS_DATA: OnceLock<VcsData> = OnceLock::new();
68
static PEP440_VCS_DATA: OnceLock<VcsData> = OnceLock::new();
79

810
fn create_vcs_data_with_tag(tag: &str, filename: &str, content: &str, commit_msg: &str) -> VcsData {
911
let test_dir = TestDir::new().expect("Failed to create test dir");
12+
13+
if should_use_native_git() {
14+
create_vcs_data_with_native_git(&test_dir, tag, filename, content, commit_msg)
15+
} else {
16+
create_vcs_data_with_docker(&test_dir, tag, filename, content, commit_msg)
17+
}
18+
}
19+
20+
fn create_vcs_data_with_native_git(
21+
test_dir: &TestDir,
22+
tag: &str,
23+
filename: &str,
24+
content: &str,
25+
commit_msg: &str,
26+
) -> VcsData {
27+
let path = test_dir.path();
28+
29+
// Create initial file
30+
fs::write(path.join("README.md"), "# Test Repository").expect("Failed to create README");
31+
32+
// Use isolated Git config
33+
let git_cmd = |args: &[&str]| {
34+
Command::new("git")
35+
.env("GIT_CONFIG_GLOBAL", "/dev/null")
36+
.env("GIT_CONFIG_SYSTEM", "/dev/null")
37+
.args(args)
38+
.current_dir(path)
39+
.output()
40+
.expect("should execute git command")
41+
};
42+
43+
// Initialize repo and create initial commit
44+
let commands = [
45+
&["init"][..],
46+
&["config", "user.name", "Test User"],
47+
&["config", "user.email", "test@example.com"],
48+
&["add", "."],
49+
&["commit", "-m", "Initial commit"],
50+
&["tag", tag],
51+
];
52+
53+
for args in commands {
54+
let output = git_cmd(args);
55+
assert!(
56+
output.status.success(),
57+
"Git command '{:?}' failed: {}",
58+
args,
59+
String::from_utf8_lossy(&output.stderr)
60+
);
61+
}
62+
63+
// Create additional file and commit
64+
test_dir
65+
.create_file(filename, content)
66+
.expect("Failed to create file");
67+
68+
let output = git_cmd(&["add", "."]);
69+
assert!(
70+
output.status.success(),
71+
"Git add failed: {}",
72+
String::from_utf8_lossy(&output.stderr)
73+
);
74+
75+
let output = git_cmd(&["commit", "-m", commit_msg]);
76+
assert!(
77+
output.status.success(),
78+
"Git commit failed: {}",
79+
String::from_utf8_lossy(&output.stderr)
80+
);
81+
82+
let git_vcs = GitVcs::new(test_dir.path()).expect("Failed to create GitVcs");
83+
git_vcs.get_vcs_data().expect("Failed to get VCS data")
84+
}
85+
86+
fn create_vcs_data_with_docker(
87+
test_dir: &TestDir,
88+
tag: &str,
89+
filename: &str,
90+
content: &str,
91+
commit_msg: &str,
92+
) -> VcsData {
1093
let docker_git = DockerGit::new();
1194

95+
docker_git.init_repo(test_dir).expect("Failed to init repo");
1296
docker_git
13-
.init_repo(&test_dir)
14-
.expect("Failed to init repo");
15-
docker_git
16-
.create_tag(&test_dir, tag)
97+
.create_tag(test_dir, tag)
1798
.expect("Failed to create tag");
1899

19100
test_dir
20101
.create_file(filename, content)
21102
.expect("Failed to create file");
22103
docker_git
23-
.create_commit(&test_dir, commit_msg)
104+
.create_commit(test_dir, commit_msg)
24105
.expect("Failed to create commit");
25106

26107
let git_vcs = GitVcs::new(test_dir.path()).expect("Failed to create GitVcs");

src/vcs/git.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,10 @@ impl Vcs for GitVcs {
158158
#[cfg(test)]
159159
mod tests {
160160
use super::*;
161-
use crate::test_utils::TestDir;
161+
use crate::test_utils::{TestDir, should_use_native_git};
162162
use std::fs;
163163
use std::process::Command;
164164

165-
/// Check if we should use native Git (CI only) or Docker (local development)
166-
fn should_use_native_git() -> bool {
167-
std::env::var("CI").is_ok()
168-
}
169-
170165
/// Setup Git repo - uses native Git in CI, Docker locally
171166
fn setup_test_git_repo() -> TestDir {
172167
if should_use_native_git() {

0 commit comments

Comments
 (0)