diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-10 16:59:09 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-10 16:59:09 +0000 |
| commit | cbed48d5a20b646a5bcc23e907d6163a3a8d36c5 (patch) | |
| tree | d01b4e49e5ffadc8f12f00f44e015531fa2deadb /tests/common/sync_helpers.rs | |
| parent | a958a55196537598492c3935ab46e3b6e23ee44b (diff) | |
refactor(tests): extract shared create_repo_announcement helper
Diffstat (limited to 'tests/common/sync_helpers.rs')
| -rw-r--r-- | tests/common/sync_helpers.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/common/sync_helpers.rs b/tests/common/sync_helpers.rs index d9be332..be8f421 100644 --- a/tests/common/sync_helpers.rs +++ b/tests/common/sync_helpers.rs | |||
| @@ -325,6 +325,46 @@ pub fn build_layer3_quote_with_q_tag( | |||
| 325 | } | 325 | } |
| 326 | 326 | ||
| 327 | // ============================================================================ | 327 | // ============================================================================ |
| 328 | // Repository Announcement Helper | ||
| 329 | // ============================================================================ | ||
| 330 | |||
| 331 | /// Create a valid repository announcement event for testing sync. | ||
| 332 | /// | ||
| 333 | /// This creates a kind 30617 event with required clone and relays tags. | ||
| 334 | /// The event lists all provided domains so it will be accepted by each | ||
| 335 | /// relay's write policy. | ||
| 336 | /// | ||
| 337 | /// # Arguments | ||
| 338 | /// * `keys` - Keys for signing | ||
| 339 | /// * `domains` - Slice of domain strings (e.g., "127.0.0.1:8080") | ||
| 340 | /// * `identifier` - Repository identifier (d-tag) | ||
| 341 | /// | ||
| 342 | /// # Returns | ||
| 343 | /// A signed repository announcement event ready to send. | ||
| 344 | pub fn create_repo_announcement(keys: &Keys, domains: &[&str], identifier: &str) -> Event { | ||
| 345 | // Build clone URLs for all domains (with .git suffix) | ||
| 346 | let clone_urls: Vec<String> = domains | ||
| 347 | .iter() | ||
| 348 | .map(|d| format!("http://{}/{}.git", d, identifier)) | ||
| 349 | .collect(); | ||
| 350 | |||
| 351 | // Build relay URLs for all domains | ||
| 352 | let relay_urls: Vec<String> = domains.iter().map(|d| format!("ws://{}", d)).collect(); | ||
| 353 | |||
| 354 | // Build tags for repository announcement | ||
| 355 | let tags = vec![ | ||
| 356 | Tag::identifier(identifier), | ||
| 357 | Tag::custom(TagKind::custom("clone"), clone_urls), | ||
| 358 | Tag::custom(TagKind::custom("relays"), relay_urls), | ||
| 359 | ]; | ||
| 360 | |||
| 361 | EventBuilder::new(Kind::Custom(KIND_REPOSITORY_STATE), "Repository state") | ||
| 362 | .tags(tags) | ||
| 363 | .sign_with_keys(keys) | ||
| 364 | .expect("Failed to sign repo announcement") | ||
| 365 | } | ||
| 366 | |||
| 367 | // ============================================================================ | ||
| 328 | // Assertion Helpers | 368 | // Assertion Helpers |
| 329 | // ============================================================================ | 369 | // ============================================================================ |
| 330 | 370 | ||