forge
Explore
Log in

Don't you dare go Hollow

Forge-core integration tests build as one binary

Browse files at this commit

d9b0f879d1df48727b20bf4edc4c0cd4ab02bdb5Ahmet Kaan GümüşParent: 9abc059
  • refactor
    • forge-core integration tests build as one binary
Show full message
♻️ refactor: forge-core integration tests build as one binary

Four test binaries (audit_store, read_pool, stars_store, store_basic) are
now one `integration` binary. Binaries 4 to 1, test count unchanged at 29.
The store open and db path helpers are deduped into tests/integration/common.rs.
crates/forge-core/tests/audit_store.rs → crates/forge-core/tests/integration/audit_store.rsrenamed+6 -9
@@ -1,14 +1,11 @@
1 //! Store tests for the audit log: record, filtered listing, cursor paging and retention purge.1 //! Store tests for the audit log: record, filtered listing, cursor paging and retention purge.
2 2
3-use std::path::Path;
4 use std::time::Duration;3 use std::time::Duration;
5 4
6 use forge_core::time::stamp_ago;5 use forge_core::time::stamp_ago;
7 use forge_core::{AuditAction, AuditCursor, AuditEntry, AuditFilter, Store, User};6 use forge_core::{AuditAction, AuditCursor, AuditEntry, AuditFilter, Store, User};
8 7
9-async fn open_store(path: &Path) -> Store {8+use crate::common::{db_path, open_store};
10- Store::open(path).await.expect("open store")
11-}
12 9
13 async fn user(store: &Store, name: &str) -> User {10 async fn user(store: &Store, name: &str) -> User {
14 store.create_user(name, None, "h", false).await.unwrap()11 store.create_user(name, None, "h", false).await.unwrap()
@@ -24,7 +21,7 @@ fn entry(action: AuditAction, actor: Option<&User>) -> AuditEntry {
24 #[tokio::test]21 #[tokio::test]
25 async fn record_and_list_round_trip_with_all_fields() {22 async fn record_and_list_round_trip_with_all_fields() {
26 let dir = tempfile::tempdir().unwrap();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 let tahinli = user(&store, "tahinli").await;25 let tahinli = user(&store, "tahinli").await;
29 let mut e = entry(AuditAction::RepoRenamed, Some(&tahinli));26 let mut e = entry(AuditAction::RepoRenamed, Some(&tahinli));
30 e.target_kind = "repo".into();27 e.target_kind = "repo".into();
@@ -44,7 +41,7 @@ async fn record_and_list_round_trip_with_all_fields() {
44 #[tokio::test]41 #[tokio::test]
45 async fn anonymous_entries_store_a_null_actor() {42 async fn anonymous_entries_store_a_null_actor() {
46 let dir = tempfile::tempdir().unwrap();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 let mut e = AuditEntry::new(AuditAction::LoginFailed);45 let mut e = AuditEntry::new(AuditAction::LoginFailed);
49 e.target_name = "mallory".into();46 e.target_name = "mallory".into();
50 store.record_audit(&e).await.unwrap();47 store.record_audit(&e).await.unwrap();
@@ -59,7 +56,7 @@ async fn anonymous_entries_store_a_null_actor() {
59 #[tokio::test]56 #[tokio::test]
60 async fn filters_by_actor_action_target_and_involved_user() {57 async fn filters_by_actor_action_target_and_involved_user() {
61 let dir = tempfile::tempdir().unwrap();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 let tahinli = user(&store, "tahinli").await;60 let tahinli = user(&store, "tahinli").await;
64 let bob = user(&store, "bob").await;61 let bob = user(&store, "bob").await;
65 62
@@ -118,7 +115,7 @@ async fn filters_by_actor_action_target_and_involved_user() {
118 #[tokio::test]115 #[tokio::test]
119 async fn cursor_pages_newest_first_without_gaps() {116 async fn cursor_pages_newest_first_without_gaps() {
120 let dir = tempfile::tempdir().unwrap();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 let mut written = Vec::new();119 let mut written = Vec::new();
123 for _ in 0..5 {120 for _ in 0..5 {
124 let e = AuditEntry::new(AuditAction::Logout);121 let e = AuditEntry::new(AuditAction::Logout);
@@ -143,7 +140,7 @@ async fn cursor_pages_newest_first_without_gaps() {
143 #[tokio::test]140 #[tokio::test]
144 async fn purge_removes_only_entries_older_than_cutoff() {141 async fn purge_removes_only_entries_older_than_cutoff() {
145 let dir = tempfile::tempdir().unwrap();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 let mut old = AuditEntry::new(AuditAction::Logout);144 let mut old = AuditEntry::new(AuditAction::Logout);
148 old.at = "2020-01-01T00:00:00.000000000Z".into();145 old.at = "2020-01-01T00:00:00.000000000Z".into();
149 store.record_audit(&old).await.unwrap();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 //! Store tests for stars, the public repo listing and the 0005 migration.1 //! Store tests for stars, the public repo listing and the 0005 migration.
2 2
3-use std::path::{Path, PathBuf};3+use forge_core::Visibility;
4-
5 use forge_core::store::RepoSort;4 use forge_core::store::RepoSort;
6 use forge_core::store::migrate::{MIGRATIONS, migrate};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 {7+use crate::common::{db_path, open_store};
14- Store::open(path).await.expect("open store")
15-}
16 8
17 #[tokio::test]9 #[tokio::test]
18 async fn star_and_unstar_round_trip_with_count() {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 //! Store round-trip tests against a real turso database file in a temp directory.1 //! Store round-trip tests against a real turso database file in a temp directory.
2 2
3 use forge_core::time::{now_stamp, stamp_after};3 use forge_core::time::{now_stamp, stamp_after};
4-use forge_core::{Error, Role, Store, Visibility};4+use forge_core::{Error, Role, Visibility};
5-use std::path::{Path, PathBuf};
6 use std::time::Duration;5 use std::time::Duration;
7 6
8-fn db_path(dir: &tempfile::TempDir) -> PathBuf {7+use crate::common::{db_path, open_store};
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-}
15 8
16 #[tokio::test]9 #[tokio::test]
17 async fn create_user_and_lookup_case_insensitively() {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 ## Tech debt52 ## Tech debt
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 all53 - [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 - [x] Login and git auth throttling (`throttle.rs`, `client_ip.rs`, `trusted_proxies`)55 - [x] Login and git auth throttling (`throttle.rs`, `client_ip.rs`, `trusted_proxies`)
56 56
57 ## Later57 ## Later