-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrun_config_executable_override_test.rs
More file actions
98 lines (76 loc) · 3.57 KB
/
run_config_executable_override_test.rs
File metadata and controls
98 lines (76 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
use std::error::Error;
use std::path::Path;
mod common;
use common::{build_run_config, git_add_all_files, setup_fixture_repo};
#[test]
fn test_run_config_executable_path_overrides_config_file() -> Result<(), Box<dyn Error>> {
use codeowners::runner::validate;
let fixture_root = Path::new("tests/fixtures/custom_executable_name");
let temp_dir = setup_fixture_repo(fixture_root);
let project_path = temp_dir.path();
git_add_all_files(project_path);
// This fixture has executable_name: "bin/codeownership validate" in config
// But we'll override it with RunConfig.executable_name
let mut run_config = build_run_config(project_path, ".github/CODEOWNERS");
run_config.executable_name = Some("my-wrapper-tool validate".to_string());
let result = validate(&run_config, vec![]);
// Should use "my-wrapper-tool validate" from RunConfig, NOT "bin/codeownership validate" from config
assert!(!result.validation_errors.is_empty(), "Expected validation errors but got none");
let error_msg = result.validation_errors.join("\n");
assert!(
error_msg.contains("Run `my-wrapper-tool validate`"),
"Expected error to contain 'my-wrapper-tool validate' but got: {}",
error_msg
);
assert!(
!error_msg.contains("bin/codeownership"),
"Error should not contain config file's executable_name when overridden"
);
Ok(())
}
#[test]
fn test_run_config_without_executable_path_uses_config_file() -> Result<(), Box<dyn Error>> {
use codeowners::runner::validate;
let fixture_root = Path::new("tests/fixtures/custom_executable_name");
let temp_dir = setup_fixture_repo(fixture_root);
let project_path = temp_dir.path();
git_add_all_files(project_path);
// This fixture has executable_name: "bin/codeownership validate" in config
let mut run_config = build_run_config(project_path, ".github/CODEOWNERS");
run_config.executable_name = None; // Explicitly no override
let result = validate(&run_config, vec![]);
// Should use "bin/codeownership validate" from config file
assert!(!result.validation_errors.is_empty(), "Expected validation errors but got none");
let error_msg = result.validation_errors.join("\n");
assert!(
error_msg.contains("Run `bin/codeownership validate`"),
"Expected error to contain 'bin/codeownership validate' but got: {}",
error_msg
);
Ok(())
}
#[test]
fn test_run_config_executable_path_overrides_default() -> Result<(), Box<dyn Error>> {
use codeowners::runner::validate;
let fixture_root = Path::new("tests/fixtures/default_executable_name");
let temp_dir = setup_fixture_repo(fixture_root);
let project_path = temp_dir.path();
git_add_all_files(project_path);
// This fixture has NO executable_name in config (uses default "codeowners generate")
let mut run_config = build_run_config(project_path, ".github/CODEOWNERS");
run_config.executable_name = Some("custom-command generate".to_string());
let result = validate(&run_config, vec![]);
// Should use "custom-command generate" from RunConfig, NOT default "codeowners generate"
assert!(!result.validation_errors.is_empty(), "Expected validation errors but got none");
let error_msg = result.validation_errors.join("\n");
assert!(
error_msg.contains("Run `custom-command generate`"),
"Expected error to contain 'custom-command generate' but got: {}",
error_msg
);
assert!(
!error_msg.contains("codeowners generate"),
"Error should not contain default when overridden"
);
Ok(())
}