use super::*;
use crate::auth::InstallationId;
use crate::client::{ClientConfig, GitHubClient};
use crate::error::ApiError;
use wiremock::matchers::{header, method, path};
use wiremock::{Mock, MockServer, ResponseTemplate};
#[path = "test_helpers.rs"]
mod test_helpers;
use test_helpers::MockAuthProvider;
mod repository_operations_tests {
use super::*;
#[tokio::test]
async fn test_get_repository() {
let mock_server = MockServer::start().await;
let test_token = "ghs_test_token";
let repo_json = serde_json::json!({
"id": 1296269,
"name": "Hello-World",
"full_name": "octocat/Hello-World",
"owner": {
"login": "octocat",
"id": 1,
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"type": "User"
},
"description": "This your first repo!",
"private": false,
"default_branch": "main",
"html_url": "https://github.com/octocat/Hello-World",
"clone_url": "https://github.com/octocat/Hello-World.git",
"ssh_url": "git@github.com:octocat/Hello-World.git",
"created_at": "2011-01-26T19:01:12Z",
"updated_at": "2011-01-26T19:14:43Z"
});
Mock::given(method("GET"))
.and(path("/repos/octocat/Hello-World"))
.and(header("Authorization", format!("Bearer {}", test_token)))
.and(header("Accept", "application/vnd.github+json"))
.respond_with(ResponseTemplate::new(200).set_body_json(repo_json))
.mount(&mock_server)
.await;
let auth = MockAuthProvider::new_with_token(test_token);
let github_client = GitHubClient::builder(auth)
.config(ClientConfig::default().with_github_api_url(mock_server.uri()))
.build()
.unwrap();
let installation_id = InstallationId::new(12345);
let client = github_client
.installation_by_id(installation_id)
.await
.unwrap();
let result = client.repositories().get("octocat", "Hello-World").await;
assert!(result.is_ok());
let repo = result.unwrap();
assert_eq!(repo.id, 1296269);
assert_eq!(repo.name, "Hello-World");
assert_eq!(repo.full_name, "octocat/Hello-World");
assert_eq!(repo.owner.login, "octocat");
assert_eq!(repo.default_branch, "main");
assert_eq!(repo.description, Some("This your first repo!".to_string()));
}
#[tokio::test]
async fn test_get_repository_not_found() {
let mock_server = MockServer::start().await;
let test_token = "ghs_test_token";
Mock::given(method("GET"))
.and(path("/repos/octocat/NonExistent"))
.respond_with(ResponseTemplate::new(404).set_body_json(serde_json::json!({
"message": "Not Found",
"documentation_url": "https://docs.github.com/rest/repos/repos#get-a-repository"
})))
.mount(&mock_server)
.await;
let auth = MockAuthProvider::new_with_token(test_token);
let github_client = GitHubClient::builder(auth)
.config(ClientConfig::default().with_github_api_url(mock_server.uri()))
.build()
.unwrap();
let installation_id = InstallationId::new(12345);
let client = github_client
.installation_by_id(installation_id)
.await
.unwrap();
let result = client.repositories().get("octocat", "NonExistent").await;
assert!(result.is_err());
let err = result.unwrap_err();
assert!(matches!(err, ApiError::NotFound));
}
#[tokio::test]
async fn test_get_repository_permission_denied() {
let mock_server = MockServer::start().await;
let test_token = "ghs_test_token";
Mock::given(method("GET"))
.and(path("/repos/private-org/secret-repo"))
.respond_with(ResponseTemplate::new(403).set_body_json(serde_json::json!({
"message": "Resource not accessible by integration",
"documentation_url": "https://docs.github.com/rest/repos/repos#get-a-repository"
})))
.mount(&mock_server)
.await;
let auth = MockAuthProvider::new_with_token(test_token);
let github_client = GitHubClient::builder(auth)
.config(ClientConfig::default().with_github_api_url(mock_server.uri()))
.build()
.unwrap();
let installation_id = InstallationId::new(12345);
let client = github_client
.installation_by_id(installation_id)
.await
.unwrap();
let result = client
.repositories()
.get("private-org", "secret-repo")
.await;
assert!(result.is_err());
let err = result.unwrap_err();
assert!(matches!(err, ApiError::AuthorizationFailed));
}
}
mod branch_operations_tests {
use super::*;
#[tokio::test]
async fn test_list_branches() {
let mock_server = MockServer::start().await;
let test_token = "ghs_test_token";
let branches_json = serde_json::json!([
{
"name": "main",
"commit": {
"sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e",
"url": "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b"
},
"protected": true
},
{
"name": "development",
"commit": {
"sha": "7dcb09b5b57875f334f61aebed695e2e4193db5e",
"url": "https://api.github.com/repos/octocat/Hello-World/commits/7dcb09b"
},
"protected": false
}
]);
Mock::given(method("GET"))
.and(path("/repos/octocat/Hello-World/branches"))
.and(header("Authorization", format!("Bearer {}", test_token)))
.and(header("Accept", "application/vnd.github+json"))
.respond_with(ResponseTemplate::new(200).set_body_json(branches_json))
.mount(&mock_server)
.await;
let auth = MockAuthProvider::new_with_token(test_token);
let github_client = GitHubClient::builder(auth)
.config(ClientConfig::default().with_github_api_url(mock_server.uri()))
.build()
.unwrap();
let installation_id = InstallationId::new(12345);
let client = github_client
.installation_by_id(installation_id)
.await
.unwrap();
let result = client
.repositories()
.list_branches("octocat", "Hello-World")
.await;
assert!(result.is_ok());
let branches = result.unwrap();
assert_eq!(branches.len(), 2);
assert_eq!(branches[0].name, "main");
assert!(branches[0].protected);
assert_eq!(branches[1].name, "development");
assert!(!branches[1].protected);
}
#[tokio::test]
async fn test_get_branch() {
let mock_server = MockServer::start().await;
let test_token = "ghs_test_token";
let branch_json = serde_json::json!({
"name": "main",
"commit": {
"sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e",
"url": "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b"
},
"protected": true
});
Mock::given(method("GET"))
.and(path("/repos/octocat/Hello-World/branches/main"))
.and(header("Authorization", format!("Bearer {}", test_token)))
.and(header("Accept", "application/vnd.github+json"))
.respond_with(ResponseTemplate::new(200).set_body_json(branch_json))
.mount(&mock_server)
.await;
let auth = MockAuthProvider::new_with_token(test_token);
let github_client = GitHubClient::builder(auth)
.config(ClientConfig::default().with_github_api_url(mock_server.uri()))
.build()
.unwrap();
let installation_id = InstallationId::new(12345);
let client = github_client
.installation_by_id(installation_id)
.await
.unwrap();
let result = client
.repositories()
.get_branch("octocat", "Hello-World", "main")
.await;
assert!(result.is_ok());
let branch = result.unwrap();
assert_eq!(branch.name, "main");
assert_eq!(
branch.commit.sha,
"6dcb09b5b57875f334f61aebed695e2e4193db5e"
);
assert!(branch.protected);
}
#[tokio::test]
async fn test_get_branch_not_found() {
let mock_server = MockServer::start().await;
let test_token = "ghs_test_token";
Mock::given(method("GET"))
.and(path("/repos/octocat/Hello-World/branches/nonexistent"))
.respond_with(ResponseTemplate::new(404).set_body_json(serde_json::json!({
"message": "Branch not found"
})))
.mount(&mock_server)
.await;
let auth = MockAuthProvider::new_with_token(test_token);
let github_client = GitHubClient::builder(auth)
.config(ClientConfig::default().with_github_api_url(mock_server.uri()))
.build()
.unwrap();
let installation_id = InstallationId::new(12345);
let client = github_client
.installation_by_id(installation_id)
.await
.unwrap();
let result = client
.repositories()
.get_branch("octocat", "Hello-World", "nonexistent")
.await;
assert!(result.is_err());
let err = result.unwrap_err();
assert!(matches!(err, ApiError::NotFound));
}
}
mod git_ref_operations_tests {
use super::*;
#[tokio::test]
async fn test_get_git_ref() {
let mock_server = MockServer::start().await;
let test_token = "ghs_test_token";
let ref_json = serde_json::json!({
"ref": "refs/heads/feature-a",
"node_id": "MDM6UmVmcmVmcy9oZWFkcy9mZWF0dXJlLWE=",
"url": "https://api.github.com/repos/octocat/Hello-World/git/refs/heads/feature-a",
"object": {
"sha": "aa218f56b14c9653891f9e74264a383fa43fefbd",
"type": "commit",
"url": "https://api.github.com/repos/octocat/Hello-World/git/commits/aa218f5"
}
});
Mock::given(method("GET"))
.and(path("/repos/octocat/Hello-World/git/refs/heads/feature-a"))
.and(header("Authorization", format!("Bearer {}", test_token)))
.respond_with(ResponseTemplate::new(200).set_body_json(ref_json))
.mount(&mock_server)
.await;
let auth = MockAuthProvider::new_with_token(test_token);
let github_client = GitHubClient::builder(auth)
.config(ClientConfig::default().with_github_api_url(mock_server.uri()))
.build()
.unwrap();
let installation_id = InstallationId::new(12345);
let client = github_client
.installation_by_id(installation_id)
.await
.unwrap();
let result = client
.repositories()
.get_ref("octocat", "Hello-World", "heads/feature-a")
.await;
assert!(result.is_ok());
let git_ref = result.unwrap();
assert_eq!(git_ref.ref_name, "refs/heads/feature-a");
assert_eq!(
git_ref.object.sha,
"aa218f56b14c9653891f9e74264a383fa43fefbd"
);
}
#[tokio::test]
async fn test_create_git_ref() {
let mock_server = MockServer::start().await;
let test_token = "ghs_test_token";
let created_ref_json = serde_json::json!({
"ref": "refs/heads/new-feature",
"node_id": "MDM6UmVmcmVmcy9oZWFkcy9uZXctZmVhdHVyZQ==",
"url": "https://api.github.com/repos/octocat/Hello-World/git/refs/heads/new-feature",
"object": {
"sha": "aa218f56b14c9653891f9e74264a383fa43fefbd",
"type": "commit",
"url": "https://api.github.com/repos/octocat/Hello-World/git/commits/aa218f5"
}
});
Mock::given(method("POST"))
.and(path("/repos/octocat/Hello-World/git/refs"))
.and(header("Authorization", format!("Bearer {}", test_token)))
.respond_with(ResponseTemplate::new(201).set_body_json(created_ref_json))
.mount(&mock_server)
.await;
let auth = MockAuthProvider::new_with_token(test_token);
let github_client = GitHubClient::builder(auth)
.config(ClientConfig::default().with_github_api_url(mock_server.uri()))
.build()
.unwrap();
let installation_id = InstallationId::new(12345);
let client = github_client
.installation_by_id(installation_id)
.await
.unwrap();
let result = client
.repositories()
.create_ref(
"octocat",
"Hello-World",
"refs/heads/new-feature",
"aa218f56b14c9653891f9e74264a383fa43fefbd",
)
.await;
assert!(result.is_ok());
let git_ref = result.unwrap();
assert_eq!(git_ref.ref_name, "refs/heads/new-feature");
}
#[tokio::test]
async fn test_create_git_ref_already_exists() {
let mock_server = MockServer::start().await;
let test_token = "ghs_test_token";
Mock::given(method("POST"))
.and(path("/repos/octocat/Hello-World/git/refs"))
.respond_with(ResponseTemplate::new(422).set_body_json(serde_json::json!({
"message": "Reference already exists"
})))
.mount(&mock_server)
.await;
let auth = MockAuthProvider::new_with_token(test_token);
let github_client = GitHubClient::builder(auth)
.config(ClientConfig::default().with_github_api_url(mock_server.uri()))
.build()
.unwrap();
let installation_id = InstallationId::new(12345);
let client = github_client
.installation_by_id(installation_id)
.await
.unwrap();
let result = client
.repositories()
.create_ref(
"octocat",
"Hello-World",
"refs/heads/main",
"aa218f56b14c9653891f9e74264a383fa43fefbd",
)
.await;
assert!(result.is_err());
let err = result.unwrap_err();
assert!(matches!(err, ApiError::InvalidRequest { .. }));
}
#[tokio::test]
async fn test_update_git_ref_fast_forward() {
let mock_server = MockServer::start().await;
let test_token = "ghs_test_token";
let updated_ref_json = serde_json::json!({
"ref": "refs/heads/feature-a",
"node_id": "MDM6UmVmcmVmcy9oZWFkcy9mZWF0dXJlLWE=",
"url": "https://api.github.com/repos/octocat/Hello-World/git/refs/heads/feature-a",
"object": {
"sha": "bb218f56b14c9653891f9e74264a383fa43fefbd",
"type": "commit",
"url": "https://api.github.com/repos/octocat/Hello-World/git/commits/bb218f5"
}
});
Mock::given(method("PATCH"))
.and(path("/repos/octocat/Hello-World/git/refs/heads/feature-a"))
.and(header("Authorization", format!("Bearer {}", test_token)))
.respond_with(ResponseTemplate::new(200).set_body_json(updated_ref_json))
.mount(&mock_server)
.await;
let auth = MockAuthProvider::new_with_token(test_token);
let github_client = GitHubClient::builder(auth)
.config(ClientConfig::default().with_github_api_url(mock_server.uri()))
.build()
.unwrap();
let installation_id = InstallationId::new(12345);
let client = github_client
.installation_by_id(installation_id)
.await
.unwrap();
let result = client
.repositories()
.update_ref(
"octocat",
"Hello-World",
"heads/feature-a",
"bb218f56b14c9653891f9e74264a383fa43fefbd",
false,
)
.await;
assert!(result.is_ok());
let git_ref = result.unwrap();
assert_eq!(
git_ref.object.sha,
"bb218f56b14c9653891f9e74264a383fa43fefbd"
);
}
#[tokio::test]
async fn test_update_git_ref_force() {
let mock_server = MockServer::start().await;
let test_token = "ghs_test_token";
let updated_ref_json = serde_json::json!({
"ref": "refs/heads/feature-a",
"node_id": "MDM6UmVmcmVmcy9oZWFkcy9mZWF0dXJlLWE=",
"url": "https://api.github.com/repos/octocat/Hello-World/git/refs/heads/feature-a",
"object": {
"sha": "cc218f56b14c9653891f9e74264a383fa43fefbd",
"type": "commit",
"url": "https://api.github.com/repos/octocat/Hello-World/git/commits/cc218f5"
}
});
Mock::given(method("PATCH"))
.and(path("/repos/octocat/Hello-World/git/refs/heads/feature-a"))
.respond_with(ResponseTemplate::new(200).set_body_json(updated_ref_json))
.mount(&mock_server)
.await;
let auth = MockAuthProvider::new_with_token(test_token);
let github_client = GitHubClient::builder(auth)
.config(ClientConfig::default().with_github_api_url(mock_server.uri()))
.build()
.unwrap();
let installation_id = InstallationId::new(12345);
let client = github_client
.installation_by_id(installation_id)
.await
.unwrap();
let result = client
.repositories()
.update_ref(
"octocat",
"Hello-World",
"heads/feature-a",
"cc218f56b14c9653891f9e74264a383fa43fefbd",
true,
)
.await;
assert!(result.is_ok());
let git_ref = result.unwrap();
assert_eq!(
git_ref.object.sha,
"cc218f56b14c9653891f9e74264a383fa43fefbd"
);
}
#[tokio::test]
async fn test_delete_git_ref() {
let mock_server = MockServer::start().await;
let test_token = "ghs_test_token";
Mock::given(method("DELETE"))
.and(path("/repos/octocat/Hello-World/git/refs/heads/feature-a"))
.and(header("Authorization", format!("Bearer {}", test_token)))
.respond_with(ResponseTemplate::new(204))
.mount(&mock_server)
.await;
let auth = MockAuthProvider::new_with_token(test_token);
let github_client = GitHubClient::builder(auth)
.config(ClientConfig::default().with_github_api_url(mock_server.uri()))
.build()
.unwrap();
let installation_id = InstallationId::new(12345);
let client = github_client
.installation_by_id(installation_id)
.await
.unwrap();
let result = client
.repositories()
.delete_ref("octocat", "Hello-World", "heads/feature-a")
.await;
assert!(result.is_ok());
}
#[tokio::test]
async fn test_delete_git_ref_not_found() {
let mock_server = MockServer::start().await;
let test_token = "ghs_test_token";
Mock::given(method("DELETE"))
.and(path(
"/repos/octocat/Hello-World/git/refs/heads/nonexistent",
))
.respond_with(ResponseTemplate::new(404).set_body_json(serde_json::json!({
"message": "Not Found"
})))
.mount(&mock_server)
.await;
let auth = MockAuthProvider::new_with_token(test_token);
let github_client = GitHubClient::builder(auth)
.config(ClientConfig::default().with_github_api_url(mock_server.uri()))
.build()
.unwrap();
let installation_id = InstallationId::new(12345);
let client = github_client
.installation_by_id(installation_id)
.await
.unwrap();
let result = client
.repositories()
.delete_ref("octocat", "Hello-World", "heads/nonexistent")
.await;
assert!(result.is_err());
let err = result.unwrap_err();
assert!(matches!(err, ApiError::NotFound));
}
}
mod tag_operations_tests {
use super::*;
#[tokio::test]
async fn test_list_tags() {
let mock_server = MockServer::start().await;
let test_token = "ghs_test_token";
let tags_json = serde_json::json!([
{
"name": "v1.0.0",
"commit": {
"sha": "c5b97d5ae6c19d5c5df71a34c7fbeeda2479ccbc",
"url": "https://api.github.com/repos/octocat/Hello-World/commits/c5b97d5"
},
"zipball_url": "https://github.com/octocat/Hello-World/zipball/v1.0.0",
"tarball_url": "https://github.com/octocat/Hello-World/tarball/v1.0.0"
},
{
"name": "v0.1.0",
"commit": {
"sha": "b5b97d5ae6c19d5c5df71a34c7fbeeda2479ccbc",
"url": "https://api.github.com/repos/octocat/Hello-World/commits/b5b97d5"
},
"zipball_url": "https://github.com/octocat/Hello-World/zipball/v0.1.0",
"tarball_url": "https://github.com/octocat/Hello-World/tarball/v0.1.0"
}
]);
Mock::given(method("GET"))
.and(path("/repos/octocat/Hello-World/tags"))
.and(header("Authorization", format!("Bearer {}", test_token)))
.and(header("Accept", "application/vnd.github+json"))
.respond_with(ResponseTemplate::new(200).set_body_json(tags_json))
.mount(&mock_server)
.await;
let auth = MockAuthProvider::new_with_token(test_token);
let github_client = GitHubClient::builder(auth)
.config(ClientConfig::default().with_github_api_url(mock_server.uri()))
.build()
.unwrap();
let installation_id = InstallationId::new(12345);
let client = github_client
.installation_by_id(installation_id)
.await
.unwrap();
let result = client
.repositories()
.list_tags("octocat", "Hello-World")
.await;
assert!(result.is_ok());
let tags = result.unwrap();
assert_eq!(tags.len(), 2);
assert_eq!(tags[0].name, "v1.0.0");
assert_eq!(tags[1].name, "v0.1.0");
assert_eq!(
tags[0].commit.sha,
"c5b97d5ae6c19d5c5df71a34c7fbeeda2479ccbc"
);
}
#[tokio::test]
async fn test_list_tags_empty_repo() {
let mock_server = MockServer::start().await;
let test_token = "ghs_test_token";
Mock::given(method("GET"))
.and(path("/repos/octocat/Empty-Repo/tags"))
.and(header("Authorization", format!("Bearer {}", test_token)))
.respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!([])))
.mount(&mock_server)
.await;
let auth = MockAuthProvider::new_with_token(test_token);
let github_client = GitHubClient::builder(auth)
.config(ClientConfig::default().with_github_api_url(mock_server.uri()))
.build()
.unwrap();
let installation_id = InstallationId::new(12345);
let client = github_client
.installation_by_id(installation_id)
.await
.unwrap();
let result = client
.repositories()
.list_tags("octocat", "Empty-Repo")
.await;
assert!(result.is_ok());
let tags = result.unwrap();
assert_eq!(tags.len(), 0);
}
}
mod type_serialization_tests {
use super::*;
#[test]
fn test_repository_deserialization() {
let json = r#"{
"id": 1296269,
"name": "Hello-World",
"full_name": "octocat/Hello-World",
"owner": {
"login": "octocat",
"id": 1,
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"type": "User"
},
"description": "This your first repo!",
"private": false,
"default_branch": "main",
"html_url": "https://github.com/octocat/Hello-World",
"clone_url": "https://github.com/octocat/Hello-World.git",
"ssh_url": "git@github.com:octocat/Hello-World.git",
"created_at": "2011-01-26T19:01:12Z",
"updated_at": "2011-01-26T19:14:43Z"
}"#;
let repo: Repository = serde_json::from_str(json).unwrap();
assert_eq!(repo.id, 1296269);
assert_eq!(repo.name, "Hello-World");
assert_eq!(repo.full_name, "octocat/Hello-World");
assert_eq!(repo.owner.login, "octocat");
assert_eq!(repo.owner.id, 1);
assert_eq!(repo.description, Some("This your first repo!".to_string()));
assert!(!repo.private);
assert_eq!(repo.default_branch, "main");
}
#[test]
fn test_repository_deserialization_without_description() {
let json = r#"{
"id": 1296269,
"name": "Hello-World",
"full_name": "octocat/Hello-World",
"owner": {
"login": "octocat",
"id": 1,
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"type": "User"
},
"description": null,
"private": false,
"default_branch": "main",
"html_url": "https://github.com/octocat/Hello-World",
"clone_url": "https://github.com/octocat/Hello-World.git",
"ssh_url": "git@github.com:octocat/Hello-World.git",
"created_at": "2011-01-26T19:01:12Z",
"updated_at": "2011-01-26T19:14:43Z"
}"#;
let repo: Repository = serde_json::from_str(json).unwrap();
assert_eq!(repo.description, None);
}
#[test]
fn test_branch_deserialization() {
let json = r#"{
"name": "main",
"commit": {
"sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e",
"url": "https://api.github.com/repos/octocat/Hello-World/commits/6dcb09b"
},
"protected": true
}"#;
let branch: Branch = serde_json::from_str(json).unwrap();
assert_eq!(branch.name, "main");
assert_eq!(
branch.commit.sha,
"6dcb09b5b57875f334f61aebed695e2e4193db5e"
);
assert!(branch.protected);
}
#[test]
fn test_git_ref_deserialization() {
let json = r#"{
"ref": "refs/heads/feature-a",
"node_id": "MDM6UmVmcmVmcy9oZWFkcy9mZWF0dXJlLWE=",
"url": "https://api.github.com/repos/octocat/Hello-World/git/refs/heads/feature-a",
"object": {
"sha": "aa218f56b14c9653891f9e74264a383fa43fefbd",
"type": "commit",
"url": "https://api.github.com/repos/octocat/Hello-World/git/commits/aa218f5"
}
}"#;
let git_ref: GitRef = serde_json::from_str(json).unwrap();
assert_eq!(git_ref.ref_name, "refs/heads/feature-a");
assert_eq!(git_ref.node_id, "MDM6UmVmcmVmcy9oZWFkcy9mZWF0dXJlLWE=");
assert_eq!(
git_ref.object.sha,
"aa218f56b14c9653891f9e74264a383fa43fefbd"
);
assert!(matches!(git_ref.object.object_type, GitObjectType::Commit));
}
#[test]
fn test_tag_deserialization() {
let json = r#"{
"name": "v1.0.0",
"commit": {
"sha": "c5b97d5ae6c19d5c5df71a34c7fbeeda2479ccbc",
"url": "https://api.github.com/repos/octocat/Hello-World/commits/c5b97d5"
},
"zipball_url": "https://github.com/octocat/Hello-World/zipball/v1.0.0",
"tarball_url": "https://github.com/octocat/Hello-World/tarball/v1.0.0"
}"#;
let tag: Tag = serde_json::from_str(json).unwrap();
assert_eq!(tag.name, "v1.0.0");
assert_eq!(tag.commit.sha, "c5b97d5ae6c19d5c5df71a34c7fbeeda2479ccbc");
assert!(tag.zipball_url.contains("zipball/v1.0.0"));
assert!(tag.tarball_url.contains("tarball/v1.0.0"));
}
#[test]
fn test_git_object_type_serialization() {
let commit_type = GitObjectType::Commit;
let tree_type = GitObjectType::Tree;
let blob_type = GitObjectType::Blob;
let tag_type = GitObjectType::Tag;
let commit_json = serde_json::to_string(&commit_type).unwrap();
let tree_json = serde_json::to_string(&tree_type).unwrap();
let blob_json = serde_json::to_string(&blob_type).unwrap();
let tag_json = serde_json::to_string(&tag_type).unwrap();
assert_eq!(commit_json, r#""commit""#);
assert_eq!(tree_json, r#""tree""#);
assert_eq!(blob_json, r#""blob""#);
assert_eq!(tag_json, r#""tag""#);
}
#[test]
fn test_owner_type_serialization() {
let user_type = OwnerType::User;
let org_type = OwnerType::Organization;
let user_json = serde_json::to_string(&user_type).unwrap();
let org_json = serde_json::to_string(&org_type).unwrap();
assert_eq!(user_json, r#""User""#);
assert_eq!(org_json, r#""Organization""#);
}
}