feat: enforce output version v1 and add version subcommand
This commit is contained in:
@@ -8,6 +8,7 @@ fn render_md_reads_json_and_outputs_markdown_to_stdout() {
|
||||
std::fs::write(
|
||||
input.path(),
|
||||
r#"{
|
||||
"version": "v1",
|
||||
"meta": {
|
||||
"repo": "org/repo",
|
||||
"pr_index": 1,
|
||||
@@ -52,6 +53,7 @@ fn render_md_writes_to_out_file_when_requested() {
|
||||
std::fs::write(
|
||||
input.path(),
|
||||
r#"{
|
||||
"version": "v1",
|
||||
"meta": {
|
||||
"repo": "org/repo",
|
||||
"pr_index": 2,
|
||||
@@ -291,6 +293,59 @@ fn fetch_writes_json_to_out_file_when_requested() {
|
||||
let written = std::fs::read_to_string(output.path()).unwrap();
|
||||
assert!(written.contains("\"repo\": \"org/repo\""));
|
||||
assert!(written.contains("\"pr_index\": 8"));
|
||||
assert!(written.contains("\"version\": \"v1\""));
|
||||
assert!(written.contains("\"fetched_at\":"));
|
||||
assert!(written.contains("\"head_branch\": \"feature/y\""));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn render_md_fails_when_version_mismatch() {
|
||||
let input = NamedTempFile::new().unwrap();
|
||||
std::fs::write(
|
||||
input.path(),
|
||||
r#"{
|
||||
"version": "v2",
|
||||
"meta": {
|
||||
"repo": "org/repo",
|
||||
"pr_index": 3,
|
||||
"title": "t3",
|
||||
"description": "PR body",
|
||||
"fetched_at": "2026-04-08T12:34:56Z",
|
||||
"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();
|
||||
|
||||
Command::cargo_bin("gitea-pr-review")
|
||||
.unwrap()
|
||||
.args(["render-md", "--in", input.path().to_str().unwrap()])
|
||||
.assert()
|
||||
.failure();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn version_subcommand_prints_current_version() {
|
||||
let assert = Command::cargo_bin("gitea-pr-review")
|
||||
.unwrap()
|
||||
.arg("version")
|
||||
.assert()
|
||||
.success();
|
||||
let stdout = String::from_utf8(assert.get_output().stdout.clone()).unwrap();
|
||||
assert_eq!(stdout.trim(), "v1");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user