Skip to content

Commit eb4eba3

Browse files
committed
test(fetcher/gitlab/common): cover payload's metadata-unset wrapping, project_from_url's https-userinfo bail when the credential chunk embeds a slash, and resolve_project's cwd-git-remote fallback recovering the project path from the origin URL
1 parent 1e9c943 commit eb4eba3

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

‎src/fetcher/gitlab/common.rs‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,42 @@ mod tests {
312312
assert_eq!(opts, Opts::default());
313313
}
314314

315+
#[test]
316+
fn payload_wraps_body_and_leaves_all_metadata_unset() {
317+
let p = payload(Body::Text(crate::payload::TextData {
318+
value: "hello".into(),
319+
}));
320+
assert!(p.icon.is_none());
321+
assert!(p.status.is_none());
322+
assert!(p.format.is_none());
323+
assert!(matches!(p.body, Body::Text(t) if t.value == "hello"));
324+
}
325+
326+
#[test]
327+
fn project_from_url_rejects_userinfo_that_contains_a_slash() {
328+
// A userinfo chunk with a slash can't be a real `user(:token)?` credential pair; the
329+
// https-userinfo arm bails out instead of mistaking the embedded slash for the start
330+
// of the project path.
331+
assert!(project_from_url("https://a/[email protected]/group/proj", "gitlab.com").is_none());
332+
}
333+
334+
#[test]
335+
fn resolve_project_falls_back_to_the_cwd_git_remote() {
336+
// With no explicit `project`, resolution walks the cwd's git remote. The suite runs
337+
// inside splashboard's own repo, whose `origin` lives on github.com — passing that
338+
// host lets the generic prefix parser recover `unhappychoice/splashboard` from the
339+
// remote URL, exercising the `Some(path) => Ok(path)` arm.
340+
let _lock = crate::paths::TEST_ENV_LOCK
341+
.lock()
342+
.unwrap_or_else(|e| e.into_inner());
343+
let previous = std::env::current_dir().unwrap();
344+
std::env::set_current_dir(env!("CARGO_MANIFEST_DIR")).unwrap();
345+
let resolved = resolve_project(None, "github.com");
346+
std::env::set_current_dir(previous).unwrap();
347+
let path = resolved.expect("cwd repo remote should resolve a project");
348+
assert_eq!(path.as_str(), "unhappychoice/splashboard");
349+
}
350+
315351
#[test]
316352
fn parse_options_surfaces_serde_failures() {
317353
#[derive(Debug, Default, serde::Deserialize)]

0 commit comments

Comments
 (0)