Skip to content

Commit 1de77f3

Browse files
committed
reinstate test where bad_pr_info causes panic
1 parent c25e194 commit 1de77f3

1 file changed

Lines changed: 31 additions & 24 deletions

File tree

cpp-linter/tests/reviews.rs

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,19 @@ fn generate_tool_summary(review_enabled: bool, force_lgtm: bool, tool_name: &str
7272

7373
async fn setup(lib_root: &Path, test_params: &TestParams) {
7474
let mut event_payload_path = NamedTempFile::new_in("./").unwrap();
75-
let event_payload = serde_json::json!({
76-
"pull_request": {
77-
"draft": test_params.pr_draft,
78-
"state": test_params.pr_state,
79-
"number": PR,
80-
"locked": false,
81-
}
82-
})
83-
.to_string();
75+
let event_payload = if test_params.bad_pr_info {
76+
"".to_string()
77+
} else {
78+
serde_json::json!({
79+
"pull_request": {
80+
"draft": test_params.pr_draft,
81+
"state": test_params.pr_state,
82+
"number": PR,
83+
"locked": false,
84+
}
85+
})
86+
.to_string()
87+
};
8488
event_payload_path
8589
.write_all(event_payload.as_bytes())
8690
.expect("Failed to create mock event payload.");
@@ -108,22 +112,24 @@ async fn setup(lib_root: &Path, test_params: &TestParams) {
108112
}
109113
let mut mocks = vec![];
110114

111-
let pr_endpoint = format!("/repos/{REPO}/pulls/{PR}");
112-
mocks.push(
113-
server
114-
.mock("GET", format!("{pr_endpoint}/files").as_str())
115-
.match_header("Accept", "application/vnd.github.raw+json")
116-
.match_header("Authorization", format!("token {TOKEN}").as_str())
117-
.match_query(Matcher::Any)
118-
.with_body_from_file(format!("{asset_path}pr_27.json"))
119-
.with_header(REMAINING_RATE_LIMIT_HEADER, "50")
120-
.with_header(RESET_RATE_LIMIT_HEADER, reset_timestamp.as_str())
121-
.create(),
122-
);
115+
if !test_params.bad_pr_info {
116+
let pr_endpoint = format!("/repos/{REPO}/pulls/{PR}");
117+
mocks.push(
118+
server
119+
.mock("GET", format!("{pr_endpoint}/files").as_str())
120+
.match_header("Accept", "application/vnd.github.raw+json")
121+
.match_header("Authorization", format!("token {TOKEN}").as_str())
122+
.match_query(Matcher::Any)
123+
.with_body_from_file(format!("{asset_path}pr_27.json"))
124+
.with_header(REMAINING_RATE_LIMIT_HEADER, "50")
125+
.with_header(RESET_RATE_LIMIT_HEADER, reset_timestamp.as_str())
126+
.create(),
127+
);
128+
}
123129

124130
let reviews_endpoint = format!("/repos/{REPO}/pulls/{PR}/reviews");
125131

126-
if test_params.pr_state != "closed" {
132+
if test_params.pr_state != "closed" && !test_params.bad_pr_info {
127133
let mut mock = server
128134
.mock("GET", reviews_endpoint.as_str())
129135
.match_header("Accept", "application/vnd.github.raw+json")
@@ -149,6 +155,7 @@ async fn setup(lib_root: &Path, test_params: &TestParams) {
149155
if !test_params.fail_get_existing_reviews
150156
&& !test_params.bad_existing_reviews
151157
&& test_params.pr_state != "closed"
158+
&& !test_params.bad_pr_info
152159
{
153160
mocks.push(
154161
server
@@ -247,12 +254,12 @@ async fn setup(lib_root: &Path, test_params: &TestParams) {
247254
}
248255
match run_main(args).await {
249256
Ok(_) => {
250-
if test_params.bad_existing_reviews {
257+
if test_params.bad_existing_reviews || test_params.bad_pr_info {
251258
panic!("Expected failure, but it succeeded");
252259
}
253260
}
254261
Err(e) => {
255-
if !test_params.bad_existing_reviews {
262+
if !test_params.bad_existing_reviews && !test_params.bad_pr_info {
256263
panic!("Failed unexpectedly: {e:?}");
257264
}
258265
}

0 commit comments

Comments
 (0)