95 lines
2.1 KiB
Rust
95 lines
2.1 KiB
Rust
use assert_cmd::Command;
|
|
use tempfile::NamedTempFile;
|
|
|
|
#[test]
|
|
fn render_md_reads_json_and_outputs_markdown_to_stdout() {
|
|
let input = NamedTempFile::new().unwrap();
|
|
std::fs::write(
|
|
input.path(),
|
|
r#"{
|
|
"meta": {
|
|
"repo": "org/repo",
|
|
"pr_index": 1,
|
|
"title": "t",
|
|
"state": "open",
|
|
"author": "a",
|
|
"base_branch": "main",
|
|
"head_branch": "f",
|
|
"created_at": "2026-04-08T10:00:00Z",
|
|
"updated_at": "2026-04-08T11:00:00Z",
|
|
"merged_at": null
|
|
},
|
|
"commits": [],
|
|
"diff_stat": {
|
|
"files_changed": 0,
|
|
"additions": 0,
|
|
"deletions": 0,
|
|
"files": []
|
|
},
|
|
"reviews": [],
|
|
"threads": []
|
|
}"#,
|
|
)
|
|
.unwrap();
|
|
|
|
let mut cmd = Command::cargo_bin("gitea-pr-review").unwrap();
|
|
let assert = cmd
|
|
.args(["render-md", "--in", input.path().to_str().unwrap()])
|
|
.assert()
|
|
.success();
|
|
|
|
let stdout = String::from_utf8(assert.get_output().stdout.clone()).unwrap();
|
|
assert!(stdout.contains("# org/repo `#1` t"));
|
|
assert!(stdout.contains("## Metadata"));
|
|
}
|
|
|
|
#[test]
|
|
fn render_md_writes_to_out_file_when_requested() {
|
|
let input = NamedTempFile::new().unwrap();
|
|
std::fs::write(
|
|
input.path(),
|
|
r#"{
|
|
"meta": {
|
|
"repo": "org/repo",
|
|
"pr_index": 2,
|
|
"title": "t2",
|
|
"state": "open",
|
|
"author": "a",
|
|
"base_branch": "main",
|
|
"head_branch": "f",
|
|
"created_at": "2026-04-08T10:00:00Z",
|
|
"updated_at": "2026-04-08T11:00:00Z",
|
|
"merged_at": null
|
|
},
|
|
"commits": [],
|
|
"diff_stat": {
|
|
"files_changed": 0,
|
|
"additions": 0,
|
|
"deletions": 0,
|
|
"files": []
|
|
},
|
|
"reviews": [],
|
|
"threads": []
|
|
}"#,
|
|
)
|
|
.unwrap();
|
|
|
|
let output = NamedTempFile::new().unwrap();
|
|
|
|
Command::cargo_bin("gitea-pr-review")
|
|
.unwrap()
|
|
.args([
|
|
"render-md",
|
|
"--in",
|
|
input.path().to_str().unwrap(),
|
|
"--out",
|
|
output.path().to_str().unwrap(),
|
|
])
|
|
.assert()
|
|
.success();
|
|
|
|
let written = std::fs::read_to_string(output.path()).unwrap();
|
|
assert!(written.contains("# org/repo `#2` t2"));
|
|
assert!(written.contains("## Metadata"));
|
|
}
|