Forge-core integration tests build as one binary
Browse files at this commitd9b0f879d1df48727b20bf4edc4c0cd4ab02bdb5Parent: 9abc059- refactor
- forge-core integration tests build as one binary
7 changed files +33 -29
- crates/forge-core/tests/audit_store.rs → crates/forge-core/tests/integration/audit_store.rs +6 -9
- crates/forge-core/tests/integration/common.rs +13 -0
- crates/forge-core/tests/integration/main.rs +9 -0
- crates/forge-core/tests/read_pool.rs → crates/forge-core/tests/integration/read_pool.rs +0 -0
- crates/forge-core/tests/stars_store.rs → crates/forge-core/tests/integration/stars_store.rs +2 -10
- crates/forge-core/tests/store_basic.rs → crates/forge-core/tests/integration/store_basic.rs +2 -9
- docs/backlog.md +1 -1
crates/forge-core/tests/audit_store.rs → crates/forge-core/tests/integration/audit_store.rsrenamed+6 -9
| @@ -1,14 +1,11 @@ | ||
| 1 | 1 | //! Store tests for the audit log: record, filtered listing, cursor paging and retention purge. |
| 2 | 2 | |
| 3 | -use std::path::Path; | |
| 4 | 3 | use std::time::Duration; |
| 5 | 4 | |
| 6 | 5 | use forge_core::time::stamp_ago; |
| 7 | 6 | use forge_core::{AuditAction, AuditCursor, AuditEntry, AuditFilter, Store, User}; |
| 8 | 7 | |
| 9 | -async fn open_store(path: &Path) -> Store { | |
| 10 | - Store::open(path).await.expect("open store") | |
| 11 | -} | |
| 8 | +use crate::common::{db_path, open_store}; | |
| 12 | 9 | |
| 13 | 10 | async fn user(store: &Store, name: &str) -> User { |
| 14 | 11 | store.create_user(name, None, "h", false).await.unwrap() |
| @@ -24,7 +21,7 @@ fn entry(action: AuditAction, actor: Option<&User>) -> AuditEntry { | ||
| 24 | 21 | #[tokio::test] |
| 25 | 22 | async fn record_and_list_round_trip_with_all_fields() { |
| 26 | 23 | let dir = tempfile::tempdir().unwrap(); |
| 27 | - let store = open_store(&dir.path().join("forge.db")).await; | |
| 24 | + let store = open_store(&db_path(&dir)).await; | |
| 28 | 25 | let tahinli = user(&store, "tahinli").await; |
| 29 | 26 | let mut e = entry(AuditAction::RepoRenamed, Some(&tahinli)); |
| 30 | 27 | e.target_kind = "repo".into(); |
| @@ -44,7 +41,7 @@ async fn record_and_list_round_trip_with_all_fields() { | ||
| 44 | 41 | #[tokio::test] |
| 45 | 42 | async fn anonymous_entries_store_a_null_actor() { |
| 46 | 43 | let dir = tempfile::tempdir().unwrap(); |
| 47 | - let store = open_store(&dir.path().join("forge.db")).await; | |
| 44 | + let store = open_store(&db_path(&dir)).await; | |
| 48 | 45 | let mut e = AuditEntry::new(AuditAction::LoginFailed); |
| 49 | 46 | e.target_name = "mallory".into(); |
| 50 | 47 | store.record_audit(&e).await.unwrap(); |
| @@ -59,7 +56,7 @@ async fn anonymous_entries_store_a_null_actor() { | ||
| 59 | 56 | #[tokio::test] |
| 60 | 57 | async fn filters_by_actor_action_target_and_involved_user() { |
| 61 | 58 | let dir = tempfile::tempdir().unwrap(); |
| 62 | - let store = open_store(&dir.path().join("forge.db")).await; | |
| 59 | + let store = open_store(&db_path(&dir)).await; | |
| 63 | 60 | let tahinli = user(&store, "tahinli").await; |
| 64 | 61 | let bob = user(&store, "bob").await; |
| 65 | 62 | |
| @@ -118,7 +115,7 @@ async fn filters_by_actor_action_target_and_involved_user() { | ||
| 118 | 115 | #[tokio::test] |
| 119 | 116 | async fn cursor_pages_newest_first_without_gaps() { |
| 120 | 117 | let dir = tempfile::tempdir().unwrap(); |
| 121 | - let store = open_store(&dir.path().join("forge.db")).await; | |
| 118 | + let store = open_store(&db_path(&dir)).await; | |
| 122 | 119 | let mut written = Vec::new(); |
| 123 | 120 | for _ in 0..5 { |
| 124 | 121 | let e = AuditEntry::new(AuditAction::Logout); |
| @@ -143,7 +140,7 @@ async fn cursor_pages_newest_first_without_gaps() { | ||
| 143 | 140 | #[tokio::test] |
| 144 | 141 | async fn purge_removes_only_entries_older_than_cutoff() { |
| 145 | 142 | let dir = tempfile::tempdir().unwrap(); |
| 146 | - let store = open_store(&dir.path().join("forge.db")).await; | |
| 143 | + let store = open_store(&db_path(&dir)).await; | |
| 147 | 144 | let mut old = AuditEntry::new(AuditAction::Logout); |
| 148 | 145 | old.at = "2020-01-01T00:00:00.000000000Z".into(); |
| 149 | 146 | store.record_audit(&old).await.unwrap(); |
crates/forge-core/tests/integration/common.rsadded+13 -0
| @@ -0,0 +1,13 @@ | ||
| 1 | +//! Helpers shared by the store test modules. | |
| 2 | + | |
| 3 | +use std::path::{Path, PathBuf}; | |
| 4 | + | |
| 5 | +use forge_core::Store; | |
| 6 | + | |
| 7 | +pub fn db_path(dir: &tempfile::TempDir) -> PathBuf { | |
| 8 | + dir.path().join("forge.db") | |
| 9 | +} | |
| 10 | + | |
| 11 | +pub async fn open_store(path: &Path) -> Store { | |
| 12 | + Store::open(path).await.expect("open store") | |
| 13 | +} |
crates/forge-core/tests/integration/main.rsadded+9 -0
| @@ -0,0 +1,9 @@ | ||
| 1 | +//! Store integration tests for forge-core, built as one test binary. | |
| 2 | + | |
| 3 | +#[allow(dead_code)] | |
| 4 | +mod common; | |
| 5 | + | |
| 6 | +mod audit_store; | |
| 7 | +mod read_pool; | |
| 8 | +mod stars_store; | |
| 9 | +mod store_basic; |
crates/forge-core/tests/read_pool.rs → crates/forge-core/tests/integration/read_pool.rsrenamed+0 -0
crates/forge-core/tests/stars_store.rs → crates/forge-core/tests/integration/stars_store.rsrenamed+2 -10
| @@ -1,18 +1,10 @@ | ||
| 1 | 1 | //! Store tests for stars, the public repo listing and the 0005 migration. |
| 2 | 2 | |
| 3 | -use std::path::{Path, PathBuf}; | |
| 4 | - | |
| 3 | +use forge_core::Visibility; | |
| 5 | 4 | use forge_core::store::RepoSort; |
| 6 | 5 | use forge_core::store::migrate::{MIGRATIONS, migrate}; |
| 7 | -use forge_core::{Store, Visibility}; | |
| 8 | - | |
| 9 | -fn db_path(dir: &tempfile::TempDir) -> PathBuf { | |
| 10 | - dir.path().join("forge.db") | |
| 11 | -} | |
| 12 | 6 | |
| 13 | -async fn open_store(path: &Path) -> Store { | |
| 14 | - Store::open(path).await.expect("open store") | |
| 15 | -} | |
| 7 | +use crate::common::{db_path, open_store}; | |
| 16 | 8 | |
| 17 | 9 | #[tokio::test] |
| 18 | 10 | async fn star_and_unstar_round_trip_with_count() { |
crates/forge-core/tests/store_basic.rs → crates/forge-core/tests/integration/store_basic.rsrenamed+2 -9
| @@ -1,17 +1,10 @@ | ||
| 1 | 1 | //! Store round-trip tests against a real turso database file in a temp directory. |
| 2 | 2 | |
| 3 | 3 | use forge_core::time::{now_stamp, stamp_after}; |
| 4 | -use forge_core::{Error, Role, Store, Visibility}; | |
| 5 | -use std::path::{Path, PathBuf}; | |
| 4 | +use forge_core::{Error, Role, Visibility}; | |
| 6 | 5 | use std::time::Duration; |
| 7 | 6 | |
| 8 | -fn db_path(dir: &tempfile::TempDir) -> PathBuf { | |
| 9 | - dir.path().join("forge.db") | |
| 10 | -} | |
| 11 | - | |
| 12 | -async fn open_store(path: &Path) -> Store { | |
| 13 | - Store::open(path).await.expect("open store") | |
| 14 | -} | |
| 7 | +use crate::common::{db_path, open_store}; | |
| 15 | 8 | |
| 16 | 9 | #[tokio::test] |
| 17 | 10 | async fn create_user_and_lookup_case_insensitively() { |
docs/backlog.mdmodified+1 -1
| @@ -51,7 +51,7 @@ Status: `[ ]` todo, `[~]` in progress, `[x]` done. | ||
| 51 | 51 | |
| 52 | 52 | ## Tech debt |
| 53 | 53 | - [x] A shared test fixture `test_support::app(dir) -> (AppState, Router)`: Config and AppState literals are copied into about 8 test modules, and every new field breaks them all |
| 54 | -- [x] Store read pool: one writer connection plus 4 `query_only` readers (`Store::read_conn`); pure-SELECT functions use the readers (rules in the `Store` doc comment, proof in `crates/forge-core/tests/read_pool.rs`) | |
| 54 | +- [x] Store read pool: one writer connection plus 4 `query_only` readers (`Store::read_conn`); pure-SELECT functions use the readers (rules in the `Store` doc comment, proof in `crates/forge-core/tests/integration/read_pool.rs`) | |
| 55 | 55 | - [x] Login and git auth throttling (`throttle.rs`, `client_ip.rs`, `trusted_proxies`) |
| 56 | 56 | |
| 57 | 57 | ## Later |