use nyl::git::{CredentialProvider, GitCredential};
use std::collections::HashMap;
#[test]
fn test_credential_provider_creation() {
let provider = CredentialProvider::new();
assert!(provider.get_credential("https://github.com/org/repo").is_none());
}
#[test]
fn test_credential_provider_with_ssh_key() {
let mut credentials = HashMap::new();
credentials.insert(
"https://github.com/org/repo".to_string(),
GitCredential::SshKey {
username: "git".to_string(),
private_key: "test-key".to_string(),
public_key: None,
passphrase: None,
},
);
let provider = CredentialProvider::with_credentials(credentials);
assert!(provider.get_credential("https://github.com/org/repo").is_some());
assert!(provider.get_credential("https://github.com/org/other-repo").is_some());
assert!(provider.get_credential("https://gitlab.com/org/repo").is_none());
}
#[test]
fn test_credential_provider_with_https_token() {
let mut credentials = HashMap::new();
credentials.insert(
"https://github.com/org/repo".to_string(),
GitCredential::HttpsToken {
username: "user".to_string(),
token: "ghp_token123".to_string(),
},
);
let provider = CredentialProvider::with_credentials(credentials);
assert!(provider.get_credential("https://github.com/org/repo").is_some());
}
#[test]
fn test_credential_provider_with_ssh_agent() {
let mut credentials = HashMap::new();
credentials.insert(
"git@github.com:org/repo".to_string(),
GitCredential::SshAgent {
username: "git".to_string(),
},
);
let provider = CredentialProvider::with_credentials(credentials);
assert!(provider.get_credential("git@github.com:org/repo").is_some());
}
#[test]
fn test_credential_provider_url_matching() {
let mut credentials = HashMap::new();
credentials.insert(
"https://github.com/org/repo.git".to_string(),
GitCredential::SshAgent {
username: "git".to_string(),
},
);
let provider = CredentialProvider::with_credentials(credentials);
assert!(provider.get_credential("https://github.com/org/repo").is_some());
assert!(provider.get_credential("https://github.com/org/repo.git").is_some());
}
#[test]
fn test_credential_provider_add_credential() {
let provider = CredentialProvider::new();
provider.add_credential(
"https://github.com/org/repo".to_string(),
GitCredential::SshAgent {
username: "git".to_string(),
},
);
assert!(provider.get_credential("https://github.com/org/repo").is_some());
}
#[test]
fn test_build_callbacks() {
let mut credentials = HashMap::new();
credentials.insert(
"https://github.com/org/repo".to_string(),
GitCredential::SshAgent {
username: "git".to_string(),
},
);
let provider = CredentialProvider::with_credentials(credentials);
let _callbacks = provider.build_callbacks("https://github.com/org/repo");
}