Skip to content

Commit 4a67095

Browse files
unhappychoiceclaude
andcommitted
test(github): cover GHE host parsing for slug_from_url
Direct unit tests on `parse_with_host` so we can exercise GHE-shaped URLs without coupling to the process-wide `client::host()` OnceLock. Covers HTTPS, SCP-style, `ssh://` scheme variants, the Microsoft GHE `microsoft@...` SCP user, and rejection of mismatched hosts. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent 228476d commit 4a67095

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

‎src/fetcher/github/common.rs‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,49 @@ mod tests {
273273
assert!(slug_from_url("[email protected]:a/b.git").is_none());
274274
}
275275

276+
#[test]
277+
fn parse_with_host_handles_ghe_https() {
278+
let s =
279+
parse_with_host("ghe.example.com", "https://ghe.example.com/owner/repo.git").unwrap();
280+
assert_eq!(s.owner, "owner");
281+
assert_eq!(s.name, "repo");
282+
}
283+
284+
#[test]
285+
fn parse_with_host_handles_ghe_scp() {
286+
let s = parse_with_host("ghe.example.com", "[email protected]:owner/repo.git").unwrap();
287+
assert_eq!(s.owner, "owner");
288+
assert_eq!(s.name, "repo");
289+
}
290+
291+
#[test]
292+
fn parse_with_host_handles_ghe_ssh_scheme() {
293+
let s = parse_with_host(
294+
"ghe.example.com",
295+
"ssh://[email protected]/owner/repo.git",
296+
)
297+
.unwrap();
298+
assert_eq!(s.owner, "owner");
299+
assert_eq!(s.name, "repo");
300+
}
301+
302+
#[test]
303+
fn parse_with_host_accepts_non_git_scp_user() {
304+
let s = parse_with_host(
305+
"ghe.microsoft.com",
306+
"[email protected]:org/repo.git",
307+
)
308+
.unwrap();
309+
assert_eq!(s.owner, "org");
310+
assert_eq!(s.name, "repo");
311+
}
312+
313+
#[test]
314+
fn parse_with_host_rejects_other_host() {
315+
assert!(parse_with_host("ghe.example.com", "https://github.com/owner/repo").is_none());
316+
assert!(parse_with_host("ghe.example.com", "[email protected]:owner/repo.git").is_none());
317+
}
318+
276319
#[test]
277320
fn parse_timestamp_reads_rfc3339() {
278321
let ts = parse_timestamp("2026-04-22T10:15:30Z");

0 commit comments

Comments
 (0)