diff options
-rw-r--r-- | src/lib.rs | 39 | ||||
-rw-r--r-- | tests/ci_test.rs | 6 | ||||
-rw-r--r-- | tests/repo_data.json | 91 |
3 files changed, 39 insertions, 97 deletions
@@ -290,6 +290,45 @@ fn parse_ssh_url(raw_url: &String) -> Result<Url, url::ParseError> { }) } +#[test] +fn ssh_url_deserialization() { + #[derive(serde::Deserialize)] + struct SshUrl { + #[serde(deserialize_with = "deserialize_ssh_url")] + url: url::Url, + } + let full_url = r#"{ "url": "ssh://git@codeberg.org/Cyborus/forgejo-api" }"#; + let ssh_url = r#"{ "url": "git@codeberg.org:Cyborus/forgejo-api" }"#; + + let full_url_de = + serde_json::from_str::<SshUrl>(full_url).expect("failed to deserialize full url"); + let ssh_url_de = + serde_json::from_str::<SshUrl>(ssh_url).expect("failed to deserialize ssh url"); + + let expected = "ssh://git@codeberg.org/Cyborus/forgejo-api"; + assert_eq!(full_url_de.url.as_str(), expected); + assert_eq!(ssh_url_de.url.as_str(), expected); + + #[derive(serde::Deserialize)] + struct OptSshUrl { + #[serde(deserialize_with = "deserialize_optional_ssh_url")] + url: Option<url::Url>, + } + let null_url = r#"{ "url": null }"#; + + let full_url_de = serde_json::from_str::<OptSshUrl>(full_url) + .expect("failed to deserialize optional full url"); + let ssh_url_de = + serde_json::from_str::<OptSshUrl>(ssh_url).expect("failed to deserialize optional ssh url"); + let null_url_de = + serde_json::from_str::<OptSshUrl>(null_url).expect("failed to deserialize null url"); + + let expected = Some("ssh://git@codeberg.org/Cyborus/forgejo-api"); + assert_eq!(full_url_de.url.as_ref().map(|u| u.as_ref()), expected); + assert_eq!(ssh_url_de.url.as_ref().map(|u| u.as_ref()), expected); + assert!(null_url_de.url.is_none()); +} + impl From<structs::DefaultMergeStyle> for structs::MergePullRequestOptionDo { fn from(value: structs::DefaultMergeStyle) -> Self { match value { diff --git a/tests/ci_test.rs b/tests/ci_test.rs index d51a274..6eca774 100644 --- a/tests/ci_test.rs +++ b/tests/ci_test.rs @@ -430,9 +430,3 @@ async fn admin() { .await .expect("failed to delete hook"); } - -#[test] -fn ssh_url_deserialization() { - let data = include_str!("./repo_data.json"); - assert!(serde_json::from_str::<Repository>(data).is_ok()); -} diff --git a/tests/repo_data.json b/tests/repo_data.json deleted file mode 100644 index 81e94de..0000000 --- a/tests/repo_data.json +++ /dev/null @@ -1,91 +0,0 @@ -{ - "id": 160106, - "owner": { - "id": 94809, - "login": "Cyborus", - "login_name": "", - "full_name": "", - "email": "cyborus@noreply.codeberg.org", - "avatar_url": "https://codeberg.org/avatars/53e78f627539c6a0b96854028529779133724a5df2d2c229e5d0eb48aaa3d1fa", - "language": "", - "is_admin": false, - "last_login": "0001-01-01T00:00:00Z", - "created": "2023-04-30T00:54:15Z", - "restricted": false, - "active": false, - "prohibit_login": false, - "location": "", - "pronouns": "", - "website": "https://cyborus.xyz", - "description": "I host my own Forgejo instance at https://code.cartoon-aa.xyz/", - "visibility": "public", - "followers_count": 4, - "following_count": 4, - "starred_repos_count": 8, - "username": "Cyborus" - }, - "name": "forgejo-api", - "full_name": "Cyborus/forgejo-api", - "description": "Rust crate to interact with the Forgejo API", - "empty": false, - "private": false, - "fork": false, - "template": false, - "parent": null, - "mirror": false, - "size": 1481, - "language": "Rust", - "languages_url": "https://codeberg.org/api/v1/repos/Cyborus/forgejo-api/languages", - "html_url": "https://codeberg.org/Cyborus/forgejo-api", - "url": "https://codeberg.org/api/v1/repos/Cyborus/forgejo-api", - "link": "", - "ssh_url": "git@codeberg.org:Cyborus/forgejo-api.git", - "clone_url": "https://codeberg.org/Cyborus/forgejo-api.git", - "original_url": "", - "website": "", - "stars_count": 4, - "forks_count": 1, - "watchers_count": 2, - "open_issues_count": 2, - "open_pr_counter": 0, - "release_counter": 2, - "default_branch": "main", - "archived": false, - "created_at": "2023-11-09T17:42:18Z", - "updated_at": "2024-04-27T22:42:52Z", - "archived_at": "1970-01-01T00:00:00Z", - "permissions": { - "admin": false, - "push": false, - "pull": true - }, - "has_issues": true, - "internal_tracker": { - "enable_time_tracker": true, - "allow_only_contributors_to_track_time": true, - "enable_issue_dependencies": true - }, - "has_wiki": false, - "wiki_branch": "master", - "has_pull_requests": true, - "has_projects": true, - "has_releases": true, - "has_packages": false, - "has_actions": false, - "ignore_whitespace_conflicts": false, - "allow_merge_commits": true, - "allow_rebase": true, - "allow_rebase_explicit": true, - "allow_squash_merge": true, - "allow_fast_forward_only_merge": false, - "allow_rebase_update": true, - "default_delete_branch_after_merge": true, - "default_merge_style": "merge", - "default_allow_maintainer_edit": true, - "avatar_url": "", - "internal": false, - "mirror_interval": "", - "object_format_name": "sha1", - "mirror_updated": "0001-01-01T00:00:00Z", - "repo_transfer": null -} |