git_hosting_providers: Clean up tests (#19927)

This PR cleans up the tests for the various Git hosting providers.

These tests had rotted a bit over time, to the point that some of them
weren't even testing what they claimed anymore.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-10-29 17:24:32 -04:00 committed by GitHub
parent 518f6b529b
commit 90edb7189f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 356 additions and 445 deletions

View file

@ -84,53 +84,62 @@ impl GitHostingProvider for Bitbucket {
#[cfg(test)]
mod tests {
use std::sync::Arc;
use git::{parse_git_remote_url, GitHostingProviderRegistry};
use pretty_assertions::assert_eq;
use super::*;
#[test]
fn test_parse_git_remote_url_bitbucket_https_with_username() {
let provider_registry = Arc::new(GitHostingProviderRegistry::new());
provider_registry.register_hosting_provider(Arc::new(Bitbucket));
let url = "https://thorstenballzed@bitbucket.org/thorstenzed/testingrepo.git";
let (provider, parsed) = parse_git_remote_url(provider_registry, url).unwrap();
assert_eq!(provider.name(), "Bitbucket");
assert_eq!(parsed.owner.as_ref(), "thorstenzed");
assert_eq!(parsed.repo.as_ref(), "testingrepo");
fn test_parse_remote_url_given_ssh_url() {
let parsed_remote = Bitbucket
.parse_remote_url("git@bitbucket.org:zed-industries/zed.git")
.unwrap();
assert_eq!(
parsed_remote,
ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
}
);
}
#[test]
fn test_parse_git_remote_url_bitbucket_https_without_username() {
let provider_registry = Arc::new(GitHostingProviderRegistry::new());
provider_registry.register_hosting_provider(Arc::new(Bitbucket));
let url = "https://bitbucket.org/thorstenzed/testingrepo.git";
let (provider, parsed) = parse_git_remote_url(provider_registry, url).unwrap();
assert_eq!(provider.name(), "Bitbucket");
assert_eq!(parsed.owner.as_ref(), "thorstenzed");
assert_eq!(parsed.repo.as_ref(), "testingrepo");
fn test_parse_remote_url_given_https_url() {
let parsed_remote = Bitbucket
.parse_remote_url("https://bitbucket.org/zed-industries/zed.git")
.unwrap();
assert_eq!(
parsed_remote,
ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
}
);
}
#[test]
fn test_parse_git_remote_url_bitbucket_git() {
let provider_registry = Arc::new(GitHostingProviderRegistry::new());
provider_registry.register_hosting_provider(Arc::new(Bitbucket));
let url = "git@bitbucket.org:thorstenzed/testingrepo.git";
let (provider, parsed) = parse_git_remote_url(provider_registry, url).unwrap();
assert_eq!(provider.name(), "Bitbucket");
assert_eq!(parsed.owner.as_ref(), "thorstenzed");
assert_eq!(parsed.repo.as_ref(), "testingrepo");
fn test_parse_remote_url_given_https_url_with_username() {
let parsed_remote = Bitbucket
.parse_remote_url("https://thorstenballzed@bitbucket.org/zed-industries/zed.git")
.unwrap();
assert_eq!(
parsed_remote,
ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
}
);
}
#[test]
fn test_build_bitbucket_permalink_from_ssh_url() {
let remote = ParsedGitRemote {
owner: "thorstenzed".into(),
repo: "testingrepo".into(),
};
fn test_build_bitbucket_permalink() {
let permalink = Bitbucket.build_permalink(
remote,
ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
},
BuildPermalinkParams {
sha: "f00b4r",
path: "main.rs",
@ -138,18 +147,17 @@ mod tests {
},
);
let expected_url = "https://bitbucket.org/thorstenzed/testingrepo/src/f00b4r/main.rs";
let expected_url = "https://bitbucket.org/zed-industries/zed/src/f00b4r/main.rs";
assert_eq!(permalink.to_string(), expected_url.to_string())
}
#[test]
fn test_build_bitbucket_permalink_from_ssh_url_single_line_selection() {
let remote = ParsedGitRemote {
owner: "thorstenzed".into(),
repo: "testingrepo".into(),
};
fn test_build_bitbucket_permalink_with_single_line_selection() {
let permalink = Bitbucket.build_permalink(
remote,
ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
},
BuildPermalinkParams {
sha: "f00b4r",
path: "main.rs",
@ -157,19 +165,17 @@ mod tests {
},
);
let expected_url =
"https://bitbucket.org/thorstenzed/testingrepo/src/f00b4r/main.rs#lines-7";
let expected_url = "https://bitbucket.org/zed-industries/zed/src/f00b4r/main.rs#lines-7";
assert_eq!(permalink.to_string(), expected_url.to_string())
}
#[test]
fn test_build_bitbucket_permalink_from_ssh_url_multi_line_selection() {
let remote = ParsedGitRemote {
owner: "thorstenzed".into(),
repo: "testingrepo".into(),
};
fn test_build_bitbucket_permalink_with_multi_line_selection() {
let permalink = Bitbucket.build_permalink(
remote,
ParsedGitRemote {
owner: "zed-industries".into(),
repo: "zed".into(),
},
BuildPermalinkParams {
sha: "f00b4r",
path: "main.rs",
@ -178,7 +184,7 @@ mod tests {
);
let expected_url =
"https://bitbucket.org/thorstenzed/testingrepo/src/f00b4r/main.rs#lines-24:48";
"https://bitbucket.org/zed-industries/zed/src/f00b4r/main.rs#lines-24:48";
assert_eq!(permalink.to_string(), expected_url.to_string())
}
}