diff options
Diffstat (limited to 'tests/purgatory.rs')
| -rw-r--r-- | tests/purgatory.rs | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/tests/purgatory.rs b/tests/purgatory.rs new file mode 100644 index 0000000..73f85ca --- /dev/null +++ b/tests/purgatory.rs | |||
| @@ -0,0 +1,89 @@ | |||
| 1 | //! Purgatory Integration Tests | ||
| 2 | //! | ||
| 3 | //! Tests ngit-grasp relay's implementation of GRASP-01 purgatory behavior. | ||
| 4 | //! Uses grasp-audit library to avoid code duplication. | ||
| 5 | //! | ||
| 6 | //! # Test Strategy | ||
| 7 | //! | ||
| 8 | //! - Each test runs in complete isolation with its own fresh relay instance | ||
| 9 | //! - Uses macro to eliminate boilerplate while maintaining test isolation | ||
| 10 | //! - Calls individual test methods from grasp-audit for minimal duplication | ||
| 11 | //! - Automatic cleanup via TestRelay fixture (removes container and temp dirs) | ||
| 12 | //! | ||
| 13 | //! # Running Tests | ||
| 14 | //! | ||
| 15 | //! ```bash | ||
| 16 | //! # Run all purgatory tests | ||
| 17 | //! cargo test --test purgatory | ||
| 18 | //! | ||
| 19 | //! # Run specific test | ||
| 20 | //! cargo test --test purgatory test_state_event_not_served_before_git_data | ||
| 21 | //! | ||
| 22 | //! # With output | ||
| 23 | //! cargo test --test purgatory -- --nocapture | ||
| 24 | //! ``` | ||
| 25 | |||
| 26 | mod common; | ||
| 27 | |||
| 28 | use common::TestRelay; | ||
| 29 | use grasp_audit::specs::grasp01::PurgatoryTests; | ||
| 30 | use grasp_audit::{AuditClient, AuditConfig}; | ||
| 31 | |||
| 32 | /// Macro to generate isolated integration tests for purgatory | ||
| 33 | /// | ||
| 34 | /// Each test runs with its own fresh relay instance to ensure complete isolation. | ||
| 35 | /// This eliminates issues with leftover repositories and ensures clean state. | ||
| 36 | macro_rules! isolated_purgatory_test { | ||
| 37 | ($test_name:ident) => { | ||
| 38 | #[tokio::test] | ||
| 39 | async fn $test_name() { | ||
| 40 | let relay = TestRelay::start().await; | ||
| 41 | let config = AuditConfig::isolated(); | ||
| 42 | let client = AuditClient::new(relay.url(), config) | ||
| 43 | .await | ||
| 44 | .expect("Failed to create audit client"); | ||
| 45 | |||
| 46 | let result = PurgatoryTests::$test_name(&client).await; | ||
| 47 | |||
| 48 | relay.stop().await; | ||
| 49 | |||
| 50 | assert!( | ||
| 51 | result.passed, | ||
| 52 | "{} failed: {}", | ||
| 53 | stringify!($test_name), | ||
| 54 | result.error.as_deref().unwrap_or("unknown error") | ||
| 55 | ); | ||
| 56 | } | ||
| 57 | }; | ||
| 58 | } | ||
| 59 | |||
| 60 | // ============================================================ | ||
| 61 | // Announcement Purgatory Tests | ||
| 62 | // ============================================================ | ||
| 63 | |||
| 64 | isolated_purgatory_test!(test_announcement_not_served_before_git_data); | ||
| 65 | isolated_purgatory_test!(test_announcement_served_after_git_push); | ||
| 66 | isolated_purgatory_test!(test_bare_repo_exists_for_purgatory_announcement); | ||
| 67 | isolated_purgatory_test!(test_state_event_accepted_for_purgatory_announcement); | ||
| 68 | |||
| 69 | // ============================================================ | ||
| 70 | // Deletion Event Tests (NIP-09) | ||
| 71 | // ============================================================ | ||
| 72 | |||
| 73 | isolated_purgatory_test!(test_deletion_by_event_id_removes_purgatory_state_event); | ||
| 74 | isolated_purgatory_test!(test_deletion_by_coordinate_removes_purgatory_state_event); | ||
| 75 | |||
| 76 | // ============================================================ | ||
| 77 | // State Event Purgatory Tests (already implemented) | ||
| 78 | // ============================================================ | ||
| 79 | |||
| 80 | isolated_purgatory_test!(test_state_event_not_served_before_git_data); | ||
| 81 | isolated_purgatory_test!(test_state_event_served_after_git_push); | ||
| 82 | |||
| 83 | // ============================================================ | ||
| 84 | // PR Purgatory Tests | ||
| 85 | // ============================================================ | ||
| 86 | |||
| 87 | isolated_purgatory_test!(test_pr_event_accepted_into_purgatory_and_isnt_served); | ||
| 88 | isolated_purgatory_test!(test_pr_event_in_purgatory_git_push_accepted); | ||
| 89 | isolated_purgatory_test!(test_pr_event_served_after_git_push); | ||