[+] End-to-end testing

This commit is contained in:
2026-05-08 15:32:33 +00:00
parent ac2f2559c1
commit 74e4a6eff4
15 changed files with 2405 additions and 62 deletions
+47
View File
@@ -1,4 +1,5 @@
use super::*;
use crate::config::SyncVisibility;
use crate::config::{
ConflictResolutionStrategy, EndpointConfig, MirrorConfig, NamespaceKind, SiteConfig,
TokenConfig, Visibility,
@@ -109,6 +110,9 @@ fn matches_jobs_by_provider_and_namespace() {
endpoint("github", NamespaceKind::User, "alice"),
endpoint("gitea", NamespaceKind::User, "azalea"),
],
sync_visibility: SyncVisibility::All,
repo_whitelist: Vec::new(),
repo_blacklist: Vec::new(),
create_missing: true,
visibility: Visibility::Private,
allow_force: false,
@@ -129,6 +133,41 @@ fn matches_jobs_by_provider_and_namespace() {
assert_eq!(jobs[0].repo, "repo");
}
#[test]
fn matching_jobs_respects_repo_name_filters() {
let mut mirror = MirrorConfig {
name: "sync-1".to_string(),
endpoints: vec![endpoint("github", NamespaceKind::User, "alice")],
sync_visibility: SyncVisibility::All,
repo_whitelist: vec!["^important-".to_string()],
repo_blacklist: vec!["-archive$".to_string()],
create_missing: true,
visibility: Visibility::Private,
allow_force: false,
conflict_resolution: ConflictResolutionStrategy::Fail,
};
let config = Config {
sites: vec![site("github", ProviderKind::Github)],
mirrors: vec![mirror.clone()],
webhook: None,
};
assert_eq!(
matching_jobs(&config, &webhook_event("important-api")).len(),
1
);
assert!(matching_jobs(&config, &webhook_event("important-archive")).is_empty());
assert!(matching_jobs(&config, &webhook_event("random")).is_empty());
mirror.repo_whitelist.clear();
let config = Config {
sites: vec![site("github", ProviderKind::Github)],
mirrors: vec![mirror],
webhook: None,
};
assert_eq!(matching_jobs(&config, &webhook_event("random")).len(), 1);
}
#[test]
fn webhook_state_persists_installations() {
let temp = tempfile::TempDir::new().unwrap();
@@ -330,6 +369,14 @@ fn site(name: &str, provider: ProviderKind) -> SiteConfig {
}
}
fn webhook_event(repo: &str) -> WebhookEvent {
WebhookEvent {
provider: Some(ProviderKind::Github),
repo: repo.to_string(),
namespace: Some("alice".to_string()),
}
}
fn endpoint(site: &str, kind: NamespaceKind, namespace: &str) -> EndpointConfig {
EndpointConfig {
site: site.to_string(),