upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/tests/purgatory.rs
blob: efc28c9d8716d773f7c00986e6faed50bb066b81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//! Purgatory Integration Tests
//!
//! Tests ngit-grasp relay's implementation of GRASP-01 purgatory behavior.
//! Uses grasp-audit library to avoid code duplication.
//!
//! # Test Strategy
//!
//! - Each test runs in complete isolation with its own fresh relay instance
//! - Uses macro to eliminate boilerplate while maintaining test isolation
//! - Calls individual test methods from grasp-audit for minimal duplication
//! - Automatic cleanup via TestRelay fixture (removes container and temp dirs)
//!
//! # Running Tests
//!
//! ```bash
//! # Run all purgatory tests
//! cargo test --test purgatory
//!
//! # Run specific test
//! cargo test --test purgatory test_state_event_not_served_before_git_data
//!
//! # With output
//! cargo test --test purgatory -- --nocapture
//! ```

mod common;

use common::TestRelay;
use grasp_audit::specs::grasp01::PurgatoryTests;
use grasp_audit::{AuditClient, AuditConfig};

/// Macro to generate isolated integration tests for purgatory
///
/// Each test runs with its own fresh relay instance to ensure complete isolation.
/// This eliminates issues with leftover repositories and ensures clean state.
macro_rules! isolated_purgatory_test {
    ($test_name:ident) => {
        #[tokio::test]
        async fn $test_name() {
            let relay = TestRelay::start().await;
            let config = AuditConfig::isolated();
            let client = AuditClient::new(relay.url(), config)
                .await
                .expect("Failed to create audit client");

            let result = PurgatoryTests::$test_name(&client).await;

            relay.stop().await;

            assert!(
                result.passed,
                "{} failed: {}",
                stringify!($test_name),
                result.error.as_deref().unwrap_or("unknown error")
            );
        }
    };
}

// ============================================================
// Announcement Purgatory Tests
// ============================================================

isolated_purgatory_test!(test_announcement_not_served_before_git_data);
isolated_purgatory_test!(test_announcement_served_after_git_push);
isolated_purgatory_test!(test_bare_repo_exists_for_purgatory_announcement);
isolated_purgatory_test!(test_state_event_accepted_for_purgatory_announcement);

// ============================================================
// State Event Purgatory Tests (already implemented)
// ============================================================

isolated_purgatory_test!(test_state_event_not_served_before_git_data);
isolated_purgatory_test!(test_state_event_served_after_git_push);

// ============================================================
// PR Purgatory Tests
// ============================================================

isolated_purgatory_test!(test_pr_event_accepted_into_purgatory_and_isnt_served);
isolated_purgatory_test!(test_pr_event_in_purgatory_git_push_accepted);
isolated_purgatory_test!(test_pr_event_served_after_git_push);